Hi
1. THE PWM output is a digital output that is fixed at the CPU's power supply, so can not be adjusted in amplitude.
2. Once the PWM is running its value can be changed by writing directly to its compare register:
EG. for an output controlled by FTM (or TPM), channel 1
FTM1_C1V = _PWM_PERCENT(ucPWMValue, usFrequencyCount);where the first parameter is the required PWM percentage value (0..100) and the second is the value that was set as time base originally.
3. The timers are 16 bit and there is a limit to the lowest frequency that can be generated. This limit is defined by the PWM resolution required, the counter width (16 bits) and the clock frequency that it uses. For slower PWM signals a slower clock needs to be used.
The options are
TPM_CLOCKED_FROM_OSCERCLK (crystal speed - 32kHz?)
TPM_CLOCKED_FROM_MCGIRCLK (8MHz) if
USE_FAST_INTERNAL_CLOCK is disabled it will be 2MHz instead
or clocked from MCGFLLCLK when above are not defined.
If the 8MHz clock is used it will give 120Hz (8ms) as slowest frequency (with pre-scaler or 1 and 128 times slower with prescaler of 128)
From 2MHz 30Hz (32ms)
Therefore the best solution is to use an external 32kHz source (TPM_CLOCKED_FROM_OSCERCLK) which allows down to 2Hz (488ms)
These are with no pre-scaler:
You can choose pre-scaler from 1 to 128 (
PWM_PRESCALER_1,
PWM_PRESCALER_2, ....
PWM_PRESCALER_128) to divide further.
The pre-scaler value is valid for each individual timer, eg.
pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_16);When setting the PWM frequecy use the same pre-scaler value in the equation, eg.:
pwm_setup.pwm_frequency = PWM_TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(1000), 16);Although not exactly the same in the KL03 the following give some ideas of also cascading timers or using lower frequencies:
https://community.nxp.com/message/1006476https://community.nxp.com/message/1006476Regards
Mark