Author Topic: DMA Timer Configuration  (Read 8337 times)

Offline rnardone

  • Newbie
  • *
  • Posts: 6
    • View Profile
DMA Timer Configuration
« on: November 10, 2008, 03:28:51 PM »
Hi Mark,

   I want to use DMA Timer 3 to generate an interrupt every 500us.  I spent some time working with the DMA timer configuration and finally had to cheat by stuffing a value into the DTRR register after doing the configuration.  I got it working, but would like to do it in proper uTasker style.   Can you take a quick look and let me know what you think please?  I tried your macros for setting the delay time, but the output pulse was WAY off.  I'm using real hardware MCF52233Demo board.

    Thanks,

            Rick

static void rsn_DMA_timer_int(void)
{
    static int iTimerTest = 0;
    PORTAN ^= PORT_AN_BIT0; // toggle output
   
}

static void fnConfigure_DMA_Timer(void)
{
    DMA_TIMER_SETUP dma_timer_setup;  // interrupt configuration parameters
    CONFIG_TEST_OUTPUT();
    dma_timer_setup.int_type = DMA_TIMER_INTERRUPT;
    dma_timer_setup.int_handler = rsn_DMA_timer_int;
    dma_timer_setup.channel = 3;                         // DMA timer channel 3
    dma_timer_setup.clock_divider = 0;                                         
    dma_timer_setup.int_priority = CAN13_INTERRUPT_PRIORITY; // define interrupt priority
    dma_timer_setup.mode =  (DMA_TIMER_INTERNAL_CLOCK | DMA_TIMER_RESTART_ON_MATCH | DMA_TIMER_PERIODIC_INTERRUPT | DMA_TIMER_INTERNAL_CLOCK_DIV_16 );
    dma_timer_setup.count_delay = 100;          // 500us delay using no dividers
    fnConfigureInterrupt((void *)&dma_timer_setup);  // enter interrupt for DMA timer test
   
    DTRR3 = 1849; // set for 2KHz

}

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: DMA Timer Configuration
« Reply #1 on: November 10, 2008, 06:23:26 PM »
Hi Rick

I dusted off my DEMO board and loaded the project with your DMA configuration.
AN0 toggled with a frequency of 1.012kHz (an interrupt every 496us).

Then I did the same with the macro:

    dma_timer_setup.count_delay = DMA_TIMER_US_DELAY(1,16,(1000000/2/2000));

where the parameters are 1 = divider, 16 prescaler (because you are setting the prescaler with the parameter DMA_TIMER_INTERNAL_CLOCK_DIV_16), 1000000/2/2000 is the delay expressed in us (for the us macro) but written so that the frequency can be given rather than the us delay - the frequency is set for 2kHz since you have a note that you wanted 2kHz. (In other words 250us is the half period to generate a 2000Hz square wave).

This then gave a 2'000Hz on AN0.

I then tried by removing the prescaler (It is not needed to generate 2kHz) and tested the following:

    dma_timer_setup.mode =  (DMA_TIMER_INTERNAL_CLOCK | DMA_TIMER_RESTART_ON_MATCH | DMA_TIMER_PERIODIC_INTERRUPT );
    dma_timer_setup.count_delay = DMA_TIMER_US_DELAY(1,1,(1000000/2/2000)); // prescaler set to 1



This again gave 2'000Hz.

In the first case DTRR3 was set with 936 and the second case with 14999 (decimal).

Which values were you using for the macro? Do you want 2kHz or 1kHz? Note that the demo project is running with 60MHz PLL and any changes in PLL should automatically be adjusted by the macro.

regards

Mark






Offline rnardone

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: DMA Timer Configuration
« Reply #2 on: November 20, 2008, 03:02:51 PM »
Hi Mark,

   Definately some operator error on my part here.  Both your suggestions work 100% on my 52233DEMO, and I greatly appreciate the support.  I finished up with no clock divider and used:

dma_timer_setup.count_delay =  DMA_TIMER_US_DELAY(1,1,500);

   Thanks again for your outstanding support!

       - Rick

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: DMA Timer Configuration
« Reply #3 on: November 20, 2008, 07:00:26 PM »
Hi Rick

It may be nice to use the following macro for defining frequencies:

#define DMAFREQUENCY(Hz)  (1000000/2/Hz)

Its use would be
dma_timer_setup.count_delay = DMA_TIMER_US_DELAY(1,1,DMAFREQUENCY(1000)); // 100Hz signal

Regards

Mark