2013-02-18 15:32:11 +00:00
|
|
|
#include "test_env.h"
|
|
|
|
|
|
|
|
/* Timer/Match Register Pinout Options
|
|
|
|
|
|
|
|
CT16B0/MR0 p5 (P0_9)
|
|
|
|
CT16B0/MR1 p6 (P0_8)
|
|
|
|
CT16B0/MR2 p34 (P1_15)
|
|
|
|
|
|
|
|
CT16B1/MR0 p36 (P0_21)
|
|
|
|
CT16B1/MR1 p20 (P0_22) and p14 (P1_23)
|
|
|
|
|
|
|
|
CT32B0/MR0 p25 (P1_24)
|
|
|
|
CT32B0/MR1 p26 (P1_25) and USBTX (P0_19)
|
|
|
|
CT32B0/MR2 p10 (P1_26)
|
|
|
|
*/
|
2014-05-29 13:49:47 +00:00
|
|
|
|
2014-04-03 19:30:01 +00:00
|
|
|
float value = 0.75;
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
int main() {
|
2014-04-04 11:24:21 +00:00
|
|
|
#if defined(TARGET_FF_ARDUINO)
|
2014-04-07 15:48:56 +00:00
|
|
|
PwmOut pwm(D9);
|
2016-05-04 06:59:57 +00:00
|
|
|
int period_ms = 10;
|
2014-04-03 19:30:01 +00:00
|
|
|
|
2016-05-04 06:59:57 +00:00
|
|
|
pwm.period_ms(period_ms);
|
2014-04-03 19:30:01 +00:00
|
|
|
pwm.write(value);
|
|
|
|
|
|
|
|
float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
|
2016-05-04 06:59:57 +00:00
|
|
|
printf("PWM period = %dms with duty cycle: %d%%\n", period_ms, (int) (result * 100));
|
2014-04-03 19:30:01 +00:00
|
|
|
|
|
|
|
notify_completion(result == value ? true : false);
|
2015-05-18 09:31:10 +00:00
|
|
|
#elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC2460)
|
2014-04-03 19:30:01 +00:00
|
|
|
PwmOut pwm_p25(p25);
|
2013-02-18 15:32:11 +00:00
|
|
|
PwmOut pwm_p26(p26);
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
pwm_p25.write(0.75);
|
|
|
|
pwm_p26.write(0.50);
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
|
|
|
|
printf("Initialize PWM on pin 26 with duty cycle: %.2f\n", pwm_p26.read());
|
2013-02-26 14:57:42 +00:00
|
|
|
|
2013-07-26 09:12:49 +00:00
|
|
|
#elif defined(TARGET_LPC1114)
|
2013-09-09 09:15:51 +00:00
|
|
|
PwmOut pwm_dp24(dp24); // P0_1
|
|
|
|
PwmOut pwm_dp18(dp18); // P1_9
|
2013-07-26 09:12:49 +00:00
|
|
|
|
2013-09-09 09:15:51 +00:00
|
|
|
pwm_dp24.write(0.75);
|
|
|
|
pwm_dp18.write(0.50);
|
2013-07-26 09:12:49 +00:00
|
|
|
|
2013-09-09 09:15:51 +00:00
|
|
|
printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_dp24.read());
|
|
|
|
printf("Initialize PWM on pin 18 with duty cycle: %.2f\n", pwm_dp18.read());
|
2013-07-26 09:12:49 +00:00
|
|
|
|
2016-09-26 07:07:41 +00:00
|
|
|
#elif defined(TARGET_LPC1347)
|
|
|
|
PwmOut pwm_1(P0_18);
|
|
|
|
PwmOut pwm_2(P0_9);
|
|
|
|
|
|
|
|
pwm_1.write(0.75);
|
|
|
|
pwm_2.write(0.50);
|
|
|
|
|
|
|
|
printf("Initialize PWM on P0_18 with duty cycle: %.2f\n", pwm_1.read());
|
|
|
|
printf("Initialize PWM on P0_9 with duty cycle: %.2f\n", pwm_2.read());
|
|
|
|
|
2016-02-26 17:51:35 +00:00
|
|
|
#elif defined(TARGET_NRF51822)
|
2014-01-08 10:14:19 +00:00
|
|
|
PwmOut pwm_p24(p24);
|
2014-04-03 19:30:01 +00:00
|
|
|
PwmOut pwm_p25(p25);
|
2014-01-08 10:14:19 +00:00
|
|
|
|
|
|
|
pwm_p24.write(0.75);
|
|
|
|
pwm_p25.write(0.50);
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_p24.read());
|
|
|
|
printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
|
2014-03-19 12:15:59 +00:00
|
|
|
|
|
|
|
#elif defined(TARGET_DISCO_F100RB)
|
2014-05-29 13:49:47 +00:00
|
|
|
PwmOut pwm_1(PB_3);
|
2014-03-19 12:15:59 +00:00
|
|
|
PwmOut pwm_2(PB_4);
|
|
|
|
|
|
|
|
pwm_1.write(0.75);
|
|
|
|
pwm_2.write(0.50);
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin PB_3 with duty cycle: %.2f\n", pwm_1.read());
|
|
|
|
printf("Initialize PWM on pin PB_4 with duty cycle: %.2f\n", pwm_2.read());
|
2014-03-21 11:23:13 +00:00
|
|
|
#elif defined(TARGET_DISCO_F051R8)
|
2014-05-29 13:49:47 +00:00
|
|
|
PwmOut pwm_1(PA_7);
|
2014-03-21 11:23:13 +00:00
|
|
|
PwmOut pwm_2(PC_7);
|
|
|
|
|
|
|
|
pwm_1.write(0.75);
|
|
|
|
pwm_2.write(0.50);
|
|
|
|
|
2014-04-08 13:30:24 +00:00
|
|
|
printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
|
|
|
|
printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
|
|
|
|
#elif defined(TARGET_DISCO_F303VC)
|
2014-05-29 13:49:47 +00:00
|
|
|
PwmOut pwm_1(PA_8);
|
2014-04-08 13:30:24 +00:00
|
|
|
PwmOut pwm_2(PA_9);
|
|
|
|
|
|
|
|
pwm_1.write(0.75);
|
|
|
|
pwm_2.write(0.50);
|
|
|
|
|
2014-03-21 11:23:13 +00:00
|
|
|
printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
|
|
|
|
printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
|
2014-10-09 16:54:03 +00:00
|
|
|
#elif defined(TARGET_MAXWSNENV)
|
|
|
|
PwmOut pwm_1(TP2);
|
|
|
|
PwmOut pwm_2(TP4);
|
|
|
|
|
|
|
|
pwm_1.write(0.75);
|
|
|
|
pwm_2.write(0.50);
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin TP2 with duty cycle: %.2f\n", pwm_1.read());
|
|
|
|
printf("Initialize PWM on pin TP4 with duty cycle: %.2f\n", pwm_2.read());
|
2015-04-04 22:11:13 +00:00
|
|
|
#elif defined(TARGET_DISCO_F407VG)
|
|
|
|
PwmOut pwm_1(PD_12);
|
|
|
|
PwmOut pwm_2(PD_13);
|
|
|
|
|
2015-04-04 23:08:23 +00:00
|
|
|
pwm_1.write(value);
|
2015-04-04 22:11:13 +00:00
|
|
|
pwm_2.write(0.50);
|
2016-02-26 17:51:35 +00:00
|
|
|
|
2015-04-04 23:08:23 +00:00
|
|
|
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
2015-04-04 22:11:13 +00:00
|
|
|
|
2015-04-04 23:08:23 +00:00
|
|
|
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
2015-04-04 22:11:13 +00:00
|
|
|
printf("Initialize PWM on pin PD_13 with duty cycle: %.2f\n", pwm_2.read());
|
2015-04-04 23:08:23 +00:00
|
|
|
|
2015-04-05 00:27:34 +00:00
|
|
|
notify_completion(result == value ? true : false);
|
2016-07-04 13:04:58 +00:00
|
|
|
#elif defined(TARGET_DISCO_F429ZI) || defined(TARGET_NUCLEO_F429ZI)
|
2015-04-05 00:27:34 +00:00
|
|
|
PwmOut pwm_1(PA_0);
|
|
|
|
|
|
|
|
pwm_1.write(value);
|
2016-02-26 17:51:35 +00:00
|
|
|
|
2015-04-05 00:27:34 +00:00
|
|
|
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
|
|
|
|
2015-04-06 21:48:00 +00:00
|
|
|
notify_completion(result == value ? true : false);
|
|
|
|
#elif defined(TARGET_MTS_MDOT_F405RG)
|
|
|
|
PwmOut pwm_1(PA_0);
|
|
|
|
|
|
|
|
pwm_1.write(value);
|
2016-02-26 17:51:35 +00:00
|
|
|
|
2015-04-06 21:48:00 +00:00
|
|
|
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
|
|
|
|
|
|
|
notify_completion(result == value ? true : false);
|
|
|
|
#elif defined(TARGET_MTS_DRAGONFLY_F411RE)
|
|
|
|
PwmOut pwm_1(PA_0);
|
|
|
|
|
|
|
|
pwm_1.write(value);
|
2016-02-26 17:51:35 +00:00
|
|
|
|
2015-04-06 21:48:00 +00:00
|
|
|
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
|
|
|
|
|
|
|
notify_completion(result == value ? true : false);
|
|
|
|
#elif defined(TARGET_MTS_MDOT_F411RE)
|
|
|
|
PwmOut pwm_1(PA_0);
|
|
|
|
|
|
|
|
pwm_1.write(value);
|
2016-02-26 17:51:35 +00:00
|
|
|
|
2015-04-06 21:48:00 +00:00
|
|
|
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
|
|
|
|
|
|
|
notify_completion(result == value ? true : false);
|
2016-10-01 08:01:18 +00:00
|
|
|
#elif defined(TARGET_UBLOX_EVK_ODIN_W2)
|
2015-04-06 21:48:00 +00:00
|
|
|
PwmOut pwm_1(PA_0);
|
|
|
|
|
|
|
|
pwm_1.write(value);
|
2016-02-26 17:51:35 +00:00
|
|
|
|
2015-04-06 21:48:00 +00:00
|
|
|
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
|
|
|
|
2015-04-04 23:08:23 +00:00
|
|
|
notify_completion(result == value ? true : false);
|
2014-10-09 16:54:03 +00:00
|
|
|
#elif defined(TARGET_MAX32600MBED)
|
|
|
|
PwmOut pwm_1(P1_2);
|
|
|
|
PwmOut pwm_2(P1_3);
|
|
|
|
|
|
|
|
pwm_1.write(0.75);
|
|
|
|
pwm_2.write(0.50);
|
|
|
|
|
|
|
|
printf("Initialize PWM on pin P1.2 with duty cycle: %.2f\n", pwm_1.read());
|
|
|
|
printf("Initialize PWM on pin P1.3 with duty cycle: %.2f\n", pwm_2.read());
|
2015-09-23 08:18:08 +00:00
|
|
|
#elif defined(TARGET_SAMR21G18A) || defined(TARGET_SAMD21J18A) || defined(TARGET_SAMD21G18A) || defined(TARGET_SAML21J18A)
|
2015-08-11 11:43:38 +00:00
|
|
|
PwmOut pwm(LED1);
|
2015-08-07 10:49:39 +00:00
|
|
|
|
|
|
|
pwm.period_ms(1000);
|
|
|
|
pwm.write(value);
|
|
|
|
|
|
|
|
float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
|
2015-08-11 11:43:38 +00:00
|
|
|
printf("Initialize PWM on pin LED1 with duty cycle: %.2f\n", result);
|
2015-08-07 10:49:39 +00:00
|
|
|
|
2016-04-05 17:05:59 +00:00
|
|
|
notify_completion(result == value ? true : false);
|
|
|
|
#elif defined(TARGET_SAMG55J19)
|
|
|
|
PwmOut pwm(PA00); /*LED Doesnt support PWM for G55 XPro*/
|
|
|
|
|
|
|
|
pwm.period_ms(1000);
|
|
|
|
pwm.write(value);
|
|
|
|
|
|
|
|
float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
|
|
|
|
printf("Initialize PWM on pin PA01 with duty cycle: %.2f\n", result);
|
|
|
|
|
2015-08-07 10:49:39 +00:00
|
|
|
notify_completion(result == value ? true : false);
|
2014-04-03 19:30:01 +00:00
|
|
|
#else
|
2016-02-26 17:51:35 +00:00
|
|
|
#error [NOT_SUPPORTED] This test is not supported on this target.
|
2013-02-26 14:57:42 +00:00
|
|
|
#endif
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
notify_completion(true);
|
|
|
|
}
|