AnsweredAssumed Answered

STM32F4 Voltage issue

Question asked by Balg0r on Dec 2, 2015
Latest reply on Dec 9, 2015 by Balg0r
Hello everybody,

First sorry for my english (I'm French). I am a student and i work with my partner on a project of three-motorized drone. For the control of the motors, we use a stm32f429ZI discovery card and we have a problem with the output voltage of the pin pa1 et pa2.
We have to generate PWM signal on the pins pa0 pa1 and pa2, but the issue is that pa1 and pa2 output signal is 650mV amplitude instead of 3V. We also use other pins for I2C and the LCD displaying. Is this a problem of lack of power ?

I join the code of the pwm generation with this post:

#include "stm32f4xx_hal.h"
#include "pwm.h"
#include "defines.h"
 
static GPIO_InitTypeDef PWM_GPIO_Init; // DOIT ETRE EN VARIABLE GLOBALE ??????
static TIM_HandleTypeDef TIM5_Handle;
static TIM_OC_InitTypeDef PWM_Config;
 
void PWM_Init(void){
     
    // initialisation
    PWM_GPIO_Init.Pin           = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2; // from timer5 channel 1/2/3
    PWM_GPIO_Init.Mode          = GPIO_MODE_AF_PP;
    PWM_GPIO_Init.Speed         = GPIO_SPEED_FREQ_LOW;
    PWM_GPIO_Init.Pull          = GPIO_NOPULL;
    PWM_GPIO_Init.Alternate = GPIO_AF2_TIM5;
     
    TIM5_Handle.Instance                    = TIM5 ;
    TIM5_Handle.Init.Prescaler      = (SystemCoreClock * PWM_MS_PERIOD) / 2000000 - 1; // 2000 crans par période
    TIM5_Handle.Init.CounterMode    = TIM_COUNTERMODE_UP;
    TIM5_Handle.Init.Period             = 2000 - 1;
     
    PWM_Config.OCMode       = TIM_OCMODE_PWM1;
    PWM_Config.Pulse        = 100 + PWM_PULSE_INIT - 1;
    PWM_Config.OCPolarity   = TIM_OCPOLARITY_HIGH;
    PWM_Config.OCNPolarity  = TIM_OCNPOLARITY_HIGH;
    PWM_Config.OCFastMode   = TIM_OCFAST_DISABLE;
    PWM_Config.OCIdleState  = TIM_OCIDLESTATE_RESET;
    PWM_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
     
     
    // code
    __HAL_RCC_GPIOA_CLK_ENABLE(); // active GPIOA si ce n'est pas déjà fait
    HAL_GPIO_Init(GPIOA, &PWM_GPIO_Init);
 
    __TIM5_CLK_ENABLE();
    HAL_TIM_PWM_Init(&TIM5_Handle);
    HAL_TIM_PWM_ConfigChannel(&TIM5_Handle, &PWM_Config, TIM_CHANNEL_1);
    HAL_TIM_PWM_ConfigChannel(&TIM5_Handle, &PWM_Config, TIM_CHANNEL_2);
    HAL_TIM_PWM_ConfigChannel(&TIM5_Handle, &PWM_Config, TIM_CHANNEL_3);
     
}
 
 
void PWM_Start(){
    HAL_TIM_PWM_Start(&TIM5_Handle, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&TIM5_Handle, TIM_CHANNEL_2);
    HAL_TIM_PWM_Start(&TIM5_Handle, TIM_CHANNEL_3);
}
 
void PWM_Pulse(PWM pwmx, uint8_t value){
    if(value > 100) return;
    value+=99; // on reformate la valeur pour être entre 5 et 10% de la période
    switch(value){
        case PWMS : TIM5->CCR1 = TIM5->CCR2 = TIM5->CCR3 = value; break;
        case PWM1 : TIM5->CCR1 = value; break;
        case PWM2 : TIM5->CCR2 = value; break;
        case PWM3 : TIM5->CCR3 = value; break;
    }
    // if (CNT > value) && (CNT < CCR3) ... on met à zéro directement ? non
}

Thank you for your answers !

Outcomes