-
- kputs("PWM test\n\n");
-
- kputs("Init pwm..");
-
- pwm_init();
- kputs("done.\n");
-
- PWM_TEST_CH_SET(0);
- kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH0, PWM_TEST_CH0_FREQ, PWM_TEST_CH0_DUTY);
- PWM_TEST_CH_SET(1);
- kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH1, PWM_TEST_CH1_FREQ, PWM_TEST_CH1_DUTY);
- PWM_TEST_CH_SET(2);
- kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH2, PWM_TEST_CH2_FREQ, PWM_TEST_CH2_DUTY);
- PWM_TEST_CH_SET(3);
- kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH3, PWM_TEST_CH3_FREQ, PWM_TEST_CH3_DUTY);
+ int duty = 0;
+ int delay = 0;
+
+ pwm_testSetup();
+
+ LOG_INFO("\n\n===== BeRTOS PWM test =====\n\n");
+
+ for (int i = 0; i < PWM_CNT; i++)
+ {
+ LOG_INFO("PWM test ch[%d]\n", pwm_test_cfg[i].ch);
+ LOG_INFO("--> set pol[%d]", pwm_test_cfg[i].pol);
+ LOG_INFO("\n(Note: if polarity is false the output waveform start at high level,\n see low level implentation for detail)i\n");
+ pwm_setPolarity(pwm_test_cfg[i].ch, pwm_test_cfg[i].pol);
+ LOG_INFO("..ok\n");
+
+ LOG_INFO("--> set freq[%ld]", pwm_test_cfg[i].freq);
+ pwm_setFrequency(pwm_test_cfg[i].ch, pwm_test_cfg[i].freq);
+ LOG_INFO("..ok\n");
+
+ LOG_INFO("--> set duty[%d]", pwm_test_cfg[i].duty);
+ pwm_setDuty(pwm_test_cfg[i].ch, pwm_test_cfg[i].duty);
+ LOG_INFO("..ok\n");
+
+ LOG_INFO("--> Enable pwm");
+ pwm_enable(pwm_test_cfg[i].ch, true);
+ LOG_INFO("..ok\n");
+ }
+
+ LOG_INFO("\n-------------------------- Dinamic PWM test --------------------------\n");
+ LOG_INFO("We test if driver change correctly the duty cycle durind it working.\n");
+ LOG_INFO("On your oscilloscope you should see the pwm singal that increase until\n");
+ LOG_INFO("the duty value is 100%%. After this value we invert a polarity of pwm,\n");
+ LOG_INFO("and repeat the test. But now you should see that pwm duty decreasing until\n");
+ LOG_INFO("0%% duty value.\nAfter that, we repeat the test from beginning.\n\n");
+
+ for (;;)
+ {
+ if (delay == DELAY_TIME)
+ {
+ for (int i = 0; i < PWM_CNT; i++)
+ {
+ LOG_INFO("PWM test ch[%d]\n", pwm_test_cfg[i].ch);
+ LOG_INFO("--> set duty[%d]", duty);
+ pwm_setDuty(pwm_test_cfg[i].ch, duty);
+ LOG_INFO("..ok\n");
+ }
+ LOG_INFO("\n++++++++++++++++++++\n");
+ duty += PWM_DUTY_INC;
+ delay = 0;
+ }
+
+ //Reset duty cycle overflow
+ if (duty >= 0xFFFF)
+ {
+ duty = 0;
+ for (int i = 0; i < PWM_CNT; i++)
+ {
+ LOG_INFO("Duty reset, swap polarity:\n");
+ LOG_INFO("--> pol from [%d] to [%d]", pwm_test_cfg[i].pol, !pwm_test_cfg[i].pol);
+
+ pwm_test_cfg[i].pol = !pwm_test_cfg[i].pol;
+ pwm_setPolarity(pwm_test_cfg[i].ch, pwm_test_cfg[i].pol);
+
+ LOG_INFO("..ok\n");
+ }
+ LOG_INFO("\n++++++++++++++++++++\n");
+ }
+ delay++;
+ }
+
+ return 0;