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.

Timer Synchronization & Timer in PWM mode

I require in my project to pulse a pin 4095 times after which an interrupt is triggered which among many things disables the timers and resets it after certain tasks are completed.

I wasn't able to use the TIVA C Series PWM module for this , instead ,I decided to use two timers of different bases .

1) TIMER1_BASE timer a triggers an interrupt after 4095 counts

2) TIMER0_BASE timer a is configured as PWM

Is there a more efficient way to do this? How do i set the frequency of the timer as PWM ?

Here is how I have attempted to pulse pin PB6 using TIMER0 ()Keeps pulsing until timer is disabled) .Timer 1 counts 4095 cycles and then generates an interrupt which disables both the timers and performs certain tasks which is not the subject matter of this post .I have also used TimerSynchronize() to synchronize both the timers . 

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

	GPIOPinConfigure(GPIO_PB6_T0CCP0);   //Timer 1 A Config
	GPIOPinConfigure(GPIO_PB4_T1CCP0);   // Timer 2 A Config

	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4);

	TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC|TIMER_CFG_A_PWM|TIMER_CFG_SPLIT_PAIR);

	TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet()/SPI_FREQ_1M); //Pulses out PWM @50% dutyCycle
	TimerLoadSet(TIMER1_BASE, TIMER_A,4095);                      //Triggers an interrupt after 4095 cycles which disables the timers and
                                                                  // On clocking out GS data re-enables them
	TimerMatchSet(TIMER0_BASE, TIMER_A,0 );

    TimerSynchronize(TIMER0_BASE,TIMER_0A_SYNC|TIMER_1A_SYNC);

	IntEnable(INT_TIMER1A);
	TimerIntEnable(TIMER1_BASE,TIMER_TIMA_TIMEOUT );
	IntMasterEnable();

	TimerEnable(TIMER1_BASE, TIMER_A);
	TimerEnable(TIMER0_BASE, TIMER_A);

 

My questions are :-

  • Is this method of counting pwm pulses using two timers correct ? Is there a more simple clean and efficient way to do this 
  • Have i used the TimerSynchronize function correctly ?
  • Hi Ramesh

    If the intent is to count 4095 Clock cycles once, then it would be better to keep it in One Shot.

    If the intent is to count 4095 PWM Edges, then you can use the second timer in Edge Count Mode and then no need to synchronize.

    Amit