I need to use the freedom board to run a small robot project
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.
Solved! Go to Solution.
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.
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.
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.
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.
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
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