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.

Timers for use in "Input Edge Timing Mode"



Hi there, could there anybody help me out for this problem with some working example for this timer mode?

I saw a lot of similiar questions in this forum but I nowhere found one simple example. In Stellarisware one could find only examples for oneshot_16bit, periodic_16bit and pwm. Pwm is the timer's working method which seems to be closest to this I need ..  

I have stolen the example "timers" from Stellarisware/boards and adopted it to my requirements - I have an LM4F232 dev-kit and I try to count square in 1 KHz range waves by the help of CC timers which I lead to port PL0 and PL1 which should be unused on my board.

By the way; why are all function-calls prefixed with ROM_  in the Stellarisware-examples ?

------

here comes the (semi-)code

void
Timer0IntHandler(void)
{
    ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    HWREGBITW(&g_ulFlags, 0) ^= 1;

   g_ulCounter++;

}

//*****************************************************************************
//
// The interrupt handler for the second timer interrupt.
//
//*****************************************************************************
void
Timer1IntHandler(void)
{
   ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    HWREGBITW(&g_ulFlags, 1) ^= 1;

     g_ulCounter++;
}

in main() I do this ...

ROM_FPULazyStackingEnable();

 ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

FAL96x64x16Init();

GrContextInit(&g_sContext, &g_sCFAL96x64x16);

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);    // 

//ROM_IntMasterEnable();

 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);

  GPIOPinConfigure(GPIO_PL0_T0CCP0);
  GPIOPinConfigure(GPIO_PL1_T0CCP1);

  GPIOPinTypeTimer(GPIO_PORTL_BASE, GPIO_PIN_0);
  GPIOPinTypeTimer(GPIO_PORTL_BASE, GPIO_PIN_1);

 TimerConfigure(TIMER0_BASE, (
         TIMER_CFG_SPLIT_PAIR
         | TIMER_CFG_A_CAP_TIME
         | TIMER_CFG_B_CAP_TIME
         ));

  TimerControlEvent( TIMER0_BASE, TIMER_BOTH, TIMER_EVENT_BOTH_EDGES );

 TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());
 TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000000);

  IntMasterEnable();

  TimerIntEnable(TIMER0_BASE, ( TIMER_CAPA_EVENT | TIMER_CAPB_EVENT ));

  IntEnable( INT_TIMER0A | INT_TIMER0B);

   TimerEnable(TIMER0_BASE, TIMER_A);
   TimerEnable(TIMER0_BASE, TIMER_B);

    while(1)
    {}

 I have a breakpoint in every ISR but never fall into.

Could I have something twisted in the init-sequence?

 Thanks in advance

--jens

  • Jens Lauer said:

     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);

    Note that here your code enables Port "P"!  (and your timers are on Port "L"!)

    The ROM calls use the StellarisWare functions built w/in the MCU's ROM. 

  • Hi

    here is some sample code for measuring the frequency of an digital square wave signal. The sample uses two timers. One is configured as one second count down and the other one counts the incoming edges (rising edge). Of course you have to fit this code for your board and add the "Timer1IntHandler" to your start up code (depending on your IDE). This code works fine on my LM3S9B92 with 80 MHz.

  • thank you - but also correcting this fault did not lead to any success

  • What fault? What exactly do you mean with "no success"?

    Of course this is just an "how it should look like" for you. It works on my board, but this is an cortex 3 und you have a cortex 4. Beside that, you have to fit all you gpio pins, etc. For that you have to take a look in the datasheet of your MCU.

  • Thanks Andre,

    altought I did not completely understood  the aim of these code (what is timer2 dedicated for , etc. ) I adopted the port setting to fit these of my board (changed PB2 to PL0) but I get no interrupts at all.

    I general I cannot generate any communication across systems boundary as it seems for me - there will come no port-level changes out as no port level changes will become signalized into the controller.

    I use the example "reload_interrupt" from /stellarisware/examples/ peripheral/pwm. But even this example ( neither GPIO Port D nor GPIO Port M ) gives no signal out. The ISR I can caugh with my breakpoint but I see no changes regarding IO-pin's port level within the oscilloscope.

    So could there be any special enable sequence required for the M4 chip? A bunch of other users seem to have brougt the code up running for the M3 based devices which could be different in some behaviour  ...

    Thanks

    --jens

     

  • Jens Lauer said:
    altought I did not completely understood  the aim of these code (what is timer2 dedicated for , etc. ) I adopted the port setting to fit these of my board (changed PB2 to PL0) but I get no interrupts at all.

    This was my fault. Of course, you have to enable the processors interrupt controller. I just copied the relevant parts out of an existing project.

    void main(void)
    {
        clockInit();
        TimerInit();
        IntMasterEnable();
        freqMeasurementStart();
    }

    Jens Lauer said:
    So could there be any special enable sequence required for the M4 chip? A bunch of other users seem to have brougt the code up running for the M3 based devices which could be different in some behaviour  ...

    Because I don't have any experiences with the stellaris M4 MCUs I cannot give you a satisfying answer.

  • I finaly came up with the capture mode running ... One big question is still open:

    Q: Is one timer module (equipped with two timers) unable to handle HW input from one common, single source?

    With my software Timer2_A should count edges and Timer2_B should count times between these edges. This seems to to be unable to bring up working. As I see I either can count edges or I can measure time.  Source of signals in both cases is Port-L::Pin4 which I have set up in these manor:

    GPIOPinConfigure(GPIO_PL4_T2CCP0);

    GPIOPinTypeTimer(GPIO_PORTL_BASE, GPIO_PIN_4);

    Much thanks in advance

    Jens

     

     

      

  • Jens Lauer said:
    Is one timer module (equipped with two timers) unable to handle HW input from one common, single source?

    You won't drive two timers with one single signal source, don't you? Or am I missing your question? In a previous step I tried to use one timer to count edges and one to count the clock ticks, both of the same module. I don't know why, but it doesn't work. So I used two seperate timer modules and it works fine.

  • Andre Marianovich said:
    You won't drive two timers with one single signal source, don't you?

    Double/multiple negatives that sentence mask clarity.  I believe poster seeks to use each half of a Timer Module to:

    a) count the edges of his ~1KHz input signal via (let's say) Timer A

    b) count the duration between each edge - or "N" edges via Timer B (same Timer Module)

    Clearly this is the best use of Timer Resource - and is just how this reporter would attempt such effort.

    As you state, "doesn't work - don't know why!"   Have 3 free days pending - will take a shot @ Single Timer achieving poster's stated goal - using much/most of your past effort and will report (share) here...

  • Hi there

    I've been reading in the forum but I do not understand.

    I need a simple program to get the time or clock cycles between a rising edge and falling edge from an input pin and then save it in a variable.

    I´m a newbie, I've done programs of other things but in this case I don't understand how to do.

    I'm working with a Tiva C Series LaunchPad with the IAR Embedded Workbench compiler.

    I appreciate the help given

  • Well, you could look into TivaWare examples. It helps alot.

    Also i normaly use TivaWare peripheral guide  and the datasheet, it seems hard and boring due to the size of it but with most peripherals it's quite easy, you just need to get the hang of it, fiding information in the datasheet and the guide. 

    Try analyzing this example code to measure a pulse legth of a SRF-04, this works in every pin, but you can configure the timer to do that automaticaly, but then you have to use the timer specific pins

    http://forum.stellarisiti.com/topic/2004-pulse-legth-measure-srf04-example/