Go Down

Topic: Arduino nano v3 Solar pwm controller (Read 1 time) previous topic - next topic

bigote

Sorry Leo, like I said I know absolutely nothing about programming.
So I have no idea how to do that.
Do you mind telling me how to do it?
Chears

Wawa

Wow, need to go through some of the examples in the IDE to fix that.

There are two lines in the code you posted that are needed to print what the program is doing.
They are currently commented out (lines not used) with double slashes.
// Serial.begin(9600);
// Serial.println(pulseWidth);

Remove the // from those two lines, and re-upload the sketch.
The serial monitor will now print a stream of pulseWidth values (0-255), that are written to D9.
0 is not charging, 255 is max charging.
Report back.
Leo..

bigote

Ok great, let me try that I'm as good as blind when it comes to programming.

Let you know in a few mins.

bigote

Well did as instructed and ...
Nothing changed, I think this circuit is cursed.

any more ideas?

Wawa

What values did you get on the serial monitor?

bigote

Output on the serial monitor is zero going by very quickly.

ReverseEMF

Has anyone pointed out that the pinMode is never set to OUTPUT on pin 9 [the one being used as PWM out]?

Like this:

Code: [Select]
void setup()
{
  pinMode(9, OUTPUT);   // sets the pin as output
}
"It's a big galaxy, Mr. Scott"

Please DON'T Private Message to me, what should be part of the Public Conversation -- especially if it's to correct a mistake, or contradict a statement!  Let it ALL hang out!!

Wawa

#37
Jul 13, 2018, 04:33 am Last Edit: Jul 13, 2018, 04:43 am by Wawa
Has anyone pointed out that the pinMode is never set to OUTPUT on pin 9 [the one being used as PWM out]?
Yes, post#13-17.
AnalogWrite apparently sets the pin to OUTPUT.
Didn't know that and wasn't sure until I tested the program on a Nano.
Leo..

Wawa

#38
Jul 13, 2018, 04:42 am Last Edit: Jul 15, 2018, 11:23 pm by Wawa
Output on the serial monitor is zero going by very quickly.
That could mean that the voltage on A1 is more than ~2.6volt.
Measure it, and double-check the values of the resistors of the voltage divider on that pin.
Or use this sketch that prints the value of A1 and D9.
Report back.
Leo..
Code: [Select]
const int setPoint = 13.5 * 20 / (20 + 82) * 1024 / 5;
int measurement = 0;
int pulseWidth = 0;
int difference = 0;
int stepSize = 0;
int calculation = 0;
int led = 13;

void setup() {
  TCCR2A = TCCR2A | 0x30;
  TCCR2B = TCCR2B & 0xF8 | 0x01;
  analogWrite(11, 117);
  analogWrite(3, 137);
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {
  measurement = analogRead(A1);
  Serial.print(measurement);
  Serial.print("\t");
  calculation = setPoint - measurement;
  difference = abs(calculation);
  stepSize = difference;

  if (measurement < setPoint)
  {
    pulseWidth += stepSize;
    if (pulseWidth > 255) pulseWidth = 255;
    digitalWrite(led, LOW); // LED off
  }
  if (measurement > setPoint)
  {
    pulseWidth -= stepSize;
    if (pulseWidth < 0) pulseWidth = 0;
    digitalWrite(led, HIGH); // LED on
  }
  Serial.println(pulseWidth);
  analogWrite(9, pulseWidth);
  delay(10);
}

bigote

Very good Leo.
I'll try your sketch when I get back from work.
Battery volts now is:12.7 and @ A1 stands at 2.681
Maybe I've got defective resistors, those are quite hard to get here where I live, I will try to get new ones today.
Thanks
Luis

ReverseEMF

#40
Jul 13, 2018, 05:59 pm Last Edit: Jul 13, 2018, 06:37 pm by ReverseEMF
Battery volts now is:12.7 and @ A1 stands at 2.681
Maybe I've got defective resistors, those are quite hard to get here where I live, I will try to get new ones today.
Depends on the tolerance of those resistors.
At 1%:

R#NomLowHigh
R682k081k282k8
R720k019k820k2


The formula for calculating the  A1 voltage [the voltage across the 20k resistor], if we call the 82k resistor R6, and the 20k resistor R7, and the Battery Voltage VB:

VA1 = VBR7/(R6 + R7)

And to get the Highest voltage possible, due to tolerance variation, we take the lowest possible resistance for R6 and the highest resistance for R7, like this:

VA1(max) = 12.7(20.2)/(81.2 + 20.2) = 2.53V

Which is lower than your measured value of 2.681V

BUT

Let's say your resistors are 5%.  Then it would go like this:

R#NomLowHigh
R682k077k986k1
R720k019k021k0


VA1(max) = 12.7(21.0)/(77.9 + 21.0) = 2.70V

Which is greater than 2.681V, so definitely in the valid range.


Which means, not defective.  But, merely a case of insufficient precision.
"It's a big galaxy, Mr. Scott"

Please DON'T Private Message to me, what should be part of the Public Conversation -- especially if it's to correct a mistake, or contradict a statement!  Let it ALL hang out!!

bigote

#41
Jul 13, 2018, 08:51 pm Last Edit: Jul 13, 2018, 11:09 pm by bigote
Ok I run the code and I get 547 on the serial monitor.
I see no reference to output D9
I even desolder the  resistors and measure:
82k shows 81.8 and 22k measures 21.94 both 1% blue type
pretty good I'll say since I got them from the junk bin.
regards

Wawa

22k?

The code and the diagrams show a 20k resistor.

If you use 22k, then the charger assumes a 12.7volt battery is full.

Leave the 22k resistor in, and change the first line in the code to:

const int setPoint = 13.5 * 22 / (22 + 82) * 1024 / 5;

Leo..

bigote

You know, I think you just found the problem.
I don't know how I could have made such mistake, but you know how it is sometimes it takes someone looking at the problem from the outside.

Le me try that again, be back shortly

bigote

Ok Leo, thanks to you I think I made some progress.
I replaced the 22k for a 20k and now @ A1 I get 2.485 volts
and the output @ D9 is 5 volts.
Reading on the serial console shows

507               255

So I guess its working right?

Only problem I see now is battery voltage does not seem to be going up, I have a regular walwart 16 vdc simulating solar panel for now.

Go Up