Add accurateRead functions and Readme

This commit is contained in:
Matt McWilliams 2023-09-06 15:41:36 -04:00
parent 082dbc0826
commit 0b880a5e79
9 changed files with 50 additions and 8 deletions

View File

@ -1,5 +1,5 @@
{
"version": "1.8.24",
"version": "1.8.25",
"ext_port": 1111,
"profiles": {
"mcopy": {

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "mcopy-app",
"version": "1.8.24",
"version": "1.8.25",
"lockfileVersion": 2,
"requires": true,
"packages": {

View File

@ -1,6 +1,6 @@
{
"name": "mcopy-app",
"version": "1.8.24",
"version": "1.8.25",
"description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js",
"scripts": {

View File

@ -1,5 +1,5 @@
{
"version": "1.8.24",
"version": "1.8.25",
"ext_port": 1111,
"profiles": {
"mcopy": {

View File

@ -0,0 +1,13 @@
# mcopy projector firmware
The goal of this firmware is to drive a JK-compatible gate
with two (2) NEMA17 stepper motors. Registration will be tracked
by four (4) IR LED emitters and receivers tracking two (2)
double-stage rotary encoders.
1. log step index
2. calculate volate
3. analogRead() x 3
4. average readings
5. populate array with average at index

View File

@ -141,3 +141,32 @@ void state () {
stateString += String(mcopy.STATE);
mcopy.print(stateString);
}
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1125300L / result; // Back-calculate AVcc in mV
return result;
}
long analogReadAccurate (int pin) {
double Vcc = readVcc() / 1000.0;
double ADCValue = analogRead(pin);
return (ADCValue / 1024.0) * Vcc;
}
long analogReadAccurateAverage (int pin) {
int count = 3;
double sum = 0.0;
for (int i = 0; i < count; i++) {
sum += analogReadAccurate(pin);
delay(1);
}
return sum / (double) count;
}

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "mcopy",
"version": "1.8.24",
"version": "1.8.25",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "mcopy",
"version": "1.8.24",
"version": "1.8.25",
"license": "MIT",
"dependencies": {
"arduino": "file:app/lib/arduino",

View File

@ -1,6 +1,6 @@
{
"name": "mcopy",
"version": "1.8.24",
"version": "1.8.25",
"description": "Small gauge film optical printer platform",
"main": "build.js",
"directories": {

View File

@ -1,5 +1,5 @@
{
"version": "1.8.24",
"version": "1.8.25",
"ext_port": 1111,
"profiles": {
"mcopy": {