Freescale MCF5213 _DMA Timer_PWM pulse width calculation problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Freescale MCF5213 _DMA Timer_PWM pulse width calculation problem

1,141 Views
alitariqnagi
Contributor I

Dear All,

 

I am using two MCF5213 Evaluation kits: one for generating the PWM waveform and the other for checking the period of the PWM waveform.

 

I am using he DMA timers to check the time period of the pulse. I have configured it but giving incorrect value in the DTCR(counter) register.

 

I am using DTIN1 for giving the pulse input which has the period of 0.8ms but the value in the counter turns out to be 264244026.

 

which gives 264244026/(80 * 10^6) = 3.303050325 which is incorrect. Please check the code and let me know if i am doing something wrong here

 

thanks

 

 

I am using the following code:

 

int main(void)

{

 

 

    // Enable the directions pins TC[1]

    MCF_GPIO_PTCPAR = 0

                    | MCF_GPIO_PTCPAR_DTIN0_DTIN0

                    | MCF_GPIO_PTCPAR_DTIN1_DTIN1

                    | MCF_GPIO_PTCPAR_DTIN2_DTIN2

                    | MCF_GPIO_PTCPAR_DTIN3_DTIN3;

 

    MCF_DTIM_DTMR(1) =   

        MCF_DTIM_DTMR_PS(0x00)

        | MCF_DTIM_DTMR_CE_RISE  

        | MCF_DTIM_DTMR_CLK_DIV1

        | MCF_DTIM_DTMR_RST;

 

            //Setup the interrupt registers for DTIN[1] & DTIN[3]

    MCF_INTC_IMRL &= ~MCF_INTC_IMRL_MASKALL

                        & ~MCF_INTC_IMRL_INT_MASK20

                        & ~MCF_INTC_IMRL_INT_MASK22;

    MCF_INTC_ICR(20) = MCF_INTC_ICR_IP(4) | MCF_INTC_ICR_IL(4);

       mcf5xxx_set_handler(64 + 20, direction12_handler);

    mcf5xxx_irq_enable();

  

    while (1)

    {

    printf("the value of the counter is %d \n", counter);

    }

  

 

 

}

 

__declspec(interrupt) void direction12_handler(void) {

 

    counter = (long int) MCF_DTIM_DTCR(1);    //Read the encoder counter

 

    MCF_DTIM_DTCN(1) = 0;        //Reset the encorder counter

 

  MCF_DTIM_DTER(1) |= MCF_DTIM_DTER_CAP;

}

 


Labels (1)
0 Kudos
Reply
2 Replies

952 Views
Monica
Senior Contributor III

Ali, were those advices helpful for you to continue on your project?

How is it going? Please let us know.

Regards!

0 Kudos
Reply

952 Views
TomE
Specialist II

That's not the best way to use the DMA timer to measure a signal.

You're using Capture mode, but you shouldn't be resetting the counter. You should let the counter free-run, and then subtract "this" capture value from the "previous" capture value. The difference between successive capture values will give the period accurate to the clock interval.

Other Freescale timers I've used had one counter but up to 16 separate capture/compare units running from the one counter. With this sort of arrangement you can't clear the counter when using one of the timers as that would wreck the timing on the other 15. So the "standard way of operating" is to let the counter free-run and work from the differences. Yes, this timer has one counter per timer, but the good reasons for using the differences between counts still applies.

With what you're doing (clearing the counter), your measurement is also out by the interrupt latency from the edge to where your code clears the counter. That doesn't explain the values you're reading though.

The count value you're reading is 264244026 or 0x0FC00B3A. The value you expect is 800us * 80MHz = 64000 = 0x0000FA00. They're way out.

That value you're reading should be "jittering" a bit. If it isn't changing then the interrupt may not be happening properly. Do you get that value consistently or did you only read it once? You may have turned the second board on 3 seconds after turning the first one on and may have only got one trigger.

Where is "counter" defined, and did you remember to declare it as "volatile"?

Tom

0 Kudos
Reply