Simple arduino program question

Discussion in 'Programmer's Corner' started by coinmaster, Dec 6, 2017.

  1. coinmaster

    Thread Starter Member

    Dec 24, 2015
    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? :)
  2. Reloadron

    Well-Known Member

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

    Last edited: Dec 7, 2017
  3. be80be

    Distinguished Member

    Jul 5, 2008
    You have 3 resistors whats the top voltage and the bottom voltage.

    Screenshot from 2017-12-08 02-10-44.png
    Last edited: Dec 8, 2017
    absf likes this.
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    They said:
    - two resistors
    - in series