cancel
Showing results for 
Search instead for 
Did you mean: 

PWM with TIM8 works only with debugger

orlandospac
Associate II
Posted on January 03, 2014 at 11:50

Hello,

ich trying to create a PWM signal with TIM8 (channel 1). The PWM signal is generated as expected but only if i run the debugger. When i turn of the debugger the PWM signal is still running. Wheni turn off the power and restart the device without the debugger the PWM signal is not running. Does anybody have an idea? As i wrote, the PWM signal is running so i dont think there is a problem with the configuration:

// RCC configuratin for TIM8 and GPIOC 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); 
// Init structure 
GPIO_InitTypeDef GPIO_InitStructure; 
// GPIOC Configuration: TIM8 channel1 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_Init(GPIOC, &GPIO_InitStructure); 
// Init structures 
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 
TIM_OCInitTypeDef TIM_OCInitStructure; 
TIM_TimeBaseStructure.TIM_Period = 5000; 
TIM_TimeBaseStructure.TIM_Prescaler = 0; 
TIM_TimeBaseStructure.TIM_ClockDivision = 0; 
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure); 
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; 
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; 
TIM_OCInitStructure.TIM_Pulse = 2500; 
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; 
TIM_OC1Init(TIM8, &TIM_OCInitStructure); 
TIM_OC1PreloadConfig(TIM8, TIM_OCPreload_Enable); 
TIM_ARRPreloadConfig(TIM8, ENABLE); 
TIM_CtrlPWMOutputs(TIM8, ENABLE); 
TIM_Cmd(TIM8, ENABLE); 
}

The device is a STM32F103RCT7, the programmer is a j-Link (using SWD). Compiler:

IAR ANSI C/C++ Compiler V6.1.5097/W32 for ARM

9 REPLIES 9
chen
Associate II
Posted on January 03, 2014 at 12:27

Hi

Sounds like you are debugging your code in RAM.

In Workbench - look at the project files or project settings, find the linker script.

Check where the code is located in the linker script.

(there may be a little complication in changing the vector table when moving from RAM to Flash - try an example project that is already located in Flash).

orlandospac
Associate II
Posted on January 03, 2014 at 13:11

thanks for reply!!

The code is located in flash because other code parts works fine (even after start without the debugger). Its only the PWM generated by TIM8 that doesn´t work, all other code is executed..

chen
Associate II
Posted on January 03, 2014 at 13:18

Hi

If you are sure it is located in Flash then I do not know.

Double check by making a change (eg not turning LED on or something like that) and then test with and without the debugger.

IAR projects allow different build options eg release or target. The same mechanism can be used for locating in different locations.

orlandospac
Associate II
Posted on January 03, 2014 at 13:32

Double check by making a change (eg not turning LED on or something like that) and then test with and without the debugger. 

As i said, the other parts of the code (blinking a LED) works fine without the debugger. It´s just the PWM with TIM8 that doesn´t work... It is really strange, i havent found something similar on internet...
chen
Associate II
Posted on January 03, 2014 at 13:42

Hi Frank

''Double check by making a change (eg not turning LED on or something like that) and then test with and without the debugger.''

I was suggesting you verify the code is running from flash by making a visible change and then power cycle - this should positively show that the code is programmed and runs in Flash.

I have not tried Timer8, I have Timer1 with PWM working OK.

Can you change to Timer1 instead?

orlandospac
Associate II
Posted on January 03, 2014 at 13:48

Hi Sung,

thanks for your suggestions!

I was suggesting you verify the code is running from flash by making a visible change and then power cycle - this should positively show that the code is programmed and runs in Flash.

i did so, after a power cycle the code runs (other periperals, LEDs) correctly --> so its located in Flash. Its only the PWM with TIM8 that doesn´t work. I can not change to another timer. I also use TIM3 for a other PWM which works always fine.
chen
Associate II
Posted on January 03, 2014 at 13:58

Hi

The only thing I see is that the .GPIO_PuPd is not being set but I am not sure if this is needed for alternate function.

Posted on January 03, 2014 at 14:00

You'd want to initialize

TIM_OCInitStructure

more completely, TIM1/8 are special/advanced timers.

/**
* @brief Fills each TIM_OCInitStruct member with its default value.
* @param TIM_OCInitStruct : pointer to a TIM_OCInitTypeDef structure which will
* be initialized.
* @retval None
*/
void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct)
{
/* Set the default configuration */
TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStruct->TIM_OutputState = TIM_OutputState_Disable;
TIM_OCInitStruct->TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStruct->TIM_Pulse = 0x0000;
TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStruct->TIM_OCNPolarity = TIM_OCPolarity_High;
TIM_OCInitStruct->TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStruct->TIM_OCNIdleState = TIM_OCNIdleState_Reset;
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
orlandospac
Associate II
Posted on January 03, 2014 at 15:17

Thank you very much clive1 and sung,

i did not initalized the (entire)structure so there were undefined data written to the registers.

Now it works, i used the default configuration (

TIM_OCStructInit

() ) and changed only the needed parameters.