Dear sir / madam,
How to enable PWM Output use DC motor speed control...
How to use PWM Output in FTM Mode...
LED Blinking But Not Speed Control in DC Motor...
Advance Thanks
Velmurugan .V
hi,
First check whether input clock source for the FTM module is enabled?
Next check, which is the the type of clock source givem tp FTM module. It can be from below sources.
PWM_NO_CLOCK -> No input clock is given to FTM. FTM count is not operational
PWM_SYSTEM_CLOCK -> System clock is given to FTM.
PWM_EXTERNAL_CLOCK -> An fixed frequnecy clock is given to FTM.
PWM_FIXED_FREQ_CLOCK -> An external clock is given to FTM.
Suppose I choose fixed frequency clock of 1 kHz, and I give period in ticks. If I give my period in ticks as 95 ticks, then my one tick is 10hz. Chose period in ticks or in seconds. You can set the number of ticks to define your period of PWM.
Diectly probe Digital oscillscope to your test point by setting the duty cycle to your channel.
Hi, Velmurugan,
Regarding your question of PWM timing to control DC motor, the PWM timing is dependent on the power stage layout, for example bipolar switching or unipolar switching, pls refer to the an1927.pdf to select one.
If you use bipolar switching, you can configure the PWM0/PWM1 signal as one pair, PWM2/PWM3 as another pair, both PWM0/PWM1 and PWM2/PWM3 are in complementary mode.
I attach the an1927.pdf, you can refer to the layout of DC motor control.
You can download an5142 to understand how to generate PWM complementary signal and inverting one PWM pair if necessary.
https://www.nxp.com/docs/en/application-note/AN5142.pdf
Regarding the speed control, you have to use sensor to measure the speed of DC motor and use PID to control the speed. We have developed the PID library, you can download motor control library based on your processor type.
Real Time Control Embedded Software Motor Control and Power Conversion Libraries|NXP
Hope it can help you
BR
XiangJun Rong
Dear xiangjun.rong,
Enable PWM and Generating Frequency Upto 350Hz Will Produces Correctly Below 350Hz Will Generate 83.33Hz so How to solve this Problem and Which one Clock Source Selected
Please Help Me sir,
Advance Thanks,
V. Velmurugan
Hi,Velmurugan
Can you tell me the part number you are using?
Anyway, you use FTM to generate PWM signal, the FTMx_MOD register define the PWM signal frequency. The PWM signal frequency is (PWM driving clock frequency)/(FTM_MOD) in edge-alignment mode, you can select the "PWM driving clock frequency" via CLKS bits in FTM_SC.
CLKS:
Clock Source Selection
Selects one of the three FTM counter clock sources.
This field is write protected. It can be written only when MODE[WPDIS] = 1.
00 No clock selected. This in effect disables the FTM counter.
01 System clock
10 Fixed frequency clock
11 External clock
I suppose that you use system clock source, you have to know the system clock source frequency. The MCG module can set the system clock source frequency.
BR
Xiangjun Rong
Hi xiangjun.rong,,
i'm using single PWM Generate Example in FRDM K22F, i can't change in anything ...
i will try and change the clock source
Thanks
Hi, Velmurugan,
You can update the variables of FTM_SetupPwm() to change the PWM signal frequency.
I give you the prototype of the function FTM_SetupPwm()
the status_t FTM_SetupPwm(FTM_Type *base,
const ftm_chnl_pwm_signal_param_t *chnlParams,
uint8_t numOfChnls,
ftm_pwm_mode_t mode,
uint32_t pwmFreq_Hz,
uint32_t srcClock_Hz)
For example, the example call the function as:
FTM_SetupPwm(BOARD_FTM_BASEADDR, ftmParam, 2U, kFTM_EdgeAlignedPwm, 24000U, BOARD_TIMER_SOURCE_CLOCK);
the 24000U(PWM signal is 24KHz) is the required PWM signal frequency, you can change it for example 2400U, the PWM will be 2.4KHz
Hope it can help you
BR
XiangJun Rong
/* Initialize timer module */
static void Timer_Init(void)
{
ftm_config_t ftmInfo;
ftm_chnl_pwm_signal_param_t ftmParam[2];
/* Configure ftm params with frequency 24kHZ */
ftmParam[0].chnlNumber = (ftm_chnl_t)BOARD_FIRST_TIMER_CHANNEL;
ftmParam[0].level = kFTM_LowTrue;
ftmParam[0].dutyCyclePercent = 0U;
ftmParam[0].firstEdgeDelayPercent = 0U;
ftmParam[1].chnlNumber = (ftm_chnl_t)BOARD_SECOND_TIMER_CHANNEL;
ftmParam[1].level = kFTM_LowTrue;
ftmParam[1].dutyCyclePercent = 0U;
ftmParam[1].firstEdgeDelayPercent = 0U;
/*
* ftmInfo.prescale = kFTM_Prescale_Divide_1;
* ftmInfo.bdmMode = kFTM_BdmMode_0;
* ftmInfo.pwmSyncMode = kFTM_SoftwareTrigger;
* ftmInfo.reloadPoints = 0;
* ftmInfo.faultMode = kFTM_Fault_Disable;
* ftmInfo.faultFilterValue = 0;
* ftmInfo.deadTimePrescale = kFTM_Deadtime_Prescale_1;
* ftmInfo.deadTimeValue = 0;
* ftmInfo.extTriggers = 0;
* ftmInfo.chnlInitState = 0;
* ftmInfo.chnlPolarity = 0;
* ftmInfo.useGlobalTimeBase = false;
*/
FTM_GetDefaultConfig(&ftmInfo);
/* Initialize FTM module */
FTM_Init(BOARD_FTM_BASEADDR, &ftmInfo);
FTM_EnableInterrupts(BOARD_FTM_BASEADDR,
BOARD_FIRST_CHANNEL_INT | BOARD_SECOND_CHANNEL_INT | kFTM_TimeOverflowInterruptEnable);
NVIC_EnableIRQ(BOARD_FTM_IRQ_ID);
FTM_SetupPwm(BOARD_FTM_BASEADDR, ftmParam, 2U, kFTM_EdgeAlignedPwm, 24000U, BOARD_TIMER_SOURCE_CLOCK);
FTM_StartTimer(BOARD_FTM_BASEADDR, kFTM_SystemClock);
}
Dear xiangjun.rong ,
Thanks For Reply,
i'm Enable PWM Mode and Working But i need 20Hz PWM Frequency Generate and Measure The Frequency using Oscilloscope 83.33Hz Produces
How to solve this one,
i need Speed of DC Motor is 1200RPM, 1 seconds 20 revolution , 1 RPS = 20
What can i do Sir,
Advance Thanks,
V. Velmurugan,