9S08QG8 detecting keys using ACMP function of ADC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

9S08QG8 detecting keys using ACMP function of ADC

4,644 Views
stevec
Contributor III
I'm using a resistor chain with the bottom tap into PTA0 to detect a series of 7 switches, shorting each tap point to VSS to give different analogue levels into PTA0. I want to use the automatic compare function to trigger an interrupt so I can register a key press. I have made a resistor chain  totalling about 140kohms (need to reduce standby current then in sleep mode) and am finding that the voltages produced dont come anywhere near what I expect. Has anyone used this method of key detection, and what resistor values were used? I'm assuming its something to do with the input impedance of the ADC channel affecting the resistor chain value.

Steve
Labels (1)
0 Kudos
11 Replies

855 Views
bigmac
Specialist III
Hello Steve,
 
I completely agree with Curt's observations.
 
Perhaps something like the attached schematic would give better results.  With equal value resistors used for simplicity, the voltage step, as each switch is pressed in succession, will be non-linear.  The nominal A/D readings shown for each switch are based on 8-bit conversion.
 
With the configuration shown, there would be no current flow while no switch is pressed.
 
Regards,
Mac
 
0 Kudos

855 Views
stevec
Contributor III
Thanks for the replies guys. Seems obvious when somebody else explains it. My arrangement was similar to yours Mac except that I had 0V where you had Vdd and all switches commoned to Vdd thus my first tap is your top tap. I have also worked the resistors to give an approximate even voltage step. However I've the volts expected dont appear in practice. I believe my resistor values are too high and the results are being affected by the input impedance of the A/D. Now I realise there will be no drain on the power when switches are open (just call it a 'senior moment')  I can drop the values significantly.

Thanks again.
Steve
0 Kudos

855 Views
joerg
Contributor II
Hi
In general the input resistance of the HC(S) MPU's is around 5 kOhm (see the data sheet)! So for almost linear steps you have to calculate the steps regarding R(ADIN) too!
In general i use a  buffer amplifier for measuring  AD signals (LMC6482, rail to rail [input and output]).

Saluti Joerg

0 Kudos

855 Views
Curt
Contributor IV
joerg:
 
Do you know if that Radin on the data sheet is an AC or a DC parameter?  It's
not clear to me from looking at the data sheet, since it shows Radin in series
with an ADC block of unkown input characteristics (but not a short to ground
surely?)
 
Understanding this is obviously pretty important to using the ADC!
 
Put another way:  if I connect a 1VDC source to the AD input via a 4K resistor   -- what will the ADC report after a conversion?
0 Kudos

855 Views
bigmac
Specialist III
Hello,
 
My interpretation of the data sheet is that the Radin parameter represents the series resistance of the integral input multiplexer to the ADC.  It will influence the minimum required sampling time only.
 
Note that, for 10-bit accuracy, the external series resistance Ras must not exceed 5k, so the input resistance to the ADC must actually be much much greater than say 10k (Radin + Ras) to achieve this accuracy.  For a lower required accuracy Ras might be considerably larger, provided a longer sample period is used (ADLSMP = 1).
 
Regards,
Mac
 
0 Kudos

855 Views
joerg
Contributor II
Hi
I did a test (using a HC08QB8, so i had to change only some software and only to connect a wire to my hardware) in 10 bit mode. It shows that bigmac (as always) is wright! Connecting the  MPU directly to a Voltage source i.e. 3.4V shows me a value of 708 and connecting it via a 47kOhm resistor 705! So the influence of the resistor in series is minimal. (the values are sampled every 4ms and the program makes a mean value over 256 samples).

It would be nice if the data sheets are clearer, especially if other MPU's like the QT/QY have much lower input impedance.

Saluti Joerg
0 Kudos

855 Views
stevec
Contributor III
Thanks for the replies guys. Joerg, I could use a buffer which would solve the problem. However this is to be used with a battery powered piece of equipment and I cant afford the idle current consumption of a mA or so. This device will be used sporadically for an hour or two then be idle for possibly days. I would like to keep inactive current drawn to a few microamps when the QG8 is in stop3 mode. I will wake the processor up using the ACMP interrupt. So if anyone knows of a buffer that works at a few microamps......
0 Kudos

855 Views
Curt
Contributor IV
Hi stevec:
Using a ladder like the one diagrammed by bigmac, you shouldn't need the buffer at all, and could probably scale all the R's up to reduce power consumption as well. 
 
If you're really thinking about a power budget where microamps matter though, be
sure to check the A/D input leakage current and power specs on your data sheet.   
1 uA is not an unusual leakage spec, and A/D power consumption can be pretty high
(relatively speaking) even in "stop". 
 
 
0 Kudos

855 Views
stevec
Contributor III
Thanks Curt,

I'm actually working out the individual resistor values by sustituting a pot for each leg and adjusting for a 0.4V difference between each switch. The values are not coming out as I've calculated so am doing it the hard way , sorting each resistor in turn. I'll look at the values obtained and can maybe characterise the input from those. Whether the values arrived at are translatable across a production batch remains to be seem! Not quite there yet but will try Bigmac's suggestion as well.

Regards,
Steve
0 Kudos

855 Views
bigmac
Specialist III
Hello Steve,
 
For approximately equal 0.4 volt steps, and with a 3.3 volt Vdd, I would calculate that the following resistor values should work.  The values given are in accordance with my previous schematic, and the voltage error for each step should be less than 50mV, using 1 percent tolerance resistors.
 
R1 = 22k, R2 = 3k0, R3 = 3k9, R4 = 5k6, R5 = 8k2, R6 = 13k, R7 = 24k, using E24 preferred values.
 
The current drawn when each switch is closed will vary between 40 and 150 uA.  This is getting quite low for reliable operation of mechanical switch contacts - at these current levels the switch contacts should preferably be gold plated.
 
Regards,
Mac
 
0 Kudos

855 Views
Curt
Contributor IV
Hi stevec:
 
Don't you want the TOP tap tied to PTA0?   If I understand your configuration, you're going to be measuring (Vss + Noise) regardless of which switch you close.
 
Or am I misunderstanding the setup?
 
Regards,
Curt
 
0 Kudos