cancel
Showing results for 
Search instead for 
Did you mean: 

pwm with a voltage between 1v and 3v3

feres_cherif
Associate II
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 🙂
12 REPLIES 12
frankmeyer9
Associate II
Posted on April 08, 2013 at 08:44

You didn't mention the hardware you use.

Check the schematics, and see if there is anything connected externally to this pin. Like a pullup resistor, for instance.

Andrew Neil
Chief II
Posted on April 08, 2013 at 14:48

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

For 0V, the wouldn't output have to be OFF...?

And, as already noted, check your hardware for sources of offsets...
feres_cherif
Associate II
Posted on April 09, 2013 at 01:13

yes i connected a resistance with a LED to test the PWM signal. i didn't have a scope yet. So i generated 2  complementary PWM. when the led should be off it stay powred but the brightness decreases :\

frankmeyer9
Associate II
Posted on April 09, 2013 at 11:25

Did you check the LED forward voltage and current, i.e. can you really drive it directly ?

I suggest to disconnect your LED + resistor, configure the pin as GPIO and measure the voltage statically while toggling. If the problem persists, you might have something else connected to this pin on the board.

Edit: Again, it could be an advantage if you tell us more about your hardware.

A STM32xx Discovery, Evaluation or Custom board ?

feres_cherif
Associate II
Posted on April 10, 2013 at 02:49

Hi,

related to pin PA8 and PB13, there are a resitor (220ohm) + RED LED and i have a potentiometer (1k) related to PA0  (ADC CH1) +VCC+GND. That's all 

frankmeyer9
Associate II
Posted on April 10, 2013 at 08:27

...related to pin PA8 and PB13, there are a resitor (220ohm) + RED LED...

 

That should result in about 5mA LED current, assuming 2.4V forward voltage, and sounds o.k.

But again, this are the hardware that you connected. Have you checked the the schematics ?

If you configure this pin(s) as GPIO, and measure statically, you should see 0V and Vdd when nothing else is connected.

I had a similiar case not so long ago, were a GPIO did not go below 2.4V.  And when checking the schematics, it turned out that, surprise, a MEMS sensor output was connected to this pin.

feres_cherif
Associate II
Posted on April 10, 2013 at 19:23

the schematic is fine.something is weird:

 when i fixed the duty cycle and don't use ADC, that works very well but when i use adc i have this problem :\

frankmeyer9
Associate II
Posted on April 10, 2013 at 19:57

You don't try to configure the same pin as ADC input and PWM output, do you ?

If so, it is probably easiest to use another ADC channel, as the timer <-> PWM-out assignment is fixed.

feres_cherif
Associate II
Posted on April 10, 2013 at 20:05

 /* GPIOA Configuration: Channel 1, 2 and 3 as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* GPIOB Configuration: Channel 1N, 2N and 3N as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* GPIOB Configuration: BKIN pin */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOB, &GPIO_InitStructure);  

  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure PB.02 (ADC Channel8) as analog input -------------------------*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);  

this is the configuration.