i need specific sample code for controlling stepper motor using KL46 controller. so i would request you to provide me specific/close sample c code to access PWM mode .
Thanks in advance
PWM on the KL46 is included in the code at KINETIS Project Code
The PWM (timer interface) is discussed in the HW timer document http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF
and is compatible with all KE, Kl and K devices (K/KE use FlexTimer and KL uses the TPM but the interface is the same).
pwm_setup.int_type = PWM_INTERRUPT;
pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_16); // clock PWM timer from the system clock with /16 prescaler
pwm_setup.pwm_reference = (_TIMER_0 | 3); // timer module 0, channel 3
pwm_setup.pwm_frequency = PWM_TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(1000), 16); // generate 1000Hz on PWM output
pwm_setup.pwm_value = _PWM_PERCENT(20, pwm_setup.pwm_frequency); // 20% PWM (high/low)
fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for first PWM output
pwm_setup.pwm_reference = (_TIMER_0 | 2); // timer module 0, channel 2
pwm_setup.pwm_mode |= PWM_POLARITY; // change polarity of second channel
pwm_setup.pwm_value = _PWM_TENTH_PERCENT(706, pwm_setup.pwm_frequency); // 70.6% PWM (low/high) on different channel
fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for second PWM output
You just need to choose the timer modules and channels (as available on the device being used) - any number can be used and all are independent apart from the fact that all channels on a particular module share the same base frequency.
Take a look at MCU on Eclipse blog: http://mcuoneclipse.com/
You will find a lot of examples and tips. To be more specific, take a look on pwm | Search Results | MCU on Eclipse. You will find some applications for PWM use.
Hope it helps,