Go Down

Topic: stabalize output to 0 - 5 volts (Read 112 times) previous topic - next topic

Montuck

I have a sensor and its working good as in linear.  I am using the map function to map the min and max values captured form the analog pin.   I constructed a 2nd order low pass filter thinking that would help. 
- The major problem I have is that the max voltage output read with the DMM is 4.35 V.  That value is not close to what I am looking for.   

Any advice to get this value 5 volts. 
Do I take the constrain off??



here is part of the code:



   // record the maximum and minimum sensor value
   if (val > sensorMax) {
     sensorMax = val;
   }

   // record the minimum sensor value
   if (val < sensorMin) {
     sensorMin = val;
   } 

int outputValue = map(val, sensorMin, sensorMax, 0, 255);
outputValue = constrain(outputValue, 0, 255);    // limits range of sensor values to between 0 to 255
analogWrite(analogOutPin,outputValue);
   
}




 

Wawa

The major problem I have is that the max voltage output read with the DMM is 4.35 V.  That value is not close to what I am looking for.   
Any advice to get this value 5 volts.
 
Do I take the constrain off??
1) That does not make sense.
A sensor that outputs 4.35volt max results in a digital value of 890 (if Aref is exactly 5volt).
The code maps 890 to 255.

2) I don't see why this is usefull.
Map already constrains it to 255, and 0 isn't reached if sensorMin is more than 0.

Map scales to integers. Resolution is lost.
Don't know if you want that.
Leo..

blimpyway

If he uses the value only for analogWrite() there is no use or possibility for increased resolution.
-----------
Also I think - although it isnt quite clear - the issue is that analogWrite(255) outputs 4.35V instead of exactly 5.00 
-----------
I see no use for constrain(), the map() and previous adjustment of min and max won't let outputValue out of 0-255 range.

-----------

See also this thread

I get from AWOL's answer:
Quote
Outputs are a maximum LOW of 0.9V, and a minimum HIGH of 4.2volts at 20mA
That output  isn't nailed to 5V but it is a logic level high, that means higher than a threshold.

Wawa

Ahhh, I though that 4.35volt max came from the sensor.

If that 4.35volt is measured on an output pin with a PWM value of 255, then two things could cause it.
1) The pin is loaded.
Only an unloaded pin produces the same voltage as the MCU supply.
An opamp voltage follower could fix that.

2) Arduino's supply voltage is not 5volt.
Was the Arduino supplied from USB or batteries?
Leo..


Montuck

I did try the follower  didn't really change anything.  I supplied the 5 from the USB.   I used the constrain because there was a random 257 value that occurred. Which caused the output value to go to zero really fast. .   I will keep trying.   Thanks for the help. 

Wawa

I did try the follower  didn't really change anything.

I supplied the 5 from the USB.

I used the constrain because there was a random 257 value that occurred. Which caused the output value to go to zero really fast. .   I will keep trying.   Thanks for the help. 
1) Post the diagram, so we can see what you did wrong.

2) Did you measure the 5volt pin when the Arduino was supplied from USB.

3) Post the full code. It seems you are doing things in the wrong order.
Don't forget to use code tags.
Leo..

MarkT

If the supply to the Arduino genuinely is 5.0V, and the argument to analogWrite is 255, and the output
pin isn't overloaded, and the Arduino hasn't been damaged, then I would definitely expect to see nearly
5.0V on that output (which a multimeter which averages PWM properly)

So one or more of those conditions are not being met, check each condition one by one - its called
fault-finding.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy