#include <LiquidCrystalFast.h>
const int pulse = 14;
const int tick = 16;
// initialize the library with the numbers of the interface pins
LiquidCrystalFast lcd(12, 10, 11, 5, 4, 3, 2);
// LCD pins: RS RW EN D4 D5 D6 D7
elapsedMillis startloop;
byte teststate = 0;
void setup() {
pinMode(pulse, OUTPUT);
pinMode(tick, OUTPUT);
// set up the LCD's number of rows and columns:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("hello, world!");
delay(10000);
startloop = 0;
}
void loop() {
// as long as pulse is pulsing the loop is not being blocked
digitalWriteFast(pulse, HIGH);
digitalWriteFast(pulse, LOW);
if (startloop >= 100 && teststate == 0){ //test Clear
digitalWriteFast(tick, HIGH);
lcd.clear();
teststate = 1;
}
if (startloop >= 200 && teststate == 1){ //Set cursor
digitalWriteFast(tick, LOW);
lcd.setCursor(0,0);
teststate = 2;
}
if (startloop >= 300 && teststate == 2){ //Write A
digitalWriteFast(tick, HIGH);
lcd.print("A");
teststate = 3;
}
if (startloop >= 400 && teststate == 3){ //Clear A
digitalWriteFast(tick, LOW);
lcd.clear();
teststate = 4;
}
if (startloop >= 500 && teststate == 4){ //Reset Cursor
digitalWriteFast(tick, HIGH);
lcd.setCursor(0,0);
teststate = 5;
}
if (startloop >= 600 && teststate == 5){ //Write 1
digitalWriteFast(tick, LOW);
lcd.print("1");
teststate = 6;
}
if (startloop >= 700 && teststate == 6){ //Reset Cursor
digitalWriteFast(tick, HIGH);
lcd.setCursor(0,0);
teststate = 7;
}
if (startloop >= 800 && teststate == 7){ //Write 20 Chars
digitalWriteFast(tick, LOW);
lcd.print("Fortheloveofspeeding");
teststate = 8;
}
if (startloop >= 900 && teststate == 8){ //Clear and set cursor
digitalWriteFast(tick, HIGH);
lcd.clear();
lcd.setCursor(0,0);
teststate = 9;
}
if (startloop >= 1000 && teststate == 9){ //Fill the entire screen
digitalWriteFast(tick, LOW);
lcd.print("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*0123456789");
teststate = 10;
}
if (startloop >= 5000 && teststate == 10){ //Long Pause
teststate = 0;
startloop = 0;
}
}
For higher resolution, you can go to 13bit from the 12bit I have listed. Each of my channels can read up to roughly 4.332A(1.0579mA/bit), if you reduce it to just above 2A you can increase the resolution again.
Just the 2 above changes would give you a factor of 4 increase in resolution over what I have proposed. You would have about +/-250uA per bit at 13 bit resolution.
You may be able to squeeze one more bit out of it if you sample the crap out of the ADC and then average it.
If you want more resolution then that you either need to invest in external ADC with good reference or you could split the load up with more Fets.
So I decided to remove the DC-DC iso supply I was using for +12/-12V for the Opamps.
Couple of reasons.
1. Cost, the Dc-Dc Iso supply was $6 vs about $3 for the Linear supply(LM317) and charge pump(LM2776), including caps and resistors.
2. Increased output capability. Both the LM317 and LM2776 can output more current then the DC-DC Iso supply's could ever produce.
3. We don't actually need +12v or -12V, we can get away with a much lower negative voltage since its there to ensure the OpAmp's can get to at least 0V on the gates. We also don't need +12V since the majority of Fet's we would use turn on much sooner and we are trying to drive them linearly so we should in theory never need more then 6-7V.
View attachment 8712
The thing is that the LM2776 produces a crazy amount of output ripple (>100mV for small currents). For this reason, I am not a big fan of it in combination with a linear voltage regulator (like the LM317), which has very low ripple.
I would rather use an LTC1550 which, although not being able to source as much current as the LM2776 and costs $2 instead of $1, can still go up to 50 mA (at a 6.5V VCC) and has ripple characteristics <=1mV. Since a lot of current is not needed for op-amp use, this may be a better solution if ripple characteristics are important (i.e., depending on the PSRR of the op-amps employed).