Hey guys im looking at some project feasibility.
I need to do two analog reads, a digital read, and process a calculation and provide an I2C response within (I estimate) 250 microseconds.
I tried to set the pre-scalars for the analog reads the posted about way but it doesn't seem to compile. here's a link to the standard stuff: Faster Analog Read? - Frequently-Asked Questions - Arduino Forum
I also started writing up some code to handle this, its been about 7 years since i have done much so im a bit rusty. let me know what you think or if I made any egregious mistakes.
void setup() {
Wire.setClock(400000); // Set the SCL clock speed to 400kHz
dac.begin(0x60); //Start DAC. DAC address 0x60 or 0x61
#define MICROSECONDS_PER_MINUTE (60UL*1000000UL)
#define PULSES_PER_REVOLUTION 3
int Tach = 4;
pinMode(Tach, INPUT);
int fValue = analogRead(A1);
int PValue = analogRead(A0);
int FFinal = fValue
}
void loop() {
// put your main code here, to run repeatedly:
fValue = analogRead(A1);
PValue = analogRead(A0);
if (pValue < 300){
dac.setVoltage((fValue * 4), false); //writing voltage out without adjustment
} else {
float MAFAdj =
(((980 - pValue)*(7050- currentRPM(Tach))/(555)) +
((pValue -425)*(7050- currentRPM(Tach))/(555)*1.135) +
(( (980 - pValue)*(currentRPM(Tach) -4150)/(555)) * 1.092) +
((( pValue - 425) * (currentRPM(Tach) -4150)/(555)) * 1.361));
int FFinal = fValue * MAFAdj *4;
dac.setVoltage((FFinal), false); //write final voltage to adjusted maf out
}
}
int currentRPM(int inputPin) {
unsigned long pulseLength = pulseIn(inputPin, HIGH); // Microseconds per pulse
pulseLength = (pulseLength * 100) / 30; // Convert from 30% to 100%
unsigned long pulseRate = MICROSECONDS_PER_MINUTE / pulseLength; // Pulses per minute
return pulseRate / PULSES_PER_REVOLUTION;
}
A few questions:
-the DAC im using over i2c requests a HEX handoff so im just supplying it a 0-4095 integer and I think that will work.
-Any estimates on the performance of this on the Every's 20MHz processor? (I realize while writing this that I am polling RPM every time in the calculation, ill update it to read once and write to a variable per loop.))
Thanks for taking the time to read!