cancel
Showing results for 
Search instead for 
Did you mean: 

HAL Timer PWM Instance and Init parameters error with ADC1

TGate.1
Associate II

Hello,

I am working on STM32F413VGT with STM32CubeIde.

I am using timer 3 channels 1 and 2 to generate 2 PWM signals to control a motor. This part works perfectly.

I am also using ADC1 in DMA mode to get 7 ADC measurements. This function also works perfectly.

I can change the PWM value with UART command or GPIO. But, when ADC measurement and PWM signals are both in my software the PWM signals freeze after some minutes and I can't change it. Instance and Init value of this are changed when I check on STM32CubeIde. (timer3_ok and timer3_ko)

Do you know why I have this problem on timer3 when ADC is used ?

I don't have this problem with an other timer or when the ADC is not present. I have just this error with the timer3.

I tried to generate a PWM signal with TIM1 CH4 and TIM2 CH2 and no problem...

I also tried to use ADC1 without DMA but I also have the same problem.

Parameters with timer3 OK:

0693W000001t6okQAA.png

Parameters with timer3 KO:

0693W000001t6pnQAA.png

Thank you,

Tom

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Okay, but that's not a hardware watchpoint. A hardware watchpoint will break the program when the value gets changed, which lets you see exactly when/where it's occurring.

Google "set watchpoint in eclipse".

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

8 REPLIES 8
TDK
Guru

Looks like a buffer overrun is writing over htim3.

Show the code you use to write ADC values via DMA. My guess is the problem is there.

If you feel a post has answered your question, please click "Accept as Solution".
TGate.1
Associate II

Hi,

I just use the HAL function below :

uint32_t gu32_ADC1Buffer[7];

void ADC_StartADC1(void)

{

  HAL_ADC_Start_DMA(&hadc1, gu32_ADC1Buffer, 7);

}

Tom,

TDK
Guru

Your code seems fine.

Set a hardware watchpoint on htim3.Instance and see when/where it gets changed.

If you feel a post has answered your question, please click "Accept as Solution".
TGate.1
Associate II

I set a hardware watchpoint on htim3.instance in the function I use to command the motor :

void MO_CmdMotor(e_MOTOR_CMD MotorCmd, u8 u8_speed)

{

if(u8_speed > 100) // speed > 100%

{

u8_speed = 100;

}

if(MotorCmd == CMD_Motor_Forward) // UP

{

htim3.Instance->CCR1 = (u32)(u8_speed*htim3.Init.Period)/100; // PWM_UP

htim3.Instance->CCR2 = 0; // PWM_DOWN

}

else if(MotorCmd == CMD_Motor_Reverse) // DOWN

{

htim3.Instance->CCR1 = 0; // PWM_UP = 0

htim3.Instance->CCR2 = (u32)(u8_speed*htim3.Init.Period)/100; // PWM_DOWN

}

}

The time when the value get changed vary between some seconds or some minutes ...

In my last bug only the Instance value changed, the Init value are correct :

0693W000001t7cBQAQ.png

Tom,

TDK
Guru

Okay, but that's not a hardware watchpoint. A hardware watchpoint will break the program when the value gets changed, which lets you see exactly when/where it's occurring.

Google "set watchpoint in eclipse".

If you feel a post has answered your question, please click "Accept as Solution".
TGate.1
Associate II

Hi,

I put an hardware watchpoint on htim3.Instance and I saw the program broke always in the same function. I modify it and now the problem seems solved. I think it was effectively a buffer overrun.

Thank you for your help TDK, I didn't know the hardware watchpoint function. It's useful for debug 😉

Tom,

TGate.1
Associate II

Well,

Indeed I still have the same problem ...

TGate.1
Associate II

Ok, after some tests and corrections it was a buffer overrun problem.

Thank you TDK

Tom,