Picaxe 08M2 odd behaviour

tobyw

Member
Hi all

I have a simple circuit with an 08m2 flashing 3 LEDs in sequence. It works fine on breadboard, using a small programmer breakout I etched myself (with 22k and 10k resistors plus stereo jack) slotted into the breadboard, with the LEDs connected to the pins on the breakout board.

Then I tried etching a small PCB to transfer the circuit to it.

At this point, the circuit does this...

First LED come on for a few seconds. Then they start to flash in sequence. If I switch off and on, first LED lights for a few seconds and then they flash. Or sometimes mid sequence the first LED will come on for a few seconds and then the sequence kicks in again. Or first LED comes on and stays on indefinitely...

I have tried two copies of the etched board, and they both exhibit this behaviour. I have checked and rechecked every single connection using multimeter and continuity tester. I can't find any shorts or anything else odd.

The only thing I can think of is that maybe it's to do with having the serial in and serial out pins floating on my PCB. Could that be the problem - and if so, how should they be connected on a PCB? Pulled high or low?

Thanks for any help...
 

The bear

Senior Member
Toby,
You will be asked for close-up photo's of your PCB. Plus the program you are using.

Regards, Bear..
 

tobyw

Member
Toby,
You will be asked for close-up photo's of your PCB. Plus the program you are using.

Regards, Bear..
Soldering a resistor between serial in and ground removed the problem of it 'hanging' on the first LED...but it's still rather buggy. Here are some pictures to show what I did..

Without resistor...marked for emergency drill points... forgive the messy solder everywhere...I unsoldered and resoldered almost every part trying to diagnose the problem..
IMG_3607.JPG

After adding a resistor between serial in and ground..
IMG_3608.JPG

The unfortunate side effect of fixing it is that it's not as sensitive as the other copy of the same board without a pull low resistor, which is intermittent, but does at least work sometimes, and only take a tiny vibration to trigger it. I don't think the tilt sensor is really suitable as a 'vibration' sensor, but when there is no pull low resistor, it seems like it makes the chip unstable and therefore it appears to be responding to vibration, when it's probably being triggered by a momentary change in voltage elsewhere, perhaps.

Or it could just be my code.. here is my program if you don't mind reviewing...


Code:
symbol last = b0 	' the last state of the trigger pin
symbol plen = b1	' pause length
symbol counter = b2   ' for loops
symbol type = b3
symbol rl = 4	    ' red pin
symbol gl = 1	' green pin
symbol bl = 2	  ' blue pin

last = pin3

main:
	if pin3 != last then
	    goto show
	    last = pin3
	endif
	pause 50
	goto main
	
show:
	if type = 0 then
		type = 1
		gosub flash
	else
		type = 0
		gosub strobe
	endif
	pause 500
	goto main
	
strobe:
	for counter = 1 to 10
		gosub blue
		gosub redgreen
		gosub red
		gosub greenblue
		gosub green
		gosub redblue
		gosub lightall
	next counter
	return
	
flash:
	plen = 20
	do while plen < 50
		gosub red
		gosub green
		gosub blue
		plen = plen + 1
	loop
	return
	
red:
	high rl
	pause plen
	goto golow
	
green:
	high gl
	pause plen
	goto golow
	
blue:
	high bl
	pause plen
	goto golow
	
redgreen:
	high rl
	high gl
	pause plen
	goto golow
	
redblue:
	high rl
	high bl
	pause plen
	goto golow

greenblue:
	high gl
	high bl
	pause plen
	goto golow
	
lightall:
	high rl
	high gl
	high bl
	pause plen
	goto golow
			
golow:
	low rl
	low gl
	low bl
	pause plen
	return
I think it must be buggy, because occasionally the light sequence will be retriggered continuously without movement, until you move it again.
 

westaust55

Moderator
at a glance, the programme looks okay.

If the sequence keeps restarting that can indicate the pull-down resistor on the Serial in pin has a dry joint giving poor contact.
If the SerialIn pin is floating (no resistor or bad contact) then every time the pin voltage goes to a high state the PICAXE firmware thinks a new programme download it going to occur and will in effect restart.

Check there is no solder bridge from SerialIn (physical pin/leg 2) to the supply on IC pin/leg 1 or to the red led pin on IC pin/leg 3.
Again such a bridge may be a dry joint and thus intermittent.

A schematic diagram may be helpful as well as a photo of the component side of your board.

How and where is the tilt/vibration switch mounted and connected?
Do you have a pull-down or pull-up resistor for that input circuit as well.
See PICAXE manual 3 for input switch connections.
 

rq3

Senior Member
Hi all

I have a simple circuit with an 08m2 flashing 3 LEDs in sequence. It works fine on breadboard, using a small programmer breakout I etched myself (with 22k and 10k resistors plus stereo jack) slotted into the breadboard, with the LEDs connected to the pins on the breakout board.

Then I tried etching a small PCB to transfer the circuit to it.

At this point, the circuit does this...

First LED come on for a few seconds. Then they start to flash in sequence. If I switch off and on, first LED lights for a few seconds and then they flash. Or sometimes mid sequence the first LED will come on for a few seconds and then the sequence kicks in again. Or first LED comes on and stays on indefinitely...

I have tried two copies of the etched board, and they both exhibit this behaviour. I have checked and rechecked every single connection using multimeter and continuity tester. I can't find any shorts or anything else odd.

The only thing I can think of is that maybe it's to do with having the serial in and serial out pins floating on my PCB. Could that be the problem - and if so, how should they be connected on a PCB? Pulled high or low?

Thanks for any help...
And make very VERY sure your LEDs are soldered in the right way (anode/cathode).
 

Jeremy Harris

Senior Member
Looking at the PCB it's hard to tell, but is there a decoupling capacitor close to the Picaxe power pins? I always put a 0.1µF capacitor as close as possible to the chip, usually right at the end where the power pins are, having been caught out more than once by supply noise causing unintended consequences.
 

The bear

Senior Member
Hi Toby,
Nice pictures & program.
I'm too much of a beginner to fully appreciate your program.
Regards, Bear..
 

tobyw

Member
How does 'last' ever get set....?

I think this is the flaw in my program.

Naively, I thought that
Code:
last = pin3
would set the value of last to be either 1 or 0 depending on the state of the pin - but is that how it works? If not, then you are right that it never gets set.

What I was trying to do was to detect any time the state of the tilt sensor changes. So if you tilt it, then it will trigger and then not re-trigger until you move it back again.

Is that possible, and if so, what is the correct way to tell the Pickaxe to do this?

Thanks for your help
 

Technical

Technical Support
Staff member
Not quite what we tried to point you at, the line would do what you expect it to do if it was ever processed. Look again at the code and the line directly above it - where does the program flow go and does that line therefore ever get processed at all?
 

tobyw

Member
Not quite what we tried to point you at, the line would do what you expect it to do if it was ever processed. Look again at the code and the line directly above it - where does the program flow go and does that line therefore ever get processed at all?
Hi Technical -thanks. I spotted that after I posted. show: goes back to main so those lines are never processed.

So it IS ok to do last = pin3? I wasn't sure if it allowed that.

I changed the goto to a go sub, and now last is getting populated, and I can get this working fine on breadboard, but even with the serial in resistor, the PCB version won't respond to anything. I don't know if the tilt switch on the PCB is just faulty, or I am doing something stupid.

I checked the lights are ok by programming the chip to just run the flash sequence, and that works fine on the PCB.

Then I reprogrammed to go red if pin3 is high, and green if pin3 is low, as a simple test. On the breadboard, this works, on the PCB it stays red all the time, however I tilt the switch. So I think the problem is with the tilt part.

pin3 is tied high via a 4k7 resistor, and the tilt switch is connected between pin3 and ground. I think this should mean pin3 is either high or low, depending on the position of the tilt switch, but although that's true on the breadboard, on the PCB it always seems to be high. I have rechecked every connection. Is there something about being on the PCB which would change the behaviour?

Here is the PCB layout and circuit

board.png

Thanks for your patience...it would be great to get this off the breadboard and too the PCB.
 

westaust55

Moderator
What happens on the PCB if you use a wire and bypass the tilt switch to take/force pin3 low:
(a) at the tilt switch connections on the, and
(b) at the PICAXE pin (at PCB connection and on the IC leg proper.

If (a) works then (b) should also work.
If (b) works but (a) does not then check the tilt switch connections (particularly as/if it works properly when on a breadboard - open circuit/dry solder joint, tilt switch intermittent
If neither (a) nor (b) work then measure the voltage at the PICAXE pin3 actual leg with and without the wire jumper/bridge. If voltage changes at the actual IC leg then try another PICAXE chip.
 

tobyw

Member
What happens on the PCB if you use a wire and bypass the tilt switch to take/force pin3 low:
(a) at the tilt switch connections on the, and
(b) at the PICAXE pin (at PCB connection and on the IC leg proper.

If (a) works then (b) should also work.
If (b) works but (a) does not then check the tilt switch connections (particularly as/if it works properly when on a breadboard - open circuit/dry solder joint, tilt switch intermittent
If neither (a) nor (b) work then measure the voltage at the PICAXE pin3 actual leg with and without the wire jumper/bridge. If voltage changes at the actual IC leg then try another PICAXE chip.
Hi WestAust - both approaches work fine. So I guess that means it is a malfunction in the tilt sensor? I wouldn't be that surprised, it's been soldered and desoldered so many times. I thought it would be pretty robust though, being purely mechanical..

I think I will revise the circuit board design to incorporate pulldown resistor on pin2 and re-etch this weekend.

Do I really need a cap across the power supply? I'm powering this with 3 small AG13 1.5V cells. Will the lack of a cap cause problems even when the batteries are fresh? Every component makes the circuit harder to route onto a small footprint, so if it would just mean it gets flakey when the batteries are low, that would be ok - otherwise I will just have to make it a bit bigger to fit in the resistor and cap.

Thanks
 

westaust55

Moderator
A 100 nF uF capacitor across the power terminals of the IC is highly recommended for decoupling.
Switching within the IC as internal and IO levels change state causes spikes/dips which the capacitor will help to filter out.
 
Last edited:

tobyw

Member
100nF. Also the PCB shows the serin leg (leg 2) floating/unconnected. This is never allowed and will not work reliably. See the minimum operating circuit.

http://www.picaxe.com/What-is-PICAXE/PICAXE-Pinouts/
I'm confused about the minimum operating circuit. The documentation here shows the minimum operating circuit as basically the same as the programming connection,with a 10k resistor to ground and a 22k resistor to what amounts to a floating pin, with the instruction that both resistors must be included. So what is the 22k resistor doing, if you are not actually connecting the pickaxe to your USB port?

Also, it's unclear what should be happening with the serial out leg. Can this be left floating (as it basically is in the schematic)?
 

neiltechspec

Senior Member
Like has already been said, the serial in pin MUST be grounded (via a resistor - 10k will do).

Serial out doesn't matter and can be left open cct.

Look back to the third post in this thread !!.

The decoupling capacitor is essential and in my opinion is a serious omission in the documentation by Rev Ed.

Neil.
 

westaust55

Moderator
I'm confused about the minimum operating circuit. The documentation here shows the minimum operating circuit as basically the same as the programming connection,with a 10k resistor to ground and a 22k resistor to what amounts to a floating pin, with the instruction that both resistors must be included. So what is the 22k resistor doing, if you are not actually connecting the pickaxe to your USB port?

Also, it's unclear what should be happening with the serial out leg. Can this be left floating (as it basically is in the schematic)?
Refer to my description in post 6 as to why the SerialIn pin must be kept in a low state - at least until a DISCONNECT programme statement is performed.
As already mentioned by others no requirement exists for the SerialOut which for M2 parts can be used as an output for digital or DAC functions.

With respect to the SerialIn pin, as long as it is kept low the BASIC program will work.
The standard circuit with two resistors as per the manual should be installed if there is a likelihood that you will want to reprogram the PICAXE chip in-situ.
If not then using just a pull-down resistor (say 10k Ohm) or even directly tied to 0 V / ground supply rail will work.
For the few cases where I have not included the full programming circuit (usually through extremely tight space constraints) I have used a 100 k Ohm pull down resistor.
That value is high enough that it will not impact on the addition of the two resistor programming circuit by using say an AXE029 interface should the need arise at some future time
 

rq3

Senior Member
I'm confused about the minimum operating circuit. The documentation here shows the minimum operating circuit as basically the same as the programming connection,with a 10k resistor to ground and a 22k resistor to what amounts to a floating pin, with the instruction that both resistors must be included. So what is the 22k resistor doing, if you are not actually connecting the pickaxe to your USB port?

Also, it's unclear what should be happening with the serial out leg. Can this be left floating (as it basically is in the schematic)?
Tobyw, if you are very sure that you will NEVER, EVER cross your heart and hope to die connect your picaxe to a serial port, the 22K resistor is not needed. It is a current limiting resistor that somewhat ensures that the internal picaxe protection diodes will clip the serial input level to something that the picaxe can handle.

The 10K resistor pulls the serial input pin of the picaxe to ground. Without this resistor, the pin floats somewhere between logic HIGH and logic LOW. The picaxe then expects, on a random basis, a new download from you. The resistor prevents this from happening, as it firmly tells the picaxe that its serial input is at ground. During a download of a new program, your computer sends a HIGH pulse to the picaxe that over-rides the 10K pulldown, telling the picaxe to expect to receive some incoming data (the new program).

In short, the two resistors serve two independant functions, and really have nothing to do with each other. The 22K is protection, the 10K is a required logic pull-down. You could safely solder the serial input pin to ground, but you'd never again be able to program the picaxe.

The serial output is just that. An output, and (usually) nothing else. Placing a resistor in series just prevents it from being shorted should you ground that line on your circuit, potentially asking the serial output pin to source more current than it can, and destroying it.

Let me go out on a limb here, and state that ALL active integrated circuits MUST have decoupling capacitors located as close as possible to the chip itself. This isn't really true, but only someone with a great deal of experience can reliably decide when it is OK to violate this "rule". As a rule of thumb, a 10uF tantalum, 0.1uF ceramic, and a 0.001uF ceramic capacitor should be considered minimums.

As an example, I recently built a picaxe temperature controller for my refrigerator/freezer (because the manufacturer wanted $800 for the equivalent parts). The circuit board uses a 20M2 to read the temperature from 3 sensors, and switches 2 solid state relays controlling the compressors and heaters. The circuit board is double sided, with the under side being a continous ground plane with plated through holes. The picaxe has a 10 uF tantalum capacitor, a 0.1 uF ceramic cap. and a 0.001 ceramic cap. All are surface mounted within 0.25 inch of the chip. The temperature sensors each have 0.1 uF ceramic caps placed right at the launch point for the 1 meter leads (twisted 28 gauge wire) for the temperature sensors.

It all works very well, except that I have to plug my laptop into my refrigerator now to set the temperature. Which is kind of cool (ahem, sorry). The point is that a very small printed circuit board is controlling pretty respectable power (over 5 amps at 120 VAC) in fairly drastic environmental conditions (the board is inside the fridge).

The take-away is that there is established "art" (really science) behind circuit layout and design. There are cases where you can have too much by-pass capacitance, but they are rare. With good design and experience, you'll need less than you think, but you'll NEVER need none.
 

BESQUEUT

Senior Member
at a glance, the programme looks okay.
Huuummmm...
This is probably not the problem, but mixing GOTO and GOSUB statements is a good way to overflow the RETURN stack...
that make unpredictables results...
So, my humble advice :
1) make sure the circuit is OK, (as per #3)
2) suppress all GOTO statements.
 
Last edited:

tobyw

Member
The standard circuit with two resistors as per the manual should be installed if there is a likelihood that you will want to reprogram the PICAXE chip in-situ.
That was what was confusing. To me, that is not a minimum operating requirement, as the manual implies. It's a requirement for programming. So the bottom line seems to be

1. Mandatory 10k resistor to pull the serin pin low, otherwise chip will reset itself constantly.
2. Recommended 100nF capacitor across supply pin for stability
3. Pin 7 can be left floating, but optional serin and seril out connections with additional 22k resistor to serin, if likely to reprogram in situ

Some of my boards already have a jack with 10k/22k resistors, which explains why they work fine. But on some of the more recent boards I don't want to lose the space. What I do is put an IC socket on the PCB. Then it's not a lot of work to build a test circuit with one of my home-brew breakout boards which also use a socket. Swapping the IC to the breakout to program it and then swapping it back is very quick and easy - especially if you don't push it firmly all the way in. However, at least I now know that I must have a pulldown resistor as a minimum.

Is it the same with the larger chips that have a dedicated reset pin?
 

hippy

Technical Support
Staff member
I think part of the issue might be over what is considered "operating". The "minimum operating circuit" we include in the 'PICAXE Manual 1 - Getting Started' would be the minimum required and recommended to fully use the PICAXE; programming, running code, and debugging via the download cable.

These circuits are in the "Getting Started" manual aimed at people who will likely not be experienced with PICAXE devices and so target what they would consider operating a PICAXE to be, which would be all of the above. Anything less would invite new users building PICAXE circuits which cannot be programmed and could lead to confusion, frustration and worse.

Perhaps "minimum download circuit" would be better for more advanced users but I suspect that might attract a few questions along the lines of 'what's the circuit to use after downloading?' from more inexperienced users.

100nF power supply decoupling capacitors were added to the circuits we have in Manual 1 and have been there for a few years now. We would always recommend people refer to the latest manuals. Those are included with the latest download of PICAXE Editor 6 or can be found online at -

http://www.picaxe.com/Manuals

For more experienced users, the minimum circuit needed to use a programmed PICAXE can be less if one is prepared to accept the restrictions which come with that, no in situ reprogramming, no interactive debugging through the download cable.

The minimum recommended in those circumstances would be; 10K on Serial In, Serial Out not connected, 100nF across power rails. It is possible to forego the 100nF and connect Serial In direct to 0V if one understands and accepts the potential risk of doing that.

For PICAXE chips with a Reset pin, the minimum recommended there would be to connect Reset to V+ via a 4K7. It may be possible to connect Reset directly to V+ if one wants to take the risks with doing that but I believe even Microchip datasheets recommend against doing so.
 

hippy

Technical Support
Staff member
Swapping the IC to the breakout to program it and then swapping it back is very quick and easy - especially if you don't push it firmly all the way in.
We cannot stop people doing that but we generally recommend against it.

First, it can soon get tedious having to keep swapping chips.

Second, without a programming socket, it makes it harder to debug code, trace execution flow and run diagnostic tests if things are not working.

Moving chips back and forth can lead to wear on the chip legs and DIL socket contacts and there is an increased risk of damage to both. There is also increased risk of inadvertent reverse insertion or misalignment in either the programming or target hardware. And a risk of removal or insertion with power accidentally left on.

Getting chips out of a socket is fairly easy with smaller PICAXE devices but gets more difficult as size goes up which also increases risk of damage to chip and socket. It can take ages and test patience to extricate a chip without damage if it tilts or flips in the process, more time to put legs back in line if they twist.

Not pushing chips fully in may be a solution to that, but risks poor contact and problems arising from those being mistaken as programming errors leading to wasted time trying to figure out what is going on. Intermittent contact is even harder to identify.

One can use turned-pin sockets but that makes it harder to insert chips and remove them. Turned-pin are also more expensive.

So all in, while there will be legitimate cases where minimum circuitry is essential which necessitates that, we would generally recommend against it. We would recommend the full download circuit, even if the jack socket or programming headers are not included on the final boards. If one can avoid making things difficult for oneself that's usually the best path to pursue.

One option if a really minimal circuit is needed is to build a programming board with 'pogo-pins' which is permanently attached to the target board while developing. A single 10K to Serial In can be over-ridden by buffering Serial In and it is then a single unit in development with a minimal circuit for final product.

A poor man's version can be achieved by taking Serial In and Out to header pins or just pads on the board.

Of course, the easiest solution is to develop and prototype on a different board to that which will be the final design ! It is a rare case where that cannot be done.
 
Top