Go Down

### Topic: The Timer or something in FADE doesn't work (Read 954 times)previous topic - next topic

#### quentinliu

##### Jul 14, 2011, 04:42 pm
As the topic.

I used the code below. All I need is a signal that goes from 0 to 5v steadily( the first half of a triangle signal)

But the signal only growth from 40mV to 116mV then straightly jumped to 1.04V

and then from 1.14v straight to 3.2v then it increases towards 5v.

i don't understand how could things go wrong with just a single function.

Code: [Select]
`int brightness = 0;    // how bright the LED isint fadeAmount = 1;    // how many points to fade the LED byvoid setup()  {  // declare pin 9 to be an output:  pinMode(9, OUTPUT); }void loop()  {  // set the brightness of pin 9:  analogWrite(9, brightness);      // change the brightness for next time through the loop:  brightness = brightness + fadeAmount;  // reverse the direction of the fading at the ends of the fade:  if (brightness == 0 || brightness == 255) {    brightness = 0;  }      // wait for 30 milliseconds to see the dimming effect      delay(100);                            }`

#### retrolefty

#1
##### Jul 14, 2011, 07:05 pm
Your confusion is with the arduino analogWrite function. It's doesn't output a pure DC voltage but rather a digital PWM signal that is always either +5vdc or ground at any given instant in time. It's the duty cycle (ratio of on to off) that can be manipulated with the analogWrite function in 8 bits of resolution. If you require a true analog 0-5vdc output then you must add an external low pass filter to convert the PWM signal to a true analog output voltage. You also may need to add a op-amp buffer stage if you need to provide any significant current to the device using the signal.

Lefty

#### quentinliu

#2
##### Jul 15, 2011, 12:26 pm
Thanks a lot for the quick reply.
i'll go check it out.

Quentin

Go Up

Please enter a valid email to subscribe