Hello everyone.
I have a programming issue. This is an ongoing project from:
https://forum.arduino.cc/t/attiny85-and-latest-ide/1275511/29
I'm trying to get an ATTINY 85 to control an electric fuel pump for a carbureted engine. My schematic is posted. I took a video of my O-scope but i'm not able to upload it.
my issue is that the setup code works. the PsiDrive pin goes high then I get a PWM for a very short time. Mabe 3-4 seconds. then it just drives high again.
what im attempting here is that the ATTINY85 reads and analog sensor and compares that to a predetermined value. That value is dictated by a toggle switch that grounds the IdlePin.
The tiny85 would then compare the actual pressure value from the sensor with the predetermined value and adjust PWM from there.
So why I'm not getting constant PWM is confusing.
(there are some lines of code that are commented out. i did this for testing)
If anybody wants to help, I'd appreciate it.
I'm wanting to make a couple PCB's for myself and a couple friends who have classic cars with electric fuel pumps.
(P.S. I don't want to get into a conversation of carb theory and pumps. I'm just looking to get my code to work and I can adjust as needed)
Thanks
// Fuel Pressure Regulator
// INPUTS
const int IdlePin = 1;
const int PsiSense = 2;
// OUTPUTS
int PsiDrive = 0;
// VARIABLES & STATES
bool IdleState;
int PsiVal; // Value assigned by analog read of 0.5 to 4.5v from Pressure sense pin
int PsiRef; // values set by idle state, values are direct ADC values.
int DriveVal; // PWM value
int Error;
int Timer;
unsigned long TimeNow;
unsigned long TimeThen;
void setup() {
pinMode(IdlePin, INPUT);
pinMode(PsiSense, INPUT);
pinMode(PsiDrive, OUTPUT);
digitalWrite(PsiDrive, HIGH);
Timer = 1000;
TimeThen = 0;
Error = 25;
DriveVal = 180;
delay(5000);
digitalWrite(PsiDrive,LOW);
}
void loop() {
//TimeNow = millis();
PsiVal = analogRead(PsiSense);
IdleState = digitalRead(IdlePin);
DriveVal = constrain(DriveVal,130,255);
analogWrite(PsiDrive, DriveVal);
// checks idle state and current fuel pressure
//if (TimeNow - TimeThen >= Timer) {
//IdleState = digitalRead(IdlePin);
//PsiVal = analogRead(PsiSense);
//TimeThen = TimeNow;
//}
// sets desired pressure to 4 psi
if (IdleState == false) {
PsiRef = 765;
}
// sets desired pressure to 2.75 psi
if (IdleState == true) {
PsiRef = 375;
}
// decrease PWM value to lower pressure
if (PsiVal - PsiRef >= Error) {
DriveVal --;
}
// increase PWM value to raise pressure
if (PsiVal - PsiRef <= Error) {
DriveVal ++;
}
// if sensor fails, default to full drive
// if ((PsiVal >= 1000) || (PsiVal <= 23)) {
// digitalWrite(PsiDrive, HIGH);
// }
}