Simple arduino program question

Thread Starter

coinmaster

Joined Dec 24, 2015
502
Hey there.
It's been a while since I learned to code the arduino and I can't remember how to write the code for something I'm working on, nor do I have the hours to brush up on it at the moment.
I was hoping someone could help me out.
Basically I want 3 of the ADCs to read the voltages across two resistors in series, one for the bottom, one for the middle, one for the top, and adjust one of the PWM outputs (feeding into a filter) until both voltage readings at the ADC are equal to the number I set.
So basically something like
"read port 1"
"read port 2"
"read port 3"
"if the difference between port 1/2 and 2/3 is not 1v set pwm duty cycle to sweep from 0 to 100 until port 1 & 2 = 1v"
Something to that affect.
Anyone willing to throw me a freebie? :)
 

Reloadron

Joined Jan 15, 2015
5,667
Your analog inputs are 10 bit so you get 1024 quantization levels for the analog input ranges. The normal input voltage range is 0 to 5 volts so 0 to 5 volts equals 0 to 1023. This assumes no external A/D reference is used. The PWM output is 0 to 255 for your 0 to 100%. I would start by giving this a read where an analog input is used to feed a LED using PWM. What you have is an Analog In controlling a PWM Out. In your case you want to do some math with your three inputs to derive a number and use that number to control your PWM Out. That is my guess as to how to gop about what you seem to want to do.

This link covers the If and Else statements which you may want for your input channels math.

Ron
 
Last edited:

be80be

Joined Jul 5, 2008
2,049
I read that but the top is alway 1024 the bottom 0 the middle 512 higher if top resistor is lower then bottom.
Only the middle will change
like reading a battery with adc till the chip shuts off it's still going to say it's fully charged
To do what they want takes more then 2 resistors

To read the top means you need a fixed adc voltage lower then it will ever be and a divider to scale it up to the tops voltage.
The middle same thing. The hard part is the bottom if it's 0 volts you'll get 0 if it's not much higher adc not going to read it.

So plz inligting me here
where are these 2 resistors are they between just say ground and Vdd or
is there more here because two hanging off the end of something which I can't see is got be more like 4 if two places is not ground and Vdd
I figured I post 3 cause he said 3 adc reading and I wanted to know where he is getting them.

Then there's one more problem here pwm doesn't look like 1 volt to a adc pin it's more like 0 and 1024
Need to see what the TS has going on here.
 
Last edited:

Reloadron

Joined Jan 15, 2015
5,667
Unless the thread starter returns and provides more information as to exactly what he has and what he wants to get done about all we can do is speculate. Since there is a reference to Arduino in the thread title and a mention of reading ports I would just assume reading analog inputs.

I read that but the top is alway 1024 the bottom 0 the middle 512 higher if top resistor is lower then bottom.
Only the middle will change
Actually wouldn't the top bit count be 1023 since we have a 10 bit (2^10) A to D converter yielding 1024 quantization levels starting with 0 so the highest number we would read is 1023 since the 0 counts? Anyway other than a reference to:
Basically I want 3 of the ADCs to read the voltages across two resistors in series, one for the bottom, one for the middle, one for the top, and adjust one of the PWM outputs (feeding into a filter) until both voltage readings at the ADC are equal to the number I set.
We really don't know what the original poster has in mind or is really trying to achieve.

Ron
 
Top