This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Resetting the Timer

I found a relevant post to my question (link below).

To explain my predicament:

I need to dither (for current limiting) pulses to my stepper motor. Too that effect I am using T1CCP0, T1CCP1, T2CCP0 and T2CCP1 lines for driving my stepper motor. I use Timers 1A, 1B, 2A and 2B in PWM mode, and I enable and disable each timer based on the state the stepper motor should be in. All is well and good. but since the timers are in PWM mode, during the off state of the stepper motor line the may be high or low depending upon whether the timer was disabled pre or post match.

So I need to somehow reset the timer so that I can control the match condition when transitioning to the off state.

As the post linked above suggests, I need to write to the Timer Value Register (GPTMTAV and GPTMTBV) for all four timers. However the TivaWare driverlib does not seem to have a TimerValueSet function. I dont know any other function that might allow the same functionality (as far as I can tell). Is there a particular version I need to be using? Or has this not been reflected into the library yet and I should make my own function?

  • Hello Safiullah,

    Or would it be easier switching the PWM outputs of the timers to GPIO Mode. When doing the same, you can read the state of the GPIO using GPIODATA register and then knowing if it is in the correct state, switch it to GPIO Mode with the value written to the Data Register already.

    Other than that in lack of the API, you would need to create a small API of your own in the application code.

    Regards
    Amit
  • Hi Amit,

    Thank you for the quick response.

    You 'll need to elaborate on how to do that a bit.

    The reason behind choosing the PWM mode was that I could a) run the timer continuously without servicing an interrupt, and b) I get control over the T1CCP0 pin without the need to manipulate the GPIO on each said interrupt. Since my PWM pulses are very short, the number of interrupts will be significant. Coupled with the fact that the processor has a lot of other things to deal with, a frequently recurring interrupt may not be feasible.

    for the TimerValueSet API, I dont think the function is too complex, but by your reply, I fathom that the library does not have a suitable function built in, so I will have to write my own. That is not a problem I suppose.

    Regards,
    Safi
  • Hello Safiullah,

    OK, so I did not consider the load on the CPU. By taking the same into context, yes making such a function would be the right way out and it is not all that difficult.You can use the prototype of any of the timer functions and use it make your own.

    Regards
    Amit
  • So here is the code snippet that I used.

    void
    TimerValueSet(uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Value)
    {
    	//Debug Assert Here
    
        uint32_t offset = (ui32Timer == TIMER_A) ? TIMER_O_TAV : TIMER_O_TBV;
        HWREG(ui32Base + offset) = ui32Value;
    }

    I call this at any Value above or below the match value (depending on whether I want the CCP pin set or reset) and then immediately disable the respective timer.