Hello,
Quick question, when does an interrupt function triggers when for example seeing a falling edge in the signal? Is this with every slight change or does it need to fall to a given treshold before triggering?
Hello,
Quick question, when does an interrupt function triggers when for example seeing a falling edge in the signal? Is this with every slight change or does it need to fall to a given treshold before triggering?
It is the same as a digital input, look at the data sheet for the threshold voltages that determine HIGH and LOW.
a7
Oh okay, then it should work what i was trying to do. I was trying it in thinkercad first and it would't work because the simulated arduino trigger at 2.2 Volts.
Not quite. The digital input pins on (some?) AVR microprocessors have hysteresis, so will always read HIGH or LOW.
In the "not sure" region, the reading will reflect whether the pin was truly HIGH or truly LOW most recently.
Also, the switching thresholds are minimum and maximum. Some fun is available to those with no life time to spare, hook up a variable voltage and measure for realz where the switching point is. Be sure to come down from above and go up from below to see the thresholds and the hysteresis.
a7
Thanks for your input. Hysteresis is what I hoped for, but could not find that in the datasheet.
It depends on the microcontroller.
Which Arduino are you using?
And even that depends on which manufacturing lot your processor is from.
An arduino uno knockoff
I did measure it last year and it was 2.1V and 2.7V if i recall correctly.
It’s just i have a pwm signal that coms in from a thing from te car and i just need to inow when this signal ends. So i put a rc- circuit with voltage divider in front of the port and wanted to trigger the falling edge. So i needed to know these switching voltages so i can choose the capacitor to keep the voltage above this when the signal is on
I see. I ask about the frequency and duty cycle of this waveform as my preference would be to not solve this with hardware, no matter you get a solid solution having worked out the component values.
It may be possible to see every edge and use logic and the system running clock millis() or micros() to figure out the "last" transition.
Say, now I think maybe you have another thread on this matter?
a7
Thats what i had before. I used a pulsin function with a timeout of 400 microseconds so it would return 0 when the signal stopped but it was not stable. The frequency is 10kHz on roughly 10% duty cycle and the signal lasts about 500 microseconds before turning of for about 2 milliseconds
I don't see why it would have to be, although I've never liked pulseIn.
I'll look at the other thread. An interrupt routine that reset a timer, and higher level code seeing the timer reach 400 uS should be workable.Maybe with a state variable saying we are, or are not, within the active period.
Just now doing the maths in my head, it seems like you could develop an opinion about whether the train had stopped, so to speak, way sooner than the 400 uS pulkesIn timeout.
Alternately, using hardware I don't recommend, but this is a simple missing pulse detector, and that entire matter could be outsourced to a handful of components. The venerable '555 timer chip,woukd work well, no more or less fussy than working with RC constants and hysteresis and stuff.
Just thinking and typing sitting in the transit cafe.
a7
I understand that you already tried to solve it by software but you had problems of rippling during the transitions, right? Maybe the code could be improved to avoid that, I don't know.
But if you want to try the capacitor option, I think that it could work. You could add a diode to have a kind of peak follower with a resistor to discharge it. Something like this (example values, not tested):

The diode would charge the capacitor and avoid that the lower side of the signal discharges it.
You should adjust the capacitor value to make sure that it keeps charged with the 10KHz signal. And the resistor value to discharge it quick enough when the signal stops.
You have to add also the voltage divider before the ADC pin. And I would add a comparator also, to have a clean HIGH/LOW signal and some hysteresis and avoid rippling in the transition and false positives.
This way you would have a constant HIGH during the pulse duration (plus a small delay) and LOW when the pulse is not there.
okay thank you very much
yeah you have a lot of good options and i tried most of them already, right now, the pulsinfunction with a timeout works best. Everytime I change something, Its changes everything and nothin works anymore
Then for a falling edge it must go below 0.3xVcc and for rising it must go above 0.7xVcc.
If Vcc=5V then for falling it’s 1.5V and for rising it’s 3.5V
@sander420 ,
Is this part of your main topic:
?
If so, they probably should me merged to keep the information in one place.
Thanks,
yes it is. I know it should be merged but this post doesn't necessarily needs the information of the other topic that's why i spilt it.