After much support from this forum i was finally able to come up with a code that does what i need for my project.
Its just a "watchdog" when a 12500hz pulse is present it turns on an led, and when the signal is gone it turns off the led.
The problem i am experiencing, is my led will flicker, or turn off briefly, when it should be solid lit.
The input signal is steady, i can adjust my thresholds all over the place and the blinking still occurs. When the circuit is "off" it does not blink "on" it only blinks off when it should be solidly lit {trigger signal is present}
i have tried various pull ups and pull downs on the input. Ive tried a few different capacitors in various configurations {no method, just plugging things in really}
Ive tried adding delays of various lengths in various spots in the code. with limited success. The part that really gets me is even with these long delays in place, the blink is quicker than the circuit responds to actual input change.
Depending where i put the delays i can make the blink slower {more pronounced} or faster {less noticeable} but i cannot eliminate it.
It seems like the code is overflowing and causing some sort of reset.
or possibly there is noise on the input line that i really don't know how to deal with.
I am using an Arduino Uno r3 for programming and running the code on an ATTINY45 thats imbedded.
int inPin = 3; // Charge Pump Input Packge Pin 2:
const int ledPin = 2; // Current Enable {Half} Package Pin 7:
const int led2Pin = 1; // Current Enable {Full} Package Pin 6:
const int SpinPin = 0; // Spindle Enable Package Pin 5:
unsigned int duration; // VCC+ Package Pin 8, GND Package Pin 4:
void setup() {
pinMode(ledPin, OUTPUT); // initialize the Current Enable pin as an output:
pinMode(SpinPin, OUTPUT); // initialize the Spindle pin as an output:
pinMode(inPin, INPUT_PULLUP); // make the pin an input:
}
void loop() {
duration = pulseIn(inPin, HIGH, 200);
if(duration >=20)
{
digitalWrite(ledPin, HIGH);
digitalWrite(led2Pin, HIGH); // Enables Current Enable Opto:
delay(200);
}
else{
digitalWrite(ledPin, LOW);
digitalWrite(led2Pin, LOW); // turn Current Enable off:
}
if (digitalRead(ledPin) == HIGH && digitalRead(4) == HIGH) // Spindle input from pc
//Digital 4 is Package Pin 3:
{
digitalWrite(SpinPin, LOW); // Enables Spindle Opto:
}
else{
digitalWrite(SpinPin, HIGH); // turn Spindle off:
}
}