MPPT delaying issues

I am trying to make a MPPT. I am taking in two voltage measurements. One of the voltage measurements comes from a voltage divider. The other voltage measurement is a voltage output from a current sensor. I am multiplying these voltages to get a power measurement. The first power measurement is coming out fine, but when I try to delay the second power measurement and compare them it comes out the same as the first power measurement. This should not be because happening because I am changing the voltage that it is sensing with my power supply. I want to measure two power measurements and compare them to get my dp/dv and then use my change in power to adjust my duty cycle. I also am not sure that I am adjusting my duty cycle right because my change in power is always zero. I am hoping by the end of tonight to be able to check my duty cycle on this ocilloscope.

MPPT.txt (2.77 KB)

Your code would probably be much easier to read, understand, and debug if you used sensible variable names.
"value1" and "value2" aren't sensible.
"leftSensor" and "rightSensor" are a bit more sensible.

long previousMillis = 0;      //initialize the milliseconds difference

Eventually that is going to byte you. [pun intended, even though I didn't sign it.] [[that pun was intended too...]]

The way I read your code is:

  1. Read the sensors
  2. Calculate Power1
  3. Wait a really long time (6seconds)
  4. Print the stored results
    [loop repeats here]
  5. Read the sensors
  6. Calculate Power1
  7. Calculate Power2 using the same variables as #6 [5 seconds passed since last time I did this]
  8. Wait a really long time (6 seconds)
  9. Print the results
  10. Goto 5

See the problem? You're always calculating Power1 and Power2 right after each other the 6second delay. Also, you calculate them using the same non-sensical variables.

None of code actually makes use of:
sensorValue2
voltage2
pwm2