c - PWM output is not working on STM32F10x OPEN107V Development board -
hello have got "stm32f10x open107v development board" ,i have modified code pwm given manufacturer ,but not getting pwm output on leds given on development board please following code. gpio_pins 0,1,14,15 on portb(gpiob) led pins given on development board.the code error free , has no errors while linking.as begginer don't understand problem.
/** -----------------------------------------------------------------*/ #include "stm32f10x_gpio.h" #include "stm32f10x_rcc.h" #include "stm32f10x_tim.h" tim_timebaseinittypedef tim_timebasestructure; tim_ocinittypedef tim_ocinitstructure; uint16_t ccr1_val = 333; uint16_t ccr2_val = 249; uint16_t ccr3_val = 166; uint16_t ccr4_val = 83; uint16_t prescalervalue ; /* private function prototypes -----------------------------------------------*/ void rcc_configuration(void); void gpio_configuration(void); /* private functions ---------------------------------------------------------*/ /** int main(void) { rcc_configuration(); /*gpio configuration */ gpio_configuration(); prescalervalue =(72000000 / 24000000) - 1; /* time base configuration */ tim_timebasestructure.tim_period = 665; tim_timebasestructure.tim_prescaler = prescalervalue; tim_timebasestructure.tim_clockdivision = 4; tim_timebasestructure.tim_countermode = tim_countermode_up; tim_timebaseinit(tim3, &tim_timebasestructure); /* pwm1 mode configuration: channel1 */ tim_ocinitstructure.tim_ocmode = tim_ocmode_pwm1; tim_ocinitstructure.tim_outputstate = tim_outputstate_enable; tim_ocinitstructure.tim_pulse = ccr1_val; tim_ocinitstructure.tim_ocpolarity = tim_ocpolarity_high; tim_oc1init(tim3, &tim_ocinitstructure); tim_oc1preloadconfig(tim3, tim_ocpreload_enable); /* pwm1 mode configuration: channel2 */ tim_ocinitstructure.tim_outputstate = tim_outputstate_enable; tim_ocinitstructure.tim_pulse = ccr2_val; tim_oc2init(tim3, &tim_ocinitstructure); tim_oc2preloadconfig(tim3, tim_ocpreload_enable); /* pwm1 mode configuration: channel3 */ tim_ocinitstructure.tim_outputstate = tim_outputstate_enable; tim_ocinitstructure.tim_pulse = ccr3_val; tim_oc3init(tim3, &tim_ocinitstructure); tim_oc3preloadconfig(tim3, tim_ocpreload_enable); /* tim3 enable counter */ tim_cmd(tim3, enable); while (1) {} } void rcc_configuration(void) { /* tim3 clock enable */ rcc_apb1periphclockcmd(rcc_apb1periph_tim3, enable); /* gpioa , gpiob clock enable */ rcc_apb2periphclockcmd( rcc_apb2periph_gpiob | rcc_apb2periph_afio, enable); } void gpio_configuration(void) { gpio_inittypedef gpio_initstructure; /*gpiob configuration: tim3 channel1, 2, 3 , 4 */ gpio_initstructure.gpio_pin = gpio_pin_0 | gpio_pin_1 | gpio_pin_14|gpio_pin_15 ; gpio_initstructure.gpio_mode = gpio_mode_af_pp; gpio_initstructure.gpio_speed = gpio_speed_50mhz; gpio_init(gpiob, &gpio_initstructure); gpio_pinremapconfig(gpio_fullremap_tim3, enable); }
first of all, if check on stm32f107 datasheet (that's mcu assume have), pb0 , pb1 pins can mapped tim3_ch3 , tim3_ch4, pb14 , pb15 can't mapped tim3 channels -- tim1 channels. see table 5 on section 3, version of datasheet @ least.
second, you're using afio remap feature, given call gpio_pinremapconfig()
. 2 pins indeed connected leds (pb0 , pb1) don't need remap, while other 2 (pb14 , pb15) can't remapped tim3 channels no matter do.
concretely, can pwm outputs on 2 pins (pb0 , pb1) minimal code changes doing away call gpio_pinremapconfig()
. pb14 , pb15, you'll need configure tim1 going need lot of code. unfortunately, there's nothing can map pins tim3.
Comments
Post a Comment