Skip to main content
emil_eriksson4
Associate
January 6, 2016
Question

STM32F100RCT6TR TIM12 issues

  • January 6, 2016
  • 12 replies
  • 3002 views
Posted on January 06, 2016 at 18:39

Hi!

I am trying to control two motors using an STM32F100RCT6TR microcontroller and the standard peripheral library version 3.5.0. I want to use TIM3 channel 1&2 and TIM12 channel 1&2. TIM3 works perfectly but I get nothing out of TIM12. None of the TIM12 registers that I look at using the debugging mode of IAR embedded workbench even seem to change form being 0. I figure since I initialize TIM12 the same way as TIM3 it should work. 

Does anyone know where I am doing it wrong?

This is my initializing code:

GPIO_InitTypeDef GPIO_InitStruct;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE );

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; 

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; 

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; 

    GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;

    GPIO_Init(GPIOC, &GPIO_InitStruct);

TIM_TimeBaseInitTypeDef TIM_BaseStruct; //make a struct

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM12, ENABLE); //turn on clock for TIM12

    TIM_BaseStruct.TIM_Prescaler = 0; //No prescaler

    TIM_BaseStruct.TIM_CounterMode = TIM_CounterMode_Up; //count up

    TIM_BaseStruct.TIM_Period = PWM_PERIOD; //(PWM_PERIOD=24000)

    TIM_BaseStruct.TIM_ClockDivision = TIM_CKD_DIV1; 

    TIM_BaseStruct.TIM_RepetitionCounter = 0;

    TIM_TimeBaseInit(TIM12, &TIM_BaseStruct); //init

    TIM_Cmd(TIM12, ENABLE); //enable TIM12

    

    TIM_OCInitTypeDef TIM_OCStruct; //Output compare struct

    TIM_OCStruct.TIM_OCMode = TIM_OCMode_PWM1; //clear on compare match

    TIM_OCStruct.TIM_OutputState = TIM_OutputState_Enable;

    TIM_OCStruct.TIM_OutputNState = TIM_OutputNState_Disable;

    TIM_OCStruct.TIM_Pulse = (uint32_t)(PWM_PERIOD*0.6); //60% duty cycle

    TIM_OCStruct.TIM_OCPolarity = TIM_OCPolarity_Low;

    TIM_OCStruct.TIM_OCNPolarity = TIM_OCNPolarity_High; 

    TIM_OCStruct.TIM_OCIdleState = TIM_OCIdleState_Reset;

    TIM_OCStruct.TIM_OCNIdleState = TIM_OCNIdleState_Reset;

    TIM_OC1Init(TIM12, &TIM_OCStruct); //Initialize TIM12 channel 1

    TIM_OC1PreloadConfig(TIM12, TIM_OCPreload_Enable);

    TIM_ARRPreloadConfig(TIM12, ENABLE);

    

    TIM_OCStruct.TIM_Pulse = (uint32_t)(PWM_PERIOD*0.6);

    TIM_OC2Init(TIM12, &TIM_OCStruct); //Initialize TIM12 channel 2

    TIM_OC2PreloadConfig(TIM12, TIM_OCPreload_Enable); 

    

    

    //Steering

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //turn on clock for TIM3

    TIM_TimeBaseInit(TIM3, &TIM_BaseStruct); //init

    TIM_Cmd(TIM3, ENABLE); //enable TIM3

    

    TIM_OCStruct.TIM_Pulse = (uint32_t)(PWM_PERIOD*0.5); //50% duty cycle

    TIM_OC1Init(TIM3, &TIM_OCStruct); //Initialize TIM3 channel 1

    TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);

    

    TIM_OCStruct.TIM_Pulse = (uint32_t)(PWM_PERIOD*0.5);

    TIM_OC2Init(TIM3, &TIM_OCStruct); //Initialize TIM3 channel 2

    TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); 

    

Best regards,

Emil

#stop-tap-dancing-around
    This topic has been closed for replies.

    12 replies

    Michele Galli
    Visitor II
    February 3, 2018
    Posted on February 03, 2018 at 09:14

    Hi Mayla,

        I think that we have the similar issue with STM32F100. We have develop a board with STM32F100, and this is the signature that ST-LINK utility shows:

        

    Device: STM32F100xx Low/Medium density Value Line

    DeviceID: 0x420

    RevisionID: RevZ

    Flash size: 64KBytes

        

    Now we have some failure from DAC peripheral of that microcontroller during testing. ST-LINK utility shows, for that boards:

        

    Device: STM32F10x Medium density

    DeviceID: 0x410

    RevisionID: RevY

    Flash size: 64KBytes

        

    Is that the STM32F101, please? Has STM32F101 the DAC peripheral?

        

    Thank you,

    Michele

    henry.dick
    Associate II
    February 4, 2018
    Posted on February 04, 2018 at 18:21

    that's an interesting situation.

    My nomination in this category is STM32FEBKC6T6,