# Simple arduino program question

#### 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
"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?

Joined Jan 15, 2015
7,193

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,070
You have 3 resistors whats the top voltage and the bottom voltage.

Last edited:

#### shteii01

Joined Feb 19, 2010
4,644

#### be80be

Joined Jul 5, 2008
2,070
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:

Joined Jan 15, 2015
7,193
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