I need to use a PWM to control the light, it need to able to adjust the frequency and duty arbitrarily.I can't find an example in the SDK.Can you provide an example for my reference, thanks
Hi Daniel, I hope you're doing well!
The CTIMER and SCTIMER examples included in the SDK may help give you an idea on how to use a CTIMER/SCTIMER to generate a PWM of a certain frequency and duty cycle.
These can be found in the following paths:
The CTIMER_SetupPwm function initially configures the duty cycle and frequency, and the CTIMER_UpdatePwmDutycycle function can then be used to update to a different duty cycle.
Please let me know if you need any more information.
After reading SCTimer example, I have the following questions 1. Can I reverse the waveform? 2. Example default frequency of 24k , What is the maximum and minimum frequency range? 3. Example only adjust duty cycle, but do not see adjustment frequency function？
The SCTIMER functions provide a better interface to control the level of the generated PWM, allowing it to be either High or Low true.
The frequency of the PWM is configured with the SCTIMER_SetupPwm function, but to update the PWM frequency, a custom function may need to be implemented.
The maximum frequency is approximately half the configured Bus Clock frequency.
For more information, could you please take a look at the SCTIMER with PWM Duty Cycle change example? I can be found in the following path:
1. I also look at this example. What is the maximum frequency that can be reached in this example? How to calculate frequency
2. Inverted waveform as shown below?
3. A custom function may need to be implemented on frequency.
How would it be easier to achieve this?
To change the ActiveLow/High configuration for a PWM signal, the level element of the sctimer_pwm_signal_param_t structure is the one responsible for establishing which value is considered "TRUE" for the generated PWM signal.
The maximum frequency achievable using the PWM SCTIMER functions is around 800kHz, any more than that, and the signal could get really deformed or not be generated as intended.
To be able to change the frequency when the SCTIMER is already running, the timer first has to be stopped using the SCTIMER_StopTimer function, then the new frequency can be established by using the SCTIMER_SetupPwm again, and then starting the timer again, with the SCTIMER_StartTimer function, for example:
SCTIMER_StopTimer(SCT0, kSCTIMER_Counter_L);SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_CenterAlignedPwm, 30000U, sctimerClock, &eventNumberOutput4);SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_L);
Dear Sebastian:Thank you for your best and quick reply.I already know how to use PWMThank youDaniel
Please let me know if you have any further questions!
Retrieving data ...