The question is how to control the '595 (SER, RCLK, SRCLK) to display without updating for say, 200mS.
#include <LiquidCrystal595.h>
const int ledPin = 13 ;
int ledState = LOW ;
long previousMillis = 0 ;
long timA = 500 ;
long timB = 400 ;
int RCLCK = 6 ;
int CLCK = 12;
int CLCKState = LOW ;
int valX = 0 ;
int valY = 0 ;
// number of analog samples per channel
#define SAMPLES 30
// ADC reference voltage / calibration value
#define V_REF 4.991
LiquidCrystal595 lcd (7, 6, 9); // change back to 7, 8, 9 later
int sum[4] = {0}; // sums of samples taken
unsigned char sample_count = 0; // current sample number
float voltage[4] = {0.0}; // calculated voltages
char l_cnt = 0; // used in 'for' loops
void setup()
{
pinMode (ledPin, OUTPUT) ;
pinMode (CLCK, OUTPUT) ;
pinMode (RCLCK, OUTPUT) ;
lcd.begin (20, 4);
TCCR2A = TCCR2A | 0x30;
TCCR2B = TCCR2B & 0xF8 | 0x01;
analogWrite(11, 110);
analogWrite(3, 130);
}
const int setPoint = 660.0;
int measurement = 0;
int pulseWidth = 0;
int difference = 0;
int stepSize = 0;
void loop()
{ // mark-space multivib
unsigned long currentMillis = millis () ;
if (currentMillis - previousMillis > timA)
{
previousMillis = currentMillis ;
if (ledState == LOW )
{ ledState = HIGH ;
}
digitalWrite (ledPin, ledState) ;
}
if ((ledState == HIGH) && (currentMillis - previousMillis > timB ))
digitalWrite (ledPin, LOW) ;
valX = digitalRead (ledPin) ;
valY = digitalRead (RCLCK) ;
if (valX == HIGH)
digitalWrite (CLCK, HIGH) ;
else
digitalWrite (CLCK, LOW) ;
measurement = analogRead (A7);
difference = abs (setPoint - measurement);
stepSize = difference ;
if (measurement < setPoint)
{
pulseWidth += stepSize / 2;
if (pulseWidth > 255) pulseWidth = 255;
}
if (measurement > setPoint)
{
pulseWidth -= stepSize ;
if (pulseWidth < 0) pulseWidth = 0;
}
analogWrite (10, pulseWidth);
delay (10);
// take a number of analog samples and total
while (sample_count < SAMPLES) {
// sample each channel A0 ... A3
for (l_cnt = 0; l_cnt < 4; l_cnt++) {
sum [l_cnt] += analogRead (A0 + l_cnt);
}
sample_count++;
delay(2);
}
// calculate voltage for each channel
for (l_cnt = 0; l_cnt < 4; l_cnt++) {
voltage[l_cnt] = ((float)sum[l_cnt] / (float) SAMPLES * V_REF) / 1024.0;
}
lcd.setCursor(0, 0);
lcd.print("+ ");
lcd.print(voltage[0] * 2.000, 2);
lcd.print ("A");
lcd.setCursor(0, 1);
lcd.print("- ");
lcd.print(voltage[1] * 2.000, 2);
lcd.print ("A");
// voltge 3 - C (pin A2)
lcd.setCursor(8, 0);
lcd.print(" ");
lcd.print(voltage[2] * 5.830, 2);
lcd.print("v");
// voltage 4 - D (pin A3)
lcd.setCursor(8, 1);
lcd.print(" ");
lcd.print(voltage[3] * 4.295, 2);
lcd.print("v");
// reset count and sums
sample_count = 0;
for (l_cnt = 0; l_cnt < 4; l_cnt++) {
sum[l_cnt] = 0;
}
}
I have tried another solution which reduces the display to about twice per second.
Looking at 74x595 specsheet (Table 1. Function Table) ......
Testing to find/solve problem.
Looking at line 69 : if ( valX == HIGH)...
I can get output (pin 12 for testing) as expected to be copy of ledPin = 13.
But then I select valY which is the output to RCLCK (pin 6) in order to gate it with software, I get a continuous HIGH output (pin 12), and no data from Arduino to the '595 while I KNOW that the data is there and correct, i.e. the data is coming out of pin 6 because I can control it with hardware.
What am I doing wrong?
No questions or suggestions for 2 weeks!
Or are we stumped again?
I am looking for suggestions to solve a problem.
Thank you.
Really now?I KNOW that the data is there and correct, i.e. the data is coming out of pin 6 because I can control it with hardware.
Hi easyrider. I found the code. I have never used this filter, but I know that it is proven in many aspects of automation. However it uses float numbers which means code size and execution time penalty. Have you ever used a simple averaging method with latest values stored in a table? If so, then what is the advantage of using this technique, instead of simple averaging?Easyrider83 said:I'm using Kalman's filter. I gave the code on this forum. Try to search yourself.
A Kalman filter has advantages in filtering varying measurement data, often multi-dimensional, e.g. GPS readings of an object in movement. I don't see it's meaningful for battery charger voltage and currents.what is the advantage of using this technique, instead of simple averaging?
Really. A hysteresis that freezes the display makes me wonder if the measurement is still live.It's just an visual improvement.
Yes, there are few simple alghorithms that can be tried also. You collecting some data to array, calculating average, then excluding all elements (just replacing by average) that is far from average more than some value, than calculating average again. This will reduce some noise spikes.Hi easyrider. I found the code. I have never used this filter, but I know that it is proven in many aspects of automation. However it uses float numbers which means code size and execution time penalty. Have you ever used a simple averaging method with latest values stored in a table? If so, then what is the advantage of using this technique, instead of simple averaging?
I have tried another solution which reduces the display to about twice per second.
Looking at 74x595 specsheet (Table 1. Function Table) when RCLCK goes high (and SER, SRCLCK, SRCLR and OE are all X [don't care] ), the function is quoted as "Shift register data is stored in the storage register". I then created an oscillator with adjustable mark-space to "gate" the RCLCK feeding the '595.
Now using diodes and resistors I got this working perfectly with display changing about twice per second.
The problem now is to replace the gate hardware with software.
This seems to work okay but I can't do this with software, i.e. without the resistor and diode.
I have tried several options with hardware using R-C filtering and software (average, smoothing, etc.) without success.
Hi,
I´ve a high quality brand digital true RMS multimeter.
It has 0.1mV resolution, but for all input from 0.0mV ... 1.9mV it just shows "0.0 mV",
then it immediately starts with "2.0mV"
I really don´t like this "feature".
It maybe makes the reading more "nice", but at the same time more "wrong".
Pin 13 output is a sq.wave (400mS HIGH /100mS LOW). The data from Arduino (pin 6) is sent to the '595 normally while pin 13 is LOW but when pin 6 is HIGH data is blocked and input of the '595 (pin 12) remains HIGH so the display freezes
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?