Fixed base frequency relation with counter top value
#include <bsp/bsp.h>
struct pwm_dev *pwm;
-static int value = 10000;
+uint16_t max_val;
int
main(int argc, char **argv)
@@ -33,32 +33,34 @@ main(int argc, char **argv)
.inverted = true,
.data = NULL
};
+ uint32_t base_freq;
sysinit();
pwm = (struct pwm_dev *) os_dev_open("pwm0", 0, NULL);
- /* setup led 1 */
+ /* set the PWM frequency */
+ base_freq = pwm_set_frequency(pwm, 10000);
+ max_val = (uint16_t) base_freq / 100;
+
+ /* setup led 1 - 100% duty cycle*/
pwm_chan_config(pwm, 0, &chan_conf);
- pwm_enable_duty_cycle(pwm, 0, 10000);
+ pwm_enable_duty_cycle(pwm, 0, max_val);
- /* setup led 2 */
+ /* setup led 2 - 50% duty cycle */
chan_conf.pin = LED_2;
pwm_chan_config(pwm, 1, &chan_conf);
- pwm_enable_duty_cycle(pwm, 1, value/10);
-
- /* change frequency while playing */
- pwm_set_frequency(pwm, 2000000);
+ pwm_enable_duty_cycle(pwm, 1, max_val/2);
- /* setup led 3 */
+ /* setup led 3 - 25% duty cycle */
chan_conf.pin = LED_3;
pwm_chan_config(pwm, 2, &chan_conf);
- pwm_enable_duty_cycle(pwm, 2, value/100);
+ pwm_enable_duty_cycle(pwm, 2, max_val/4);
- /* setup led 4 */
+ /* setup led 4 - 10% duty cycle */
chan_conf.pin = LED_4;
pwm_chan_config(pwm, 3, &chan_conf);
- pwm_enable_duty_cycle(pwm, 3, value/1000);
+ pwm_enable_duty_cycle(pwm, 3, max_val/10);
while (1) {
os_eventq_run(os_eventq_dflt_get());
