Im trying to detect the falling edge of a voltage drop to start a very strictly timed program.
say when
A0 goes from >=2.8 volts to 2.7 or something in that general area. i need it to start a function that carries out the timed program.
ive looked at comparators, interrupts, and even variable comparison which is to slow..
any ideas here? and it has to be analog and only use one pin for input/output.
Thanks and i have the oscope reading and will explain what im working on if needed i dont mind sharing my work with the world.
Check the datasheet. Read about the Analog Comparator, and the interrupt associated with it. Look at the comparator's speed in the "electrical characteristics" section, and decide if it's fast enough. If it's not, consider using an external comparator connected to one of the INTX pins.
You don't say anything about what "strictly timed" means in this context. Maybe you need a response - like an output - within a narrow time window, or maybe you need to know the time that the transition happened quite closely. If you want to know when something happened, then the Input Capture register associated with Timer1 and the analog comparator will help, since it captures the timer value in hardware, without assistance or response from the program.
JimmyMac88:
... will explain what im working on if needed ...
I'll go out on a limb and say, "needed." It's hard to tell what will really help you in this application without knowing more about it.
im working on a ps3 controller and trying to manipulate the com2 signal for a macro and this has been done with a microchip but i wanted to do this with the attiny85 well because it what i have.
i know the timing is in 500microsecond intervals i just need to detect that initial drop you see in the image.
analogRead() can do 8 or 9 reads per millisecond in a tight loop, so watching this 500 usec drop is possible. ! 4 reads should do it.
By lowering the resolution from 10-> 8 bits you can the ADC read it even faster (need to look for a link)
Do you want the Arduino to do anything else during this polling?
#define SAMPLES 50 // adjust to need 50 ~~ 5 milliseconds
uint16_t ar[SAMPLES];
void setup()
{
Serial.begin(115200);
Serial.println("start");
}
void loop()
{
// wait for a voltage drop lower than 700/1024 *5V
while (analogRead(A0) > 700);
// make measurements (adjust to your need)
uint32_t start = micros();
for (int i=0; i< SAMPLES; i++)
{
ar[i] = analogRead();
}
uint32_t stop = micros();
// process the array now, you know the samples are more or less equidistant in time between start and stop.
???? // this will not compile ;)
}
wait for a voltage drop, while the analogRead() is higher than 700 it waits
Then it remembers the start time,
make 50 readings and put them in an array for later processing
remember the stop time
e.g. if the (stop - start) == 5720 micros for 50 reads you know that the individual reads are
5720/49 == 117 micros apart (note between 50 values you have 49 distances!!)
since the main voltage is relatively stable. it would seem a comparator in hardware would be easy to do.
of course that would be additional circuitry.
it would be faster than software and could output a voltage to any input pin in case it would be faster to look for on/off value on a pin instead of the analogue route.
My signal that I'm reading is 2.8v give or take a little and I need to do this -
** Detect when the signal starts to fall from the 2.8v
** wait some odd time
** drive that same pin high
** then wait until the sinal is finished
** the do it all over again.
I'm looking into the interrupt idea but like I said I'm a noon and a don't really get it or how it works and if if is dependent on the voltage input. In all honesty I'm so confused that I gave up for a while and now I'm trying again.
I'm also not sure if the limitations of the arduino core on this will work for me.
I tried that code and countless others once again to no avail.
I wouldn't use an interrupt for that - just use analogRead to read the voltage at whatever frequency you need and check whether it has dropped below your threshold. The rest of the requirements to configure the analog pin as a digital output and do timed output on it seems straight forward.
Problem is that it will detect that mid signal. Where timing here is important Ineed to start at the bbeginning to get the timing correct see oscilloscope picture for the signal. Also with it only runningon 2.8v is the high considered 2.7 or 5v?