08M - Possible bug in TUNE and READADC commands.

AndyGadget

Senior Member
I've just spent 2 hours debugging a circuit on the 08m prototyping board, vassilating between suspecting the hardware , the software and the firmware (and the cat's ancestry). I was reading an ADC value, indicating it with TUNE and then setting position of a servo. Very Strange things were happening.

I finally nailed it when I noticed the direction register changing when it shouldn't.

Using the TUNE command (pin 2) sets pin 4 to an output. Demonstrated here :-

Code:
#picaxe 08m

do	
	input 4
	debug
	wait 4
	
	tune 2,2,(0)
	debug
	wait 4
loop
Also, READADC does not configure pin :-

Code:
#picaxe 08m

output 4
wait 4

do
	readadc 4,b0
	debug
	wait 2
loop
Manual entry for READADC states that 'configuration is automatic' but it does not happen in this case. (OK, READADC would only work as an input, but I would read 'automatic' to mean it defines the pin direction as well as enabling it for ADC.)

Both happen on the sim and the chip.
Workaround is to issue an 'input 4' after using 'tune'.

Prog edit 5.2.10
Firmware version 9.2
PicAxe 08m Firmware version 2

Andy.
 
Last edited:

hippy

Ex-Staff (retired)
This has always been the behaviour of the 08M though I can see where the confusion on automatic configuration comes from.

On the X2's the pins must be set to be used as analogue inputs by the programmer, this is automatically done in the pre-X2, hence, "on X2 parts the adcsetup command must be used to configure the pin as an analogue input. On all other parts configuration is automatic". "Configuration" in this sense means "make able to be used as an analogue input".

Normally one would never read an analogue input from a pin which is used as anything but an input as it doesn't make sense under normal circumstances ( an output high or low would affect the analogue source, possibly catastrophically ) so there's no particular need for READADC to make the pin input before use as it should already be an input.

In this case TUNE makes Pin 4 an output, but the subsequent READADC has no reason to suspect it would be anything but an input already and assumes it will be so doesn't explicitly make it an input.
 

AndyGadget

Senior Member
Check the command manual. Tune 2,2.... on the 08M does just that: it flashes pin 4 in time with the music.
This is where I slap myself repeatedly around the head !!!!

I've been using other chips and 'knew' the command was 'TUNE pin,tempo',
Of course, on the 08m it's 'TUNE led,tempo'.
Thanks Peter.

Hippy, my first mistake brought the other point to light. If you do nothing to the pin, it would default to input and so no problem. By coincidence though, I do have something planned which uses a pin both as an output and ADC at various times. (I'll give you the benefit of the doubt on your definition of 'automatic' #;¬)

Andy.

P.S. Robotics servo tester / exerciser / calibrator now working and will appear soon on Instructables.
 
Last edited:
Top