Author Topic: how to use the GLOBAL_HARDWARE_TIMER!  (Read 8656 times)

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
how to use the GLOBAL_HARDWARE_TIMER!
« on: March 12, 2008, 07:36:46 AM »
hi:
  Now I want to use the the DMA timers to get the 213us  interrupt,I know the #define MILLISEC LOW_RES_MS so that 71us*3=213 ,that is OK!
   Can the the DMA timers always is exactitude???
   for example i want to the led on at  213us,then next to led off at  213us,next to led on,next to led off,and forever like this!
    where to  put the led_on() and led_off() function??
   
« Last Edit: March 12, 2008, 09:30:33 AM by tr111 »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: how to use the GLOBAL_HARDWARE_TIMER!
« Reply #1 on: March 12, 2008, 02:57:34 PM »
Hi

The use of the global hardware timers is described here:
http://www.utasker.com/docs/uTasker/uTaskerTimers.PDF

However I am not use that this is the best solution for what you want to do. The global hardware timer method is an extension to the global software timers method which allows delays (resulting in events) to be programmed with higher resolution that the TICK timer.

Since the M5223X has several timers it would probably be easier to set up up to give a peropd interrupt at the desired rate an then the interrupt can be handled directly - this is more accurate than using the event method since the events are generated from code outside of the interrupt routine and so can have some jitter (as well a a small constant delay).

There is also a second PIT (Periodic Interrupt Timer) - the code from the first (fnStartTick() in M5223X.c) can be easily duplicated, with the set up to generate the required period, and the the led_on() and led_off() placed directly in teh interrupt routine.

Regards

Mark

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: how to use the GLOBAL_HARDWARE_TIMER!
« Reply #2 on: March 13, 2008, 08:45:05 AM »
hi:
   that is great!
   this code! maybe 1S!

   // Routine to initialise the Periodic Interrupt Timer interrupt
//

/* Bit definitions and macros for MCF_PIT_PMR */
#define MCF_PIT_PMR_PM(x)                    (((x)&0xFFFF)<<0)
#define PIT_PRESCALE1  0x0f00
#define TICK_DIVIDE1    MCF_PIT_PMR_PM(0x3e7);
/**************************** Periodic Interrupt Timer interrupt ******************************************/

static __interrupt__ void _PIT1Interrupt(void)
{
  PIT_PCSR_1 = (PIT_PRESCALE1 | PIT_DBG | PIT_OVW | PIT_PIF | PIT_RLD | PIT_PIE | PIT_EN); // Reset interrupt request flag
 // fnDebugMsg("tt"); 
 PORTTC ^= PORT_TC_BIT3;
}

extern void fnPITStartTick(void)
{
    PIT_PCSR_1 = (PIT_PRESCALE1 | PIT_DBG | PIT_OVW | PIT_PIF | PIT_RLD); // prepare for load
    PIT_PMR_1 = TICK_DIVIDE1;                                             // load interval value

    fnSetIntHandler(PIT1_VECTOR, (unsigned char *)_PIT1Interrupt);

    IC_ICR_0_56 = TICK_INTERRUPT_PRIORITY;                               // define interrupt level and priority
    IC_IMRH_0 &= ~(PIT_1_PIF_INT_H);                                     // unmask interrupt source
    IC_IMRL_0 &= ~(MASK_ALL_INT);                                        // clear global mask {5}

    PIT_PCSR_1 = (PIT_PRESCALE1 | PIT_DBG | PIT_OVW | PIT_PIF | PIT_RLD | PIT_PIE | PIT_EN); // start PIT with interrupt enabled

#ifdef _GNU
    asm_int_on();
#endif
}