Controlar el ancho de pulso de una señal cuadrada PWM. Generar una señal cuadrada con el módulo PWM. Visualizar las variaciones de ancho de pulso con un led.

Dependencies:   mbed

Committer:
CCastrop1012
Date:
Fri Sep 03 04:40:18 2021 +0000
Revision:
0:9eaed9723409
Se logra el objetivo descrito.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CCastrop1012 0:9eaed9723409 1 #include "mbed.h"
CCastrop1012 0:9eaed9723409 2 /**
CCastrop1012 0:9eaed9723409 3 Descripción: Controlar el ancho de pulso de una señal cuadrada PWM.
CCastrop1012 0:9eaed9723409 4 con un pulsador en Pull-up y mostrar su variación a travez de un led
CCastrop1012 0:9eaed9723409 5 conectado a un pin con salida PWM de la tarjeta.
CCastrop1012 0:9eaed9723409 6
CCastrop1012 0:9eaed9723409 7 */
CCastrop1012 0:9eaed9723409 8
CCastrop1012 0:9eaed9723409 9 PwmOut LED(LED1);
CCastrop1012 0:9eaed9723409 10 DigitalIn pulsador(PC_13);
CCastrop1012 0:9eaed9723409 11 int T=0;
CCastrop1012 0:9eaed9723409 12
CCastrop1012 0:9eaed9723409 13
CCastrop1012 0:9eaed9723409 14 main(){
CCastrop1012 0:9eaed9723409 15 while (1)
CCastrop1012 0:9eaed9723409 16 {
CCastrop1012 0:9eaed9723409 17
CCastrop1012 0:9eaed9723409 18 while (pulsador == 0)
CCastrop1012 0:9eaed9723409 19 {
CCastrop1012 0:9eaed9723409 20 T++;
CCastrop1012 0:9eaed9723409 21 if (T>2) T=1;
CCastrop1012 0:9eaed9723409 22 wait(0.3);
CCastrop1012 0:9eaed9723409 23 }
CCastrop1012 0:9eaed9723409 24
CCastrop1012 0:9eaed9723409 25 LED.pulsewidth(T);
CCastrop1012 0:9eaed9723409 26 LED.period(4);
CCastrop1012 0:9eaed9723409 27
CCastrop1012 0:9eaed9723409 28 ///DigitalOut myled(LED1);
CCastrop1012 0:9eaed9723409 29
CCastrop1012 0:9eaed9723409 30 //int main() C
CCastrop1012 0:9eaed9723409 31
CCastrop1012 0:9eaed9723409 32 ///SPWM.period_ms(2000);
CCastrop1012 0:9eaed9723409 33 ///SPWM.pulsewidth_ms(1000);
CCastrop1012 0:9eaed9723409 34
CCastrop1012 0:9eaed9723409 35 }
CCastrop1012 0:9eaed9723409 36 }