Strange Problem

alpacaman

Member
I've been using PICAXE chips for about a year and I haven't run into this problem before.

The circuit:
18X Picaxe
Unused inputs tied low thru a resistor
Other inputs going to push buttons and resistor. Other side of resistor goes to common. Other side of push button goes to +5.
Reset is tied high
Serial In tied low.

The program:
At start up a message is displayed on a LCD. When a push button is pressed a different message is displayed.

The program works as expected after initial programming. However, if I turn power off and on again the start up message displays ok but the buttons no longer work.

With a volt meter I verified that the reset pin is high and the serial-in is low. I also checked the inputs while pressing the various push buttons.

Any ideas?
 

Pekari

Senior Member
I have this idea:

a) Program doesn't run if some input voltage is higher than PICAXE supply voltage.

b) Is those pins (reset and serial in) CONNECTED to high and low, not only floating?
This I learn here forum today, IT MUST BE CONNECTED!
 

gbrusseau

Senior Member
If I read you right, when the button is pushed, the +5 goes directly to the PICAXE input pin.
Thats a big problem. You need a resistor in series with +5 and the input pin
 
Last edited:

alpacaman

Member
If I read you right, when the button is pushed, the +5 goes directly to the PICAXE input pin.
Thats a big problem. You need a resistor in series with +5 and the input pin
I'm aware that manual 3 shows a resistor in series with the +5 and the input pin. However, I have it wired as shown on the very next page, page 26. I think the reason for the resistor is when the push button is on a pin which could be either an input or an output it protects the picaxe should the pin be configured as an output and the push button is pushed. Without the resistor you would effectively be shorting the +5 to ground (thru the picaxe). Since the input pins on the 18x are input only I'm not using the resistor. Technical can correct me if I'm wrong on this.

I've been doing push buttons this way for a year with absolutely no problems. Plus it doesn't explain why it works after I program the chip, and it continues to work until I recycle power.
 

alpacaman

Member
I have this idea:

a) Program doesn't run if some input voltage is higher than PICAXE supply voltage.

b) Is those pins (reset and serial in) CONNECTED to high and low, not only floating?
This I learn here forum today, IT MUST BE CONNECTED!
Yep - they are tied high and low. First thing I checked.
 

hippy

Technical Support
Staff member
In reverse order ...

@ gbrusseau : Direct +5V via a switch into the PICAXE should't be a problem, maybe not recommended for ESD etc but does work. Your second diagram turns the switch into a voltage divider, the 'safety resistor' should be in series from the input pin to the swich/pull-down join.

@ Pekari : Phatom power supply via I/O can be a problem for PICAXE and PICmicro but if it's resetting cleanly enough to display the turn-on message it should have reset cleanly enough to have initialised the button inputs ( and they are fixed inputs anyway on 18X, configueed by firmware ).

@ alpacaman : Very odd. Could it be something in your code which makes it behave slightly differently on a subsequent run; are you using Data Eeprom ?

One thing I'd suggest is to disconnect the LCD and run a simple test program; a simple loop which reads pins and sends them back to the PC via SERTXD. Does that exhibit the same problem or does that work ... ?

Code:
Do
  SerTxd( "Pin? = ",#pin?,CR,LF )
  Pause 500
Loop
Then re-connect the LCD and test again.
 

alpacaman

Member
Hippy - I'll give that a try.

Below is my code

Code:
'*************************
'* MIDI LCD Readout with *
'* Voice, Channel, and   *
'* Attack control        *
'*************************
'18X

'LCD control
symbol latchout = 4
symbol outnibble1 = b0
symbol outnibble2 = b1
symbol counter = b2
symbol rs = b3
symbol lcdinst = 16
symbol lcddata = 48
symbol x = b8
symbol y = b9
symbol numberposition = b10

'MIDI Variables
symbol voice = b4
symbol channel = b5
symbol attack = b6

symbol readinput = b7

setfreq M8

'**** Initialize LCD ****
For counter = 0 to 5
	lookup counter, ($33,$32,$28,$0C,$01,$06),outnibble1
	rs = lcdinst
	gosub lcdout
next counter

'**** Initialize MIDI Defaults ****
voice = 0
channel = 1
attack = 127

gosub mainScreen

'**** Main Routine ****
main:
	readinput = pins
	if readinput = 1 or readinput = 2 or readinput = 65 or readinput = 66 then
		if readinput = 66 and voice < 127 then
			voice = voice + 1
			pins = 128
		end if
		if readinput = 65 and voice > 0 then
			voice = voice - 1
			pins = 64
		end if
		
		y = voice
		numberposition = 8
		gosub voice_lcd
	end if
	
	if readinput = 4 or readinput = 68 then
		if readinput = 68 then
			if channel = 16 then
				channel = 1
			else
				channel = channel + 1
			end if
			pins = 192
		end if
		
		y = channel
		numberposition = 9
		gosub channel_lcd
	end if
	
	pins = 192
goto main

'**** Main Screen ****
mainScreen:
	rs = lcdinst
	gosub line1
	rs = lcddata
	for counter = 0 to 15
		lookup counter, ("  PICAXE MIDI   "),outnibble1 
		gosub lcdout
	next counter
	return

'**** Voice ****
voice_lcd:
	rs = lcdinst
	gosub line2
	rs = lcddata
	for counter = 0 to 15
		lookup counter, ("Voice           "),outnibble1 
		gosub lcdout
	next counter
	
	gosub numbers_lcd
	
	'--- hundreds ---
	x = y // 10
	x = x + 48
	outnibble1 = $C0 + numberposition - 2
	rs = lcdinst
	gosub lcdout	
	outnibble1 = x
	rs = lcddata
	gosub lcdout
	y = y / 10
	
	return

'**** Channel ****
channel_lcd:
	rs = lcdinst
	gosub line2
	rs = lcddata
	for counter = 0 to 7
		lookup counter, ("Channel "),outnibble1 
		gosub lcdout
	next counter
	
	gosub numbers_lcd
	
	return

'**** Display Numbers ****
numbers_lcd:	
	'--- units ---
	x = y // 10
	x = x + 48
	outnibble1 = $C0 + numberposition
	rs = lcdinst
	gosub lcdout	
	outnibble1 = x
	rs = lcddata
	gosub lcdout
	y = y / 10
	
	'--- tens ---
	x = y // 10
	x = x + 48
	outnibble1 = $C0 + numberposition - 1
	rs = lcdinst
	gosub lcdout	
	outnibble1 = x
	rs = lcddata
	gosub lcdout
	y = y / 10
	
	return
	
'**** LCD Out *****
lcdout:
	outnibble2 = outnibble1
	outnibble1 = outnibble1 / 16
	pins = outnibble1 & $0F|rs	'outbyte + latch high + data/inst
	low latchout		
	pause 16				'delay to enable LCD t execute command
			
	pins = outnibble2 & $0F|rs	'outbyte + latch high + data/inst
	low latchout		
	pause 16				'delay to enable LCD t execute command
	
	return
	
'**** Move LCD to Line 1 ****
line1:
	outnibble1 = $80
	gosub lcdout
	return

'**** Move LCD to Line 2 ****
line2:
	outnibble1 = $C0
	gosub lcdout
	return
Will supply schematic when I have it drawn on something other than paper.
 

Attachments

Last edited:

alpacaman

Member
One thing I'd suggest is to disconnect the LCD and run a simple test program; a simple loop which reads pins and sends them back to the PC via SERTXD. Does that exhibit the same problem or does that work ... ?

Code:
Do
  SerTxd( "Pin? = ",#pin?,CR,LF )
  Pause 500
Loop
Then re-connect the LCD and test again.

Hippy - I tried your suggestion on all the inputs. They all worked as expected - even after I re-cycled the power.

I sent my program and schematic on previous reply.
 

BeanieBots

Moderator
Are you sure it's the PICAXE not responding to the push buttons rather than the display not responding.
I've had similar issues with the AXE033.
If your circuit has some capacitance on the power rail, when power is removed some residual voltage remains for quite a long time. This can easily be enough to keep the display in a "confused" state.

Try power down, short out the power rail for brief moment, then re-power.
If that does fix the problem, then one option is to power the display from a PICAXE O/P.
Might also be worth putting a short pause at the start of your program to give the display time to power up before talking to it.
 

westaust55

Moderator
I'm aware that manual 3 shows a resistor in series with the +5 and the input pin. However, I have it wired as shown on the very next page, page 26. I think the reason for the resistor is when the push button is on a pin which could be either an input or an output it protects the picaxe should the pin be configured as an output and the push button is pushed. Without the resistor you would effectively be shorting the +5 to ground (thru the picaxe).
I concur with Hippy.

The PICAXE inputs are rated to operate with a voltage up to Vdd.
The absolute max voltage (that should not be used) is 0.3V above Vdd.

In additional to providing some protection against ESD, a resistor in series with the switch will reduce the current in to/out of the input. This can help reduce the total PICAXE current at the Vdd and Vss pins for those seeking to minimise current draw.

But at the end of the day, the series resistors are not essential/mandatory. The circuit on manual 3 page 26 is valid.
 

alpacaman

Member
Thanks for all your suggestions.

hippy - thanks for suggesting the SerTxd. I had never used it before, but I certainly will in the future. I can see how handy it can be in troubleshooting hardware problems.

Since my last post I inserted the SerTxd command right after I read the inputs into the variable - to see what was in the variable. What was being displayed wasn't readable. However, when I recycled power everything still worked - even with the serial cable un-plugged. Inserting the SerTxd command was the only change I made. When I took the command out again it once again stopped working after I recyscled power. I repeated the proccess with the same results. I tried a new chip with the same results. I thought that the command might just be adding a small pause between steps that the chip needed. So I replaced the SerTxd command with a pause command. Didn't work.

I finally stopped trying to load the pins into the variable and read them directly in my If statements - THAT DID IT! IT WORKS!

I hate it when people automatically blame the PICAXE when the chances are extremely high that it's a problem with either the software or hardware. However, this is starting to look like the PICAXE's fault. The program ran great in simulation and the hardware hasn't changed.
 

hippy

Technical Support
Staff member
I finally stopped trying to load the pins into the variable and read them directly in my If statements - THAT DID IT! IT WORKS!
Not sure why the pins were not readable with SerTxd but I can see a potential problem with your code which might be the case here ...

readinput = pins
if readinput = 1 or readinput = 2 or readinput = 65 or readinput = 66 then

When reading pins it could be that some bits are being set which you are not expecting so maybe try with the first line as ...

readinput = pins & %11000111

You may need to change the mask to just the pins you are using for buttons ( %01000011 for the first IF test ). It's also a good idea to use binary or hex numbers rather than decimal because it's then easier to tell which pins you are checking for, %01000001 or $41 rather than 65.
 

alpacaman

Member
When reading pins it could be that some bits are being set which you are not expecting so maybe try with the first line as ...

readinput = pins & %11000111
I haven't tried it yet but that certainly makes sense. I speculate that all 8 bits of the variable are set to 0 during programming - which is why it works. But after I recycle power who knows what the bits are set at. Since the 18x only has 5 inputs I'm only setting 5 of the 8 bits in the variable when I read the pins. Setting the variable to 0 at the beginning of the program might also do the trick. But, I think using the mask would be a more reliable solution. Wouldn't hurt to do both. I believe the simulator sets all the bits of the variables to 0 at start up which would explain why the program worked in simulation. Maybe the simulator needs to set the variables to a random value at start up for a more accurate simulation.

Anyway, I'm going to try it and I'm sure it will work. I learned something which is always a goal.

Thanks for your help.
 
Top