Question about Picaxe Manual 1

elanman99

Senior Member
Appendix E to F give addition information on pin configuration for most of the Picaxe versions. I cannot see any reference to 18M2 and I am unsure of which pin I can use for a 10 bit ADC input.

Have I missed something obvious?

Ian
 

Technical

Technical Support
Staff member
Those appendices are for old obsolete types.

Simply look at the pinout diagram at the front of the manual, all ADC pins are listed, and all ADC are 10 bit.
 

elanman99

Senior Member
Those appendices are for old obsolete types.

Simply look at the pinout diagram at the front of the manual, all ADC pins are listed, and all ADC are 10 bit.
Thank you Technical I understand better now.

I am using an 18M2 with a pot and a servo with some code from the Forum Code Snippet section and seem to get the same results with readadc or readadc10.

The code I am using (below) and I want to match the pot travel to the servo travel, I assumed I would just have to adjust the values in the equation but I cannot seem to make any sense of the relationship.

What would I be the best using (simulator, sertxd or?) to show me what is happening within the code? I also have a serial LCD I could connect up to another pin

Code:
' Test programme pot and servo
' Pot wiper to  C.1 (Pin 18)
' Servo lead to B.0 (Pin  6)

Symbol Servosignal = 0
Symbol Position = b0
Symbol Delay = b2

Let delay = 33

do

readadc10 C.1,Position

Position=Position *5/17+180

pulsout servosignal, Position

pause delay

loop
 

srnet

Senior Member
Well readadc10 needs to be used with a word variable, your reading it into a byte variable.

To see the result of the ADC on the terminal screen change the code to;

readadc C.1,Position

sertxd("AD Read ",#position,CR,LF)

Position=Position *5/17+180

sertxd("Servo Position ",#position,CR,LF)
 

hippy

Ex-Staff (retired)
What would I be the best using (simulator, sertxd or?) to show me what is happening within the code? I also have a serial LCD I could connect up to another pin
Simulation is good to test out code and see if it does what is expected, while adding SERTXD to a program running in a real chip ( as srnet describes above ) is best to show that the inputs and results generated with the real hardware match what would be expected.

An LCD can be useful but may also be a hindrance or misleading if the data it shows does not represent exactly what should be shown. A SERTXD to the PICAXE Terminal is often much more reliable and easier to add. In most cases a download cable would be left connected so I would usually recommend SERTXD over an LCD display.
 

elanman99

Senior Member
I have added the lines suggested by srnet and can see 0 to 1023 as the readadc10 signal, (I've changed it to Symbol Position = W0) The mathematically modified numbers come out as 180 to 480. Those values give weird erratic servo output pulses which vary from 0 to 2400uS (although it just jumps from 0 to 900).

I am measuring the pulse width on a bit of test gear I built years ago with a S****P BS2 and serial LCD, it does show sensible numbers usually

The code snippet I started with was posted by Goeytex a couple of years ago

Ian
 

Technical

Technical Support
Staff member
For the pulsout command you want modified numbers in the range 75 to 225 only for a normal servo, so adjust the maths to fit.

Or just use the servo command instead.
 

elanman99

Senior Member
Doh!

I must be having an off day (a week really) as I should have known the range of number needed as I've used pulsout previously.

Actually I have just realised something else. The whole point of Goeytex's code was to use pulsout (and readadc10) instead of servopos and his code showed that equation which is why I used it.

I will 'do the math' now.

Thanks

Ian
 

westaust55

Moderator
Looking at the code you first posted, I suspect that it was intended to be run with the 18M2 operating with a clock speed of 8MHz so that the Pulseout durations are half of those you are observing and the delay would be about 17 ms so the pulses are repeated roughly every 20 ms.
 
Top