From 4110b12b0cbc936dc3a0b18ef7faefe80d394281 Mon Sep 17 00:00:00 2001 From: "Troller Fabian (HES)" <fabian.troller@hepia-ws-8838-lx.hes.adhes.hesge.ch> Date: Thu, 15 Oct 2020 16:33:00 +0200 Subject: [PATCH] Add new pwm features --- labo1.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/labo1.cpp b/labo1.cpp index 274f80d..faed168 100644 --- a/labo1.cpp +++ b/labo1.cpp @@ -7,7 +7,7 @@ #include "mbed.h" -DigitalOut LED_0(P0_0); +DigitalOut LED_0(P2_0); DigitalOut LED_1(P0_1); DigitalOut LED_2(P0_2); DigitalOut LED_3(P0_3); @@ -161,15 +161,70 @@ void timer_mesure() } } -void MyNewPCB() +void PWM_de_base() +{ + while(1) + { + MonBus = 1; + wait_us(200); + MonBus = 3; + } +} + +void PWM_dormant() +{ + uint16_t pwmLed; + uint16_t cpt10ms = 0; + uint8_t cptPwm = 0; + + while (1) { + if (cptPwm == 0) + { + cpt10ms++; + if (cpt10ms < 100) + { + pwmLed = cpt10ms * 256 / 100; + } + else if (cpt10ms < 200) + { + pwmLed = 256 - ((cpt10ms - 100) * 256 / 100); + } + else + { + pwmLed = 0; + + } + + + if (cpt10ms == 400) + { + cpt10ms = 0; + } + } + + if ((cptPwm == 0) && (pwmLed > 0)) + { + LED_0 = 1; + } + + if (cptPwm == pwmLed) + { + LED_0 = 0; + } + cptPwm++; + wait_us(39); + } + +} + +void tri_phase() { - LED_1 = 1; } int main(void) { // Choisir le numero de l'exercice en changeant la valeur de 'exo'. - uint8_t exo = 9; + uint8_t exo = 10; while(1) { // Choix de l'exercice. Rajouter des exercices si besoin, en gardant la même @@ -183,7 +238,8 @@ int main(void) { case 6: exercice_sequence(); break; case 7: compter_rebond(); break; case 8: timer_mesure(); break; - case 9: MyNewPCB(); break; + case 9: PWM_de_base(); break; + case 10: PWM_dormant(); break; default: printf("Bad exercice number !\n"); } } -- GitLab