mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 #include "test_env.h"
elessair 0:f269e3021894 2
elessair 0:f269e3021894 3 /* Timer/Match Register Pinout Options
elessair 0:f269e3021894 4
elessair 0:f269e3021894 5 CT16B0/MR0 p5 (P0_9)
elessair 0:f269e3021894 6 CT16B0/MR1 p6 (P0_8)
elessair 0:f269e3021894 7 CT16B0/MR2 p34 (P1_15)
elessair 0:f269e3021894 8
elessair 0:f269e3021894 9 CT16B1/MR0 p36 (P0_21)
elessair 0:f269e3021894 10 CT16B1/MR1 p20 (P0_22) and p14 (P1_23)
elessair 0:f269e3021894 11
elessair 0:f269e3021894 12 CT32B0/MR0 p25 (P1_24)
elessair 0:f269e3021894 13 CT32B0/MR1 p26 (P1_25) and USBTX (P0_19)
elessair 0:f269e3021894 14 CT32B0/MR2 p10 (P1_26)
elessair 0:f269e3021894 15 */
elessair 0:f269e3021894 16
elessair 0:f269e3021894 17 float value = 0.75;
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 int main() {
elessair 0:f269e3021894 20 #if defined(TARGET_FF_ARDUINO)
elessair 0:f269e3021894 21 PwmOut pwm(D9);
elessair 0:f269e3021894 22 int period_ms = 10;
elessair 0:f269e3021894 23
elessair 0:f269e3021894 24 pwm.period_ms(period_ms);
elessair 0:f269e3021894 25 pwm.write(value);
elessair 0:f269e3021894 26
elessair 0:f269e3021894 27 float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 28 printf("PWM period = %dms with duty cycle: %d%%\n", period_ms, (int) (result * 100));
elessair 0:f269e3021894 29
elessair 0:f269e3021894 30 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 31 #elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC2460)
elessair 0:f269e3021894 32 PwmOut pwm_p25(p25);
elessair 0:f269e3021894 33 PwmOut pwm_p26(p26);
elessair 0:f269e3021894 34
elessair 0:f269e3021894 35 pwm_p25.write(0.75);
elessair 0:f269e3021894 36 pwm_p26.write(0.50);
elessair 0:f269e3021894 37
elessair 0:f269e3021894 38 printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
elessair 0:f269e3021894 39 printf("Initialize PWM on pin 26 with duty cycle: %.2f\n", pwm_p26.read());
elessair 0:f269e3021894 40
elessair 0:f269e3021894 41 #elif defined(TARGET_LPC1114)
elessair 0:f269e3021894 42 PwmOut pwm_dp24(dp24); // P0_1
elessair 0:f269e3021894 43 PwmOut pwm_dp18(dp18); // P1_9
elessair 0:f269e3021894 44
elessair 0:f269e3021894 45 pwm_dp24.write(0.75);
elessair 0:f269e3021894 46 pwm_dp18.write(0.50);
elessair 0:f269e3021894 47
elessair 0:f269e3021894 48 printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_dp24.read());
elessair 0:f269e3021894 49 printf("Initialize PWM on pin 18 with duty cycle: %.2f\n", pwm_dp18.read());
elessair 0:f269e3021894 50
elessair 0:f269e3021894 51 #elif defined(TARGET_LPC1347)
elessair 0:f269e3021894 52 PwmOut pwm_1(P0_18);
elessair 0:f269e3021894 53 PwmOut pwm_2(P0_9);
elessair 0:f269e3021894 54
elessair 0:f269e3021894 55 pwm_1.write(0.75);
elessair 0:f269e3021894 56 pwm_2.write(0.50);
elessair 0:f269e3021894 57
elessair 0:f269e3021894 58 printf("Initialize PWM on P0_18 with duty cycle: %.2f\n", pwm_1.read());
elessair 0:f269e3021894 59 printf("Initialize PWM on P0_9 with duty cycle: %.2f\n", pwm_2.read());
elessair 0:f269e3021894 60
elessair 0:f269e3021894 61 #elif defined(TARGET_NRF51822)
elessair 0:f269e3021894 62 PwmOut pwm_p24(p24);
elessair 0:f269e3021894 63 PwmOut pwm_p25(p25);
elessair 0:f269e3021894 64
elessair 0:f269e3021894 65 pwm_p24.write(0.75);
elessair 0:f269e3021894 66 pwm_p25.write(0.50);
elessair 0:f269e3021894 67
elessair 0:f269e3021894 68 printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_p24.read());
elessair 0:f269e3021894 69 printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
elessair 0:f269e3021894 70
elessair 0:f269e3021894 71 #elif defined(TARGET_DISCO_F100RB)
elessair 0:f269e3021894 72 PwmOut pwm_1(PB_3);
elessair 0:f269e3021894 73 PwmOut pwm_2(PB_4);
elessair 0:f269e3021894 74
elessair 0:f269e3021894 75 pwm_1.write(0.75);
elessair 0:f269e3021894 76 pwm_2.write(0.50);
elessair 0:f269e3021894 77
elessair 0:f269e3021894 78 printf("Initialize PWM on pin PB_3 with duty cycle: %.2f\n", pwm_1.read());
elessair 0:f269e3021894 79 printf("Initialize PWM on pin PB_4 with duty cycle: %.2f\n", pwm_2.read());
elessair 0:f269e3021894 80 #elif defined(TARGET_DISCO_F051R8)
elessair 0:f269e3021894 81 PwmOut pwm_1(PA_7);
elessair 0:f269e3021894 82 PwmOut pwm_2(PC_7);
elessair 0:f269e3021894 83
elessair 0:f269e3021894 84 pwm_1.write(0.75);
elessair 0:f269e3021894 85 pwm_2.write(0.50);
elessair 0:f269e3021894 86
elessair 0:f269e3021894 87 printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
elessair 0:f269e3021894 88 printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
elessair 0:f269e3021894 89 #elif defined(TARGET_DISCO_F303VC)
elessair 0:f269e3021894 90 PwmOut pwm_1(PA_8);
elessair 0:f269e3021894 91 PwmOut pwm_2(PA_9);
elessair 0:f269e3021894 92
elessair 0:f269e3021894 93 pwm_1.write(0.75);
elessair 0:f269e3021894 94 pwm_2.write(0.50);
elessair 0:f269e3021894 95
elessair 0:f269e3021894 96 printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
elessair 0:f269e3021894 97 printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
elessair 0:f269e3021894 98 #elif defined(TARGET_MAXWSNENV)
elessair 0:f269e3021894 99 PwmOut pwm_1(TP2);
elessair 0:f269e3021894 100 PwmOut pwm_2(TP4);
elessair 0:f269e3021894 101
elessair 0:f269e3021894 102 pwm_1.write(0.75);
elessair 0:f269e3021894 103 pwm_2.write(0.50);
elessair 0:f269e3021894 104
elessair 0:f269e3021894 105 printf("Initialize PWM on pin TP2 with duty cycle: %.2f\n", pwm_1.read());
elessair 0:f269e3021894 106 printf("Initialize PWM on pin TP4 with duty cycle: %.2f\n", pwm_2.read());
elessair 0:f269e3021894 107 #elif defined(TARGET_DISCO_F407VG)
elessair 0:f269e3021894 108 PwmOut pwm_1(PD_12);
elessair 0:f269e3021894 109 PwmOut pwm_2(PD_13);
elessair 0:f269e3021894 110
elessair 0:f269e3021894 111 pwm_1.write(value);
elessair 0:f269e3021894 112 pwm_2.write(0.50);
elessair 0:f269e3021894 113
elessair 0:f269e3021894 114 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 115
elessair 0:f269e3021894 116 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 117 printf("Initialize PWM on pin PD_13 with duty cycle: %.2f\n", pwm_2.read());
elessair 0:f269e3021894 118
elessair 0:f269e3021894 119 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 120 #elif defined(TARGET_DISCO_F429ZI) || defined(TARGET_NUCLEO_F429ZI)
elessair 0:f269e3021894 121 PwmOut pwm_1(PA_0);
elessair 0:f269e3021894 122
elessair 0:f269e3021894 123 pwm_1.write(value);
elessair 0:f269e3021894 124
elessair 0:f269e3021894 125 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 126
elessair 0:f269e3021894 127 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 128
elessair 0:f269e3021894 129 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 130 #elif defined(TARGET_MTS_MDOT_F405RG)
elessair 0:f269e3021894 131 PwmOut pwm_1(PA_0);
elessair 0:f269e3021894 132
elessair 0:f269e3021894 133 pwm_1.write(value);
elessair 0:f269e3021894 134
elessair 0:f269e3021894 135 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 136
elessair 0:f269e3021894 137 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 138
elessair 0:f269e3021894 139 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 140 #elif defined(TARGET_MTS_DRAGONFLY_F411RE)
elessair 0:f269e3021894 141 PwmOut pwm_1(PA_0);
elessair 0:f269e3021894 142
elessair 0:f269e3021894 143 pwm_1.write(value);
elessair 0:f269e3021894 144
elessair 0:f269e3021894 145 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 146
elessair 0:f269e3021894 147 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 148
elessair 0:f269e3021894 149 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 150 #elif defined(TARGET_MTS_MDOT_F411RE)
elessair 0:f269e3021894 151 PwmOut pwm_1(PA_0);
elessair 0:f269e3021894 152
elessair 0:f269e3021894 153 pwm_1.write(value);
elessair 0:f269e3021894 154
elessair 0:f269e3021894 155 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 156
elessair 0:f269e3021894 157 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 158
elessair 0:f269e3021894 159 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 160 #elif defined(TARGET_UBLOX_EVK_ODIN_W2)
elessair 0:f269e3021894 161 PwmOut pwm_1(PA_0);
elessair 0:f269e3021894 162
elessair 0:f269e3021894 163 pwm_1.write(value);
elessair 0:f269e3021894 164
elessair 0:f269e3021894 165 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 166
elessair 0:f269e3021894 167 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 168
elessair 0:f269e3021894 169 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 170 #elif defined(TARGET_MAX32600MBED)
elessair 0:f269e3021894 171 PwmOut pwm_1(P1_2);
elessair 0:f269e3021894 172 PwmOut pwm_2(P1_3);
elessair 0:f269e3021894 173
elessair 0:f269e3021894 174 pwm_1.write(0.75);
elessair 0:f269e3021894 175 pwm_2.write(0.50);
elessair 0:f269e3021894 176
elessair 0:f269e3021894 177 printf("Initialize PWM on pin P1.2 with duty cycle: %.2f\n", pwm_1.read());
elessair 0:f269e3021894 178 printf("Initialize PWM on pin P1.3 with duty cycle: %.2f\n", pwm_2.read());
elessair 0:f269e3021894 179 #elif defined(TARGET_SAMR21G18A) || defined(TARGET_SAMD21J18A) || defined(TARGET_SAMD21G18A) || defined(TARGET_SAML21J18A)
elessair 0:f269e3021894 180 PwmOut pwm(LED1);
elessair 0:f269e3021894 181
elessair 0:f269e3021894 182 pwm.period_ms(1000);
elessair 0:f269e3021894 183 pwm.write(value);
elessair 0:f269e3021894 184
elessair 0:f269e3021894 185 float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 186 printf("Initialize PWM on pin LED1 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 187
elessair 0:f269e3021894 188 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 189 #elif defined(TARGET_SAMG55J19)
elessair 0:f269e3021894 190 PwmOut pwm(PA00); /*LED Doesnt support PWM for G55 XPro*/
elessair 0:f269e3021894 191
elessair 0:f269e3021894 192 pwm.period_ms(1000);
elessair 0:f269e3021894 193 pwm.write(value);
elessair 0:f269e3021894 194
elessair 0:f269e3021894 195 float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
elessair 0:f269e3021894 196 printf("Initialize PWM on pin PA01 with duty cycle: %.2f\n", result);
elessair 0:f269e3021894 197
elessair 0:f269e3021894 198 notify_completion(result == value ? true : false);
elessair 0:f269e3021894 199 #else
elessair 0:f269e3021894 200 #error [NOT_SUPPORTED] This test is not supported on this target.
elessair 0:f269e3021894 201 #endif
elessair 0:f269e3021894 202
elessair 0:f269e3021894 203 notify_completion(true);
elessair 0:f269e3021894 204 }