AnsweredAssumed Answered

Freescale MCF5213 _DMA Timer_PWM pulse width calculation problem

Question asked by ali tariq nagi on Nov 23, 2012
Latest reply on Jan 7, 2013 by Monica Arvizu

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;

}

 


Outcomes