user3163745
user3163745

Reputation: 41

PWM output is not working on STM32F10x OPEN107V Development board

Hello I have got "stm32f10x open107V development board" ,I have modified the code for PWM which was given by the manufacturer ,but I am not getting any PWM output on leds given on development board please anybody help with for the following code. GPIO_pins 0,1,14,15 on portB(GPIOB) are Led pins given on development board.The code is error free and has no errors while linking.As I was begginer I don't understand the what is the 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 and 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 and 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);  

     }

Upvotes: 2

Views: 2227

Answers (1)

swineone
swineone

Reputation: 2824

First of all, if you check on the STM32F107 datasheet (that's the MCU I assume that you have), the PB0 and PB1 pins can be mapped to TIM3_CH3 and TIM3_CH4, but PB14 and PB15 can't be mapped to any TIM3 channels -- only to TIM1 channels. See Table 5 on Section 3, for my version of the datasheet at least.

Second, you're using the AFIO remap feature, given the call to GPIO_PinRemapConfig(). The two pins that are indeed connected to the LEDs (PB0 and PB1) don't need a remap, while the other two (PB14 and PB15) can't be remapped to TIM3 channels no matter what you do.

Concretely, you can get PWM outputs on two pins (PB0 and PB1) with minimal code changes by just doing away with the call to GPIO_PinRemapConfig(). As for PB14 and PB15, you'll need to configure TIM1 which is going to need a lot of extra code. Unfortunately, there's just nothing you can do to map those pins to TIM3.

Upvotes: 1

Related Questions