FRDM KL25Z PWMTiming configutation problem

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

FRDM KL25Z PWMTiming configutation problem

Jump to solution
2,896 Views
kesaradecosta
Contributor II


I need to use the freedom board to run a small robot project

  1. I need 2 PWM channels to run 2 motors
  2. Need 2 to 3 channels to send 10 us trigger pulse for Ultrasonic sensors
  3. Needs 3 to 5 channels to capture the return pulses from Ultrasonic sensors

I am having trouble setting up the timer module TPM2  on the code warrier 10.3 beta to configure to have 2 PWM channels with 4kHz to control the duty cycle of the motors ( L293D )

Can anyone help me in setting up the timer.

Your help is much appreciated.

Labels (1)
1 Solution
964 Views
adriansc
Contributor IV

Hi,

If you are using different channels from the same TPM and you want 4 kHz in both, use the same Timer Unit in channel 0 and channel 1.

The TimerUnit component uses different channel for your configuration, you can see this in the image.
TU1.JPG

This configure the same frequency of 4kHz in channel 0 and channel 1 but you can set the duty cycle for each channel.

Hope this helps.

View solution in original post

0 Kudos
3 Replies
965 Views
adriansc
Contributor IV

Hi,

If you are using different channels from the same TPM and you want 4 kHz in both, use the same Timer Unit in channel 0 and channel 1.

The TimerUnit component uses different channel for your configuration, you can see this in the image.
TU1.JPG

This configure the same frequency of 4kHz in channel 0 and channel 1 but you can set the duty cycle for each channel.

Hope this helps.

0 Kudos
964 Views
kesaradecosta
Contributor II

Hi Adrian,

I have got the PWM running and posted in the forum https://community.freescale.com/thread/300691 and thanks for your help.

Please help me on configuring and coding the Ultrasonic sensor

I tried to use 1 channel of PWM to send trigger pulse and capture the eco signal on TPM0_CNT with rising edge and using coding shown in the help on the component.

Please help me on configuring and coding to read the range

Thanks,

Kesara De Costa

0 Kudos
964 Views
kesaradecosta
Contributor II

Hi Adrian,

Finally managed to configure the timers to get the range reading.

code is

void GetRange (void){

            PWM1_SetDutyUS(PWM1Ptr, 35u);

            PWM1_Enable(PWM1Ptr); 

           

    Index = 0;

    Error = TU1_ResetCounter(MyTU1Ptr);                /* Start new measuring */

    Overflow = FALSE;

    Done = FALSE;

   

    do {} while (!Done && !Overflow) ;                  /* Wait for end of measurements or time-out */

    if (Overflow) {

      /* Time out. Period of measured signal is too long */

            Bit2_PutVal(Bit2Ptr, 0);

    }

    else {

      /* TU1_CNT_INP_FREQ_R_0 is a counter input frequency in Hz - see header file */

      Period = (Ticks[1] - Ticks[0]) / TU1_CNT_INP_FREQ_R_0; /* Period of the signal in seconds */

    }

    PWM1_Disable(PWM1Ptr);

  }

int j=0;

  for(;;){

GetRange();

  Range = Period * 34000/5;

  for(j= 1; j<= 10000; j++){

  Bit1_PutVal (Bit1Ptr,Range< 10);

}

     

  }

On the events

void TU1_OnChannel0(LDD_TUserData *UserDataPtr)

{

  /* Write your code here ... */

        

  

            Error = TU1_GetCaptureValue(MyTU1Ptr,CHANNEL,&Ticks[Index]); /* Store captured value to array Ticks */

              Index++;

              if (Index >= NUMBER_OF_MEASUREMENTS) {

                Done = TRUE;

              }

But the measurement is not 100% accurate.

Kesara De Costa