I'm trying to use an Arduino Mega 2560 for a simple controller for a 0-5v analog signal controlling a mass flow controller. As it is right now it works using 3 buttons: up, down, and zero.
The issue is I need smaller voltage steps than the default 8bit pwm enables so I'd like to take advantage of the 16 bit counters on my Mega chip. I've been trying to use Timer1 to do so as directed on these two pages:
https://www.pjrc.com/teensy/td_libs_TimerOne.html
[url=http://http://playground.arduino.cc/Code/Timer1
I am struggling to get either of these to work - even something basic like just attaching it to an led and using Timer1.pwm() to manually control the pwm brightness.
can someone point me in the direction of an easy way to get this enabled? Even something simple like a link to some code that enables 16 bit and sends a pwm signal thats changed manually in the code?
Below is a link to the code I would like to eventually get working as 16 bit:
const int flowUp = 4; // the number of the pushbutton up pin
const int flowDown = 3; // the number of the pushbutton down pin
const int flowZero = 2; // the number of the pushbutton zero pin
const int controlPin = 13; // the number of the flow controller pin
const int maxFlow = 255; //this can be any number - it's the number of steps between dimmest and brightest.
// variables will change:
int flow = 0;
int interval=1;
void setup() {
// initialize the controller pin as an output:
pinMode(controlPin, OUTPUT);
// initialize the pushbutton pins as an input:
pinMode(flowUp, INPUT);
pinMode(flowDown, INPUT);
pinMode(flowZero,INPUT);
Serial.begin(9600);
Serial.println(flow*0.0588);
}
void loop(){
if (digitalRead(flowUp) == HIGH && flow < maxFlow){
flow = flow + interval;
//if the flow Up button is pushed, add one degree of flows to the current level
Serial.println(flow*0.0588+.07); //for debugging purposes
}
if (digitalRead(flowDown) == HIGH && flow > 0){
flow = flow - interval;
//if the flow Down button is pushed, subtract one degree of flow from the current level
Serial.println(flow*0.0588+.07); //for debugging purposes
}
if (digitalRead(flowZero) == HIGH && flow >= 0){
flow = 0;
//if the flow zero button is pushed, resets to zero
Serial.println(flow*0.0588); //for debugging purposes
}
delay(100);
analogWrite(controlPin, map(flow, 0, maxFlow, 0, 255));
//this code maps the max flow constant to the max flowrate
}
I'd really appreciate any help, I'm brand new to arduinos and coding so I'm trying to learn as I go.