Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:42 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Interrupt on analog voltage change on Analog Input pin?

     Page 2 of 2    
Author Message
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5648
Posted: 11:03pm 28 Feb 2021
Copy link to clipboard 
Print this post

In theory, unless the input drops below 0.65v you won't get a high-low interrupt to work. However, I did. Not by design though. :) I rigged up a temporary Micromite and tried it. If you want to be *certain* of it working then you should choose resistor values that pull ain below 0.65v.

The resistor network I used wasn't a ladder. I simply switched individual resistors from ain to ground. It made it very easy to test. I just ran the interrupt routine which contained a print pin() statement so I could see the voltage. If there was no interrupt nothing happened, if there was then it gave me the voltage for that resistor.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1584
Posted: 11:44pm 28 Feb 2021
Copy link to clipboard 
Print this post

Changing one resistor would make it more reliable with temperature changes, supply voltage changes or a replacement chip. Better safe than sorry.

Bill
Keep safe. Live long and prosper.
 
Swartz
Newbie

Joined: 15/12/2020
Location: United States
Posts: 18
Posted: 12:52am 01 Mar 2021
Copy link to clipboard 
Print this post

Thanks guys --

I have continued to experiment and have referred to the specs on the device. Having done so - have determined better values for reaching the required thresholds.

Thanks!
Swartz
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5648
Posted: 09:46am 04 Mar 2021
Copy link to clipboard 
Print this post

Final idea derived from spreadsheet (I hope I did it right! :) ).

  3.3v
    |
   2k2
    |
ain-+-100-+-100-+-100-+-100-+-100-+
    |     |     |     |     |     |
    /     /     /     /     /     /
    |     |     |     |     |     |
0v--+-----+-----+-----+-----+-----+
    0   0.143 0.275 0.396  0.5   0.61  Volts
    0     44    85   122   157   189   Count

This allows up to 6 buttons with detection via interrupt while remaining within spec for Vlow at the input. Maximum current from 3.3v is 1.5mA. I hope it's of use to someone.
Edited 2021-03-04 19:47 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1584
Posted: 11:39am 04 Mar 2021
Copy link to clipboard 
Print this post

My spreadsheet agrees with yours. Enclosed if it's of any use (Libre Office ods). I would prefer a 10K pullup resistor and I would add a 100nF capacitor from AIN to ground to aid debounce.

Voltage Divider Calculator.zip

Bill
Keep safe. Live long and prosper.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2282
Posted: 01:32pm 04 Mar 2021
Copy link to clipboard 
Print this post

if you placed a capacitor across each of the 100 ohm resistors, then you could extend the number of switches while still reliably generating the interrupt. with all switches open, the capacitors would be discharged and hence present a brief short when a switch was closed.

this (using capacitors across resistors) may work more reliably with each resistor tied back to the Ain pin and using ascending values (rather than a chain of all the same value).

fun note: we just had a little earthquake here in christchurch, nz!    


cheers,
rob   :-)
edit: not so little - was 6.15 magnitude in rotorua, 670km away from here  
Edited 2021-03-04 23:40 by robert.rozee
 
Swartz
Newbie

Joined: 15/12/2020
Location: United States
Posts: 18
Posted: 05:10pm 04 Mar 2021
Copy link to clipboard 
Print this post

Still amazed!
At the risk of repeating myself or gushing...
This board rocks!

Cheers!
Swartz
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5648
Posted: 06:32pm 04 Mar 2021
Copy link to clipboard 
Print this post

ulp!, Rob....
You don't want too many of those.

Bob: IMHO 10k might be a bit on the high side. Aren't you supposed to keep the input resistance below 10k for analogue inputs? I might be wrong. I did actually have 100nF from ain to gnd, but I didn't show it on this diagram. I think it reduces bounce on button release (as it takes time to charge up to >2.5v - it's not necessary on button close as the interrupt occurs once on the falling edge and is then disabled within the interrupt routine.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1584
Posted: 07:01pm 04 Mar 2021
Copy link to clipboard 
Print this post

  Quote   IMHO 10k might be a bit on the high side. Aren't you supposed to keep the input resistance below 10k for analogue inputs?

Yes. The micromite input impedance is >1Meg ohm, 10K could give up to 1% error. Forget I spoke.

Rob, I hope all is OK, you don't need another big one.

Bill
Keep safe. Live long and prosper.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 09:51pm 04 Mar 2021
Copy link to clipboard 
Print this post

  robert.rozee said  
fun note: we just had a little earthquake here in christchurch, nz!    


cheers,
rob   :-)
edit: not so little - was 6.15 magnitude in rotorua, 670km away from here  


Magnitude 8 off the NE coast of the north island.

We were all set to holiday in NZ a few years ago until a big(ish) quake in Christchurch persuaded us to go to 'old' Zealand instead.

I still hope to get across the ditch one day but you will have to stop shaking before the wife will go with me.

Jim
VK7JH
MMedit   MMBasic Help
 
Swartz
Newbie

Joined: 15/12/2020
Location: United States
Posts: 18
Posted: 04:20pm 08 Mar 2021
Copy link to clipboard 
Print this post

@mixtel90

Just out of curiosity , could something like this be done with voltage drops with diodes in series and switches between them ?

As said - just curious.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5648
Posted: 06:00pm 08 Mar 2021
Copy link to clipboard 
Print this post

I don't think it would be reliable. If you were simply testing the analogue input then yes, but you need a logic 0 (less than 0.65v) on the input to get a reliable interrupt, hence the low voltages from the resistor network.

As I managed an interrupt at 1v you could try using 1 or two schottky diodes to give 0.4v or 0.8v - possibly with a 0.65v from an ordinary diode and 0.3v from a germanium one. :)

Experimenting is fun but the result might only work with that chip at that temperature on a Thursday. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3422
Posted: 09:22pm 08 Mar 2021
Copy link to clipboard 
Print this post

If you want more switches reliable on one pin. I suggest following:

All switches S1...Sn connect to ground
In series with each switch add a resistor parallel to a capacitor.
All capacitors are 10nF
Resistors are 100k, 81k, 56k, 39k, 22k, 10k, 6.8k, 4.7k, 3.3k, 2.2k, 1.5k

Have a common pullup (10k)

This will make that each switch has a clearly different voltage, using the whole range of the ADC.
And each key will generate a clear interrupt level (0V).


+3.3V------10k---------+---------+--------+---//----+--------ADC
                      |         |        |         |
                   100k//10n  81k//10n 68k//10n   1.5k//10n
                      |         |        |         |
                     SW1       SW2      SW3       SW10
                      |         |        |         |
                     GND       GND      GND       GND


The trick is to wait a little after the interrupt, until the voltage settles.
With 100k and 10n that time will be 5ms, others are shorter.

Volhout
Edited 2021-03-09 07:24 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5648
Posted: 10:31pm 08 Mar 2021
Copy link to clipboard 
Print this post

Nice idea, Volhout. Is 10k pull up low enough to satisfy the maximum input resistance in the spec though? I suspect it might be - just about - but I think I might prefer something a little lower just to be certain.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1584
Posted: 12:07am 09 Mar 2021
Copy link to clipboard 
Print this post

If you take into account the input impedance of the micromite pin is approx >1 meg ohm when calculating the analogue input value.

1 meg ohm in parallel with 100k = 90.9k etc.

But I agree that lower values may be better, probably using a 100nF capacitor. This is pretty much what Rob suggested.

Bill
Keep safe. Live long and prosper.
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024