cancel
Showing results for 
Search instead for 
Did you mean: 

Generate a clear on/off PWM problem

gnu
Associate II
Posted on August 22, 2016 at 18:08

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
4 REPLIES 4
Posted on August 22, 2016 at 19:47

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 22, 2016 at 23:34

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)
Posted on August 23, 2016 at 01:33

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Walid FTITI_O
Senior II
Posted on August 23, 2016 at 13:30

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

http://www.st.com/content/ccc/resource/technical/document/application_note/group0/91/01/84/3f/7c/67/41/3f/DM00236305/files/DM00236305.pdf/jcr:content/translations/en.DM00236305.pdf

''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

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-expansion-software/x-cube-timcooker.html

.

-Hannibal-