ADC with 14M

lbenson

Senior Member
Following up on Dr_Acula's recent revelation (to me), in his PCB example, that the 14M can do multiple ADCs, I tried to code up an example in the simulator. Manual 1, p. 70-71 shows that legs 7, 8, 9, and 10 can be [ADC0, ADC1, ADC2, and ADC3 respectively--oops, I'm wrong--should be] ADC0, ADC3, ADC2, ACD1 respectively, but for ADC1-3 only after their respective pins have been set to inputs. Neither this section nor the READADC command section makes clear the syntax for using these, but I experimented in the simulator until I got something which produced no syntax errors. The code is as follows:
Code:
'14ADC
#picaxe 14M
let dirsc = %110000 ' C0-3 as inputs (for ADC), C4-5 outputs
main:
pause 5000
readadc 0,b0
readadc 1,b1
readadc 2,b2
readadc 3,b3
goto main
When I run the simulator, I get only ADC adjustment controls labelled "A0" and "A4". When I set them to, for example, "25" and "45" respectively, I get "25" in b1 and "45" in b2, indicating that my "readadc 1,b1" and "readadc 2, b2" were connected to the controls in the simulator. Have I got the syntax entirely wrong, or is there a problem with the simulator? And if the syntax is right, shouldn't the simulator present adjusting controls for each input?

I can also add the following adc commands--which should be illegal--and they compile and run, putting "25" in b5 and b9.:
Code:
readadc 5,b5
readadc 8,b8
readadc 9,b9
I don't have the necessary parts with me to test this on an actual chip.
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
It wouldn't surprise me if the Simulator isn't a 100% complete simulation.

READADC on 'illegal pins' has always been possible, same with HIGH and LOW and most other commands. Higher pin numbers usually map to lower pin numbers, probably bit-mask anded, but for things like the 14M which has ADC all over the place and spread across ports it's anyone's guess.
 

lbenson

Senior Member
hippy--you're probably right about the bit-masking--adding "readadc 10,b10" gives (in the simulator) the same value as "readadc 2,b2". But "readadc 6,b6" gives a syntax error, as does "readadc 7,b7". Having that happen for all invalid ports would seem reasonable.
 

MFB

Senior Member
Help with 14M ADC?

I have been playing with a 'real' 14M and have and also getting a bit confused when trying to configure for five ADC and three digital inputs. Before describing the problems, please can anyone see a problem with the following code?

b0=pins
let dirsc = %00000000

start: readadc 0, b1
readadc 1, b2
readadc 2, b3
readadc 3, b4 readadc 4, b5
serout 2, N1200, (#b1,",",#b2,",",#b3,",",#b4,",",#b5,cr)
serout 2, N1200, ("%",#bit3,",",#bit2,",",#bit1,cr)
pause 1000
goto start
 

MFB

Senior Member
Help!

Thanks, but I don't think I have a problem with the 14M serial output, because the following test code generates three ramping values and toggles three digital bits in sync as expected.

However, my adc version of the code does not output the state of the three digital inputs and one of the five ADC channels is effected by the state of a digital input. I don't think its my plug-board circuitry (a resistor ladder between 5V and ground, with taps at each ADC input and three pull-up resistor with switches to ground on each digital input) is at fault but I'll check again!
 

MFB

Senior Member
Sorry, missed out the following working test code:

start:
for b1 = 0 to 127
b0 = b1/2
b2 = b1*2
serout 2, N1200, (#b1,",",#b0,",",#b2,",",cr)
serout 2, N1200, ("%",#bit2,",",#bit1,",",#bit0,cr)
pause 500
next
goto start
 

hippy

Ex-Staff (retired)
@ MFB : In your example code ( post #4 ) you only read the pins once at the start of the program and not repeatedly in the Start: ... Goto Start loop.

Move the 'b0=pins' into that loop and it should perform better.
 

cpedw

Senior Member
According to the manuals, there only 2 ADC inputs on the 14M. Confusingly, Manual 1 says they are pins 0 and 4 (14M pinout, page 20) but Manual 2 syas they are 1 and 4 (readadc command).
Derek
 

MFB

Senior Member
Thanks

Hippy,
How did that line escape from the loop without me noticing? Many thanks for spotting my silly mistake. Now I just need to get the ADC stuff working reliability.

cpedw,
The main introduction to the 14M does indeed say that the default configuration has only two ADC channels. However, Appendix C (Section 1) states that “Three additional ADC pins, ADC1,2,3, are available AFTER the corresponding pin has been converted to an input” and that s what I have been trying to do.

Thanks again for all the contributions.
 

MFB

Senior Member
14M, 5 analog & 3 digital inputs

'CONFIGURE 14M FOR 5 ANALOG AND 3 DIGITAL INPUTS
'WORKS OK WITH STAMPPLOT 'NO FRILLS' SETUP


OK, this now seems to be working fine but I think the 14M documentation could do with some more examples.



let dirsc = %000 'reconfigure C0-3 as inputs

start:
b0=pins 'Read digital inputs 1-3
readadc 0, b1 'Analog input, leg 7
readadc 1, b2 ' ,, ,, ,, 10
readadc 2, b3 ' ,, ,, ,, 9
readadc 3, b4 ' ,, ,, ,, 8
readadc 4, b5 ' ,, ,, ,, 3
serout 2, N1200, (#b1,",",#b2,",",#b3,",",#b4,",",#b5,cr) 'send analog
serout 2, N1200, ("%",#bit3,",",#bit2,",",#bit1,cr) 'send digital
pause 1000
goto start
 
Top