QC

PWM STM32 MBED

 PWM STM32 MBED

PHẦN 1: MỤC TIÊU PWM

- Điều khiển đèn sáng tối ( vd đèn ngủ ... ).

- Điều khiển tốc độ động cơ ..

.... 

#include "mbed.h"
PwmOut LED_0(PA_8); //TIM1_CH1
//OUT PWM STM32F103 LQFP64
//PA_8,PA_9,PA_10,PA_11: TIM1_CH1,TIM1_CH2,TIM1_CH3,TIM1_CH4 
//PA_6,PA_7,PB_0,PB_1  : TIM3_CH1,TIM3_CH2,TIM3_CH3,TIM3_CH4 
//PA_0,PA_1,PA_2,PA_3  : TIM5_CH1,TIM5_CH2,TIM5_CH3,TIM5_CH4 
//remap
//PA_1,PA_2,PA_3       : TIM2_CH2,TIM2_CH3,TIM2_CH4 
//Note:
//The default period is 0.020s, and the default pulse width is 0.
//LED_0.period(4.0f);  // 4 second period
//LED_0 = 0.5f;        // duty cycle, relative to period, shorthand for LED_0.write(0.5f); =>2s
//OR LED_0.write(0.5f);
//LED_0.pulsewidth(2); // alternative to LED_0.write, set duty cycle time in seconds

int main() {
    float value=0; //0%
    LED_0.period(0.002f);      // 2ms period
    LED_0.write(value);       // value in % duty cycle
 

    while(1) {   
        while(value<1.0){
            LED_0.write(value); 
            wait_ms(10);
            value +=0.01;
        }
        value = 0;
    }
}





Nap Code vào PY32F003 dùng Stlink

 Nap Code vào PY32F003 dùng Stlink Bước 1: Cài đặt  KeilC v5.39 theo link sau ( chú ý 5.39 keil c mới nạp ok). https://edge07.111.ir.cdn.ir/...