2016-08-22 09:08 AM
Hello
I have the necessity to generate a PWM out of a pin that stays active for 50us and then goes 0 regularly. In the attachment you see what I want to achieve. As you can see between some PWM the pin voltage level doesn't reach zero properly. Do anyone of you had similar experience? Any Idea how I can fix it? Here the function that controls the pin:void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance==TIM3){
if(PWM_Status == 1){
PWM_Status = 0;
//Stop PWM
HAL_TIM_PWM_Stop(&htim15, TIM_CHANNEL_2);
// Deinit PWMs
HAL_TIM_PWM_DeInit(&htim15);
// GPIO init
my_GPIO_Init();
// Reset pin
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET);
}
else if(PWM_Status == 0){
PWM_Status = 1;
//Deinit GPIO
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_15);
//Init PWM
MX_TIM15_Init();
//Start PWM
HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2);
}
}
}
/* USER CODE END 0 */
I appreciate any suggestion! Thank you in advance.
- Julian
#pwm
2016-08-22 10:47 AM
Something is not working with your GPIO reinitialization. Not sure why, can't see the code, and have no interest in HAL issues.
I wouldn't modulate it by changing the GPIO settings, programming the PWM Pulse to ZERO would have the same effect as turning the channel off.2016-08-22 02:34 PM
If you are seeing that pin PB15 is not going down to zero volts, you should look for something outside of the processor that is pedestaling the pin (holding it above ground).
You don't say which processor you are using, but on mine PB15 is not a DAC channel, so there is no way that you can get anything other than 0V or 3.3V. Look for solder flux or other residue on the board, or some sort of leakage current from the circuit that you are sending the PWM to.Also, your PWM implementation is weird, it is probably a leftover from your debugging process though. Andrei (from The Great White North)2016-08-22 04:33 PM
The behaviour of external circuitry is certainly something to consider, I'd discounted it somewhat due to the success of the PWM getting it to go rail-to-rail previously. Even in OD mode it should get as close to zero as the drivers and apposing current will allow.
If simply gating the pulse width to zero doesn't achieve the desired behaviour look harder at what is attached/connected externally, and evaluate what happens on an STM32 not connected to any loading.2016-08-23 04:30 AM
Hi jung.julian,
I think that is caused by a wrong manipulation of the PWM signal in your code. Try to manipulate the signal and not the IO pin. I invite you to a new application note ''General-purpose timer cookbook'' about timers that contains some application examples and one of them is similar to your use-case intitled ''N-pulse waveform generation application'' . You find the associated firmware in the package . -Hannibal-