Program does not run as simulated

d.johnstone

New Member
Hi

I have recently purchased a PICAXE 20M2 microcontroller and programming board from the PICAXE online shop. I have written a simple program using the free software available for download on the website (PICAXE Editor 6) and it appears to run perfectly in the simulation. However, after programming the microcontroller and placing it onto my breadboard, the program does not run as expected.

The program itself simulates correctly in the following manner:
- The outputs C.3, C.4 and B.7 are made high for 2 seconds before being returned to the low state
- Output C.3 is made high again
- A PICAXE keypad (SEN040) is then scanned as per the flowchart provided here.
- Once a key is pressed, the output C.4 is pulsed high and low an equal number of times to the key that was pressed (i.e. if 2 was pressed, the output pulses twice)
- The program ends

However, when actually using the chip with LEDs at the outputs, they turn on for two seconds as expected, but soon after turning off, they turn back on for a further two seconds. This then just keeps looping.

Please find attached the flowchart file made in the programming editor for reference. I have tried two different chips, only to get the same result.


Any ideas would be much appreciated

Thanks in advance
 

Attachments

steliosm

Senior Member
Hello.
Just a quick question: Have you placed a 10k resistor between Programming SerIn pin and the ground?
 

AllyCat

Senior Member
Hi,

Welcome to the forum. Discrepancies between simulation and real hardware are often due to problems or omissions in the construction of the hardware. It sounds as if your PICaxe may be spontaneously resetting.

A test to see if this is happening is to put a #terminal 4800 at the top of the program and on a subsequent line (i.e. before any main: loop) sertxd(cr,lf,"Starting"). This should print to the screen only once when the program is run (after programming or applying power).

If it prints more than once, look for a physical cause such as: A missing pull-down resistor (10k) on the programming input pin, missing decoupling capacitor accross the power supply pins (Legs 1 and 20), a "weak" battery, current overload due to low or no resistance in series with a LED, short-circuits due to incorrect wiring or solder bridges or splashes between tracks, etc..

Cheers, Alan.
 

hippy

Technical Support
Staff member
Simulation runs at a slower speed than real execution in a physical chip so things which appear to be happening in simulation may be happening too fast to be seen when run on a real chip.

This can be the case for flashing LEDs when the LED is turned on, there is a pause or wait, the LED is turned off, and there is a jump to the code which turns the LED on again. There also needs to be a pause or wait after the LED is turned off.

This is the case for your main -

Repeat varA
High C.1
Wait 1
Low C.1
Loop

Sequence in your main program and there is similar in your 'Welcome' routine.
 
Top