2020-07-17 04:56 AM
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:
Parameters with timer3 KO:
Thank you,
Tom
Solved! Go to Solution.
2020-07-17 07:28 AM
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".
2020-07-17 05:40 AM
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.
2020-07-17 05:52 AM
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,
2020-07-17 06:49 AM
Your code seems fine.
Set a hardware watchpoint on htim3.Instance and see when/where it gets changed.
2020-07-17 07:15 AM
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 :
Tom,
2020-07-17 07:28 AM
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".
2020-07-20 08:08 AM
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,
2020-07-20 08:45 AM
Well,
Indeed I still have the same problem ...
2020-07-24 07:22 AM
Ok, after some tests and corrections it was a buffer overrun problem.
Thank you TDK
Tom,