Need a way to detect a voltage drop.

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.

how fast is too slow ?

I think the answer is no, could be anywhere...

but the question is are you looking at a voltage drop in a specific window ? say from 2.8 to 2.7?
what range could the signal be ?

its a analog signal that drops from 2.82v to 1.5 give or take and as far as speed the pins are fast enough just the code needs to be fast as possible.

the main issue is catching this initial drop and would like to keep the compare as close to 2.8 like 2.7 but doesn't have to be exactly that.

kinda like the interrupt but analog not digital that way when the voltage drops from 2.8v it starts a function not just high/low.

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.

Borrowed from acidmods forum.

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?

No just when it detects that drop,

start a timer

wait 500us

then drive the analog pin to 1v or so

then wait out the rest of the pulses

and start back over looking for that drop again

I try it in code...

#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 ;)
  
}

Can you explain this just a little bit. i get some of it... :confused:

Please just a little nudge in the right direction. im not exactly an expert in arduino programming but know some basics.

what the program does is:

  1. wait for a voltage drop, while the analogRead() is higher than 700 it waits

  2. Then it remembers the start time,

  3. make 50 readings and put them in an array for later processing

  4. 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!!)

The rest is up to you...

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.

JimmyMac88:
then drive the analog pin to 1v or so

Drive what analog pin to 1V or so? The Arduino does not have an analog output. PWM, yes, anaolog, no.

Ok I'm using a attiny85 with the arduino core.

I have 2.8v going to it

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.

Again any info or help is greatly appreciated!

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?