Skip to main content
feres_cherif
Associate II
April 8, 2013
Question

pwm with a voltage between 1v and 3v3

  • April 8, 2013
  • 12 replies
  • 2030 views
Posted on April 08, 2013 at 06:28

Hi all,

i have a problem, i have 6 complementary pwm (TIM1) and i used ADC to change the duty cycle. this my main function:

int main(void)

{

 

       

  /* System Clocks Configuration */

  RCC_Configuration();

  /* GPIO Configuration */

  GPIO_Configuration();

 ADC_Config();

 

  while (1)

  {

  pulse =(ADC_GetConversionValue(ADC1)*731)/4096;

/*   TIM_OCInitStructure.TIM_Pulse = pulse;

   TIM_OC1Init(TIM1, &TIM_OCInitStructure);

   TIM_OCInitStructure.TIM_Pulse = pulse;

  

   TIM_OC2Init(TIM1, &TIM_OCInitStructure);

    TIM_OCInitStructure.TIM_Pulse = pulse;

TIM_OC3Init(TIM1, &TIM_OCInitStructure);*/

  }

}

the PWM's voltage is between 1v and 3v3 and it must be between 0v and 3v3.

Please help me :)
    This topic has been closed for replies.

    12 replies

    feres_cherif
    Associate II
    April 11, 2013
    Posted on April 11, 2013 at 17:41

    i am using stm vld stm32f100rb

    for the adc's configuration:

    void ADC_Config(void)

    {

    ADC_InitTypeDef ADC_InitStructure;

    ADC_DeInit(ADC1);

       

    /*Initialiser ADC1*/

      ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

      ADC_InitStructure.ADC_ScanConvMode = DISABLE;

      ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

      ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

      ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

      ADC_InitStructure.ADC_NbrOfChannel = 1;

    ADC_Init(ADC1,&ADC_InitStructure);

    /*Choisir la channel de l'ADC*/

    ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_1Cycles5);

    /*Activer ADC1 */

      ADC_Cmd(ADC1, ENABLE);

      /*Lancement de conversion par programme*/ 

      ADC_SoftwareStartConvCmd(ADC1,ENABLE);

    }

    frankmeyer9
    Associate III
    April 11, 2013
    Posted on April 11, 2013 at 19:00

    i am using stm vld stm32f100rb

    So there is no

    GPIO_PinAFConfig
    ()

    , which is o.k. for the F1 But I'm missing the ADC calibration:

    ...
    /* Enable ADC1 */
    ADC_Cmd(ADC1, ENABLE);
    /* Enable ADC1 reset calibration register */ 
    ADC_ResetCalibration(ADC1);
    /* Check the end of ADC1 reset calibration register */
    while(ADC_GetResetCalibrationStatus(ADC1));
    /* Start ADC1 calibration */
    ADC_StartCalibration(ADC1);
    /* Check the end of ADC1 calibration */
    while(ADC_GetCalibrationStatus(ADC1));
    ...

    However, calibration is recommended, but not necessary according to the ref. manual. There is the User/Wakeup button connected to PA0, but I can't see how it should bias PA0. But I would check that statically, before any initialisation takes effect. The rest seems o.k. so far.