Program problem on Picaxe20M2

kenmac

Member
Hi folks,
I haven't been on this forum for awhile.
I have been trying to use a 20M2 to drive a 7 segment display.
To test it out I used the following program:

Code:
'test_7segment_2.bas
'This program tests the control of a 7 segment display using a Picaxe20M2
'
'Connections:
'c.0 ..... 10K to Segment  a
'c.1 ..... 10K to Segment  b
'c.2 ..... 10K to Segment  c
'c.3 ..... 10K to Segment  d
'c.4 ..... 10K to Segment  e
'c.5 ..... 10K to Segment  f
'c.7 ..... 10K to Segment  g
'
'    dirsc = %10111111
start:
    gosub clearall
    gosub units_one        'display "1"
    pause 1000
    gosub clearall
    gosub units_two        'display "2"
    pause 1000
    gosub clearall
    gosub units_three    'display "3"
    pause 1000
    gosub clearall
    gosub units_four    'display "4"
    pause 1000
    gosub clearall
    gosub units_five        'display "5"
    pause 1000
    gosub clearall
    gosub units_six        'display "6"
    pause 1000
    gosub clearall
    gosub units_seven    'display "7"
    pause 1000
    gosub clearall
    gosub units_eight    'display "8"        
    pause 1000
    gosub clearall
    gosub units_nine    'display "9"
    pause 1000
    gosub clearall
    gosub units_zero    'display "0"
    pause 1000
    goto start
'
end

' ##################### Subroutines #################################
'
clearall:
    low c.0
    low c.1
    low c.2
    low c.3
    low c.4
    low c.5
    low c.7
    return
'
units_one:
    high c.1
    high c.2
    return
'
units_two:
    high c.0
    high c.1
    high c.3
    high c.4
    high c.7
    return
'
units_three:
    high c.0
    high c.1
    high c.2
    high c.3
    high c.7
    return
'
units_four:
    high c.1
    high c.2
    high c.5
    high c.7
    return
'
units_five:
    high c.0
    high c.2
    high c.3
    high c.5
    high c.7
    return
'
units_six:
    high c.0
    high c.2
    high c.3
    high c.4
    high c.5
    high c.7
    return
'
units_seven:
    high c.0
    high c.1
    high c.2
    return
'
units_eight:
    high c.0
    high c.1
    high c.2
    high c.3
    high c.4
    high c.5
    high c.7
    return
'
units_nine:
    high c.0
    high c.1
    high c.2
    high c.5
    high c.7
    return
'
units_zero:
    high c.0
    high c.1
    high c.2
    high c.3
    high c.4
    high c.5
    return
'

It is a simple step by step displaying of the numbers 1 to 0.
Unfortunately it doesn't seem to follow the script.
It starts off OK, displaying "1" then "2" but then jumps back to the start to repeat those two digits.
The syntax checks OK, I'm not sure if I have run into a restriction of some sort with the 20M2 chip.
I have tried different 20M2 chips, same result.
I even tried reloading the Editor, in case it had developed a "bug".
Also, using the "Port B" it works OK - just seems to be associated with Port C.
The "experts" on the forum will probably spot the cause but I cannot work it out at the moment.
I am open to any helpful suggestions.

kenmac
 
Last edited by a moderator:

premelec

Senior Member
perhaps check each segment and see if they all seem to work as expected on C - you have skipped C.6 which is an input so that's appropriate but why it works on B and not C is odd... perhaps report Chip version you have got - maybe there was a glitch. So I'd suggest a simple one segment at a time test to start... these things are frustrating! Make sure one segment isn't just shorting something and causing reset... bypass caps? good luck!
 

inglewoodpete

Senior Member
You haven't mentioned your hardware arrangement. Since the code appears to be straightforward, the problem is probably in your wiring of the circuit.

For instance, what are you using to power the circuit? Do you have the 10k + 22k 'programming' resistors in place at all times? Have you placed a capacitor between the power pins of the PICAXE?
 

kenmac

Member
Re the hardware:
I'm using a USB programming cable and the chip is connected correctly.
The Editor is version 5.4.3.
It appears to program normally, no errors.
The 5V source is a regulated P/S.
The displays are OK - they were tested OK using Port B.

kenmac
 

inglewoodpete

Senior Member
The editor/compiler that you're using dates back to 2011. Your 20M2 may need a later version. What version is the firmware in the chip?

Forgive me asking again: Have you placed a capacitor between the power pins of the PICAXE?
 

techElder

Well-known member
kenmac, if I may offer a suggestion. Your program rightly clears all the segments between displaying a character (and obviously is just a part of a project).

There are many ways to show characters on an LED. You have chosen one way.

I would suggest that you handle "clearing" of segments within the routine that shows the segment. There will be the time when you want to show that character in sequence with another without having to go through a "clearall" routine.

In other words, handle all segments of a character and those segments that are off for that character from within the character routine.

That way it doesn't matter what sequence you call each character routine.

I agree with IWP, you probably have mis-wired the display to your 20M2 pins.

Here's how I mapped out the display segments from your program:

....... C.0

C.5 |......| C.1

....... C.7

C.4 |......| C.2

.......___
.......C.3
 

kenmac

Member
Inglewoodpete,
Yes, there is a standard decoupler capacitor (0-1u) across the power pins.
If that was a problem I would expect more random effects.
I have used the 20M2 before with no problems.
I'll download the latest Editor version and see if that makes a difference.

kenmac
 

Bill.b

Senior Member
If you are using 10K resistors as current limits for each segment, this value is to high.

use 330ohm resistors instead of the 10K.

Bill
 

Goeytex

Senior Member
Use a systematic approach to troubleshooting.


1) Is the Picaxe resetting?
Place a line at the beginning of the program
sertxd ("Starting Program",cr,lf)
Do you see this when it starts over from "2" ?
If so then the Picaxe is resetting. Why?

2) Place sertxd at strategic locations in code to see if code has executed.
Are all sertxd messages displayed ?

3) Remark out "Gosub units_three"
Does it display a 4 ? '

4) Remark out "Gosub units_four". What happens?
So forth and so on.

5) Remark out all other sections and only display an "8"
What happens?

6) Instead of doing the entire program at once, do it in small sections. Get one section working then add the next.

Troubleshooting is mostly an exercise in Logic and reason, use your critical thinking skills to find the problem.

Sample Code:

Code:
'test_7segment_2.bas
'This program tests the control of a 7 segment display using a Picaxe20M2
'
'Connections:
'c.0 ..... 10K to Segment  a
'c.1 ..... 10K to Segment  b
'c.2 ..... 10K to Segment  c
'c.3 ..... 10K to Segment  d
'c.4 ..... 10K to Segment  e
'c.5 ..... 10K to Segment  f
'c.7 ..... 10K to Segment  g
'
'    dirsc = %10111111

Pause 1000
Sertxd ("Starting Program",cr,lf)  'for debugging


start:
    gosub clearall
    gosub units_one        'display "1"
    pause 1000
    gosub clearall
    gosub units_two        'display "2"
    pause 1000
    gosub clearall
    gosub units_three    'display "3"
    pause 1000
    gosub clearall
    gosub units_four    'display "4"
    pause 1000
    gosub clearall
    gosub units_five        'display "5"
    pause 1000
    gosub clearall
    gosub units_six        'display "6"
    pause 1000
    gosub clearall
    gosub units_seven    'display "7"
    pause 1000
    gosub clearall
    gosub units_eight    'display "8"        
    pause 1000
    gosub clearall
    gosub units_nine    'display "9"
    pause 1000
    gosub clearall
    gosub units_zero    'display "0"
    pause 1000
    goto start
'
end

' ##################### Subroutines #################################
'
clearall:
    sertxd ("Clear",cr,lf)   'for debugging
    low c.0
    low c.1
    low c.2
    low c.3
    low c.4
    low c.5
    low c.7
    return
'
units_one:
    sertxd ("1",cr,lf)  'for debugging
    high c.1
    high c.2
    return
'
units_two:
    sertxd ("2",cr,lf) 'for debugging
    high c.0
    high c.1
    high c.3
    high c.4
    high c.7
    return
'
units_three:
    sertxd ("3",cr,lf) 'for debugging
    high c.0
    high c.1
    high c.2
    high c.3
    high c.7
    return
'
units_four:
    sertxd ("4",cr,lf)  'for debugging
    high c.1
    high c.2
    high c.5
    high c.7
    return
'
units_five:
    sertxd ("5",cr,lf) 'for debugging
    high c.0
    high c.2
    high c.3
    high c.5
    high c.7
    return
'
units_six:
    sertxd ("6",cr,lf)  'for debugging
    high c.0
    high c.2
    high c.3
    high c.4
    high c.5
    high c.7
    return
'
units_seven:
    sertxd ("7",cr,lf) 'for debugging
    high c.0
    high c.1
    high c.2
    return
'
units_eight:
    sertxd ("8",cr,lf)  'for debugging
    high c.0
    high c.1
    high c.2
    high c.3
    high c.4
    high c.5
    high c.7
    return
'
units_nine:
    sertxd ("9",cr,lf) 'for debugging
    high c.0
    high c.1
    high c.2
    high c.5
    high c.7
    return
'
units_zero:
    sertxd ("0",cr,lf) 'for debugging 	
    high c.0
    high c.1
    high c.2
    high c.3
    high c.4
    high c.5
    return
 

hippy

Technical Support
Staff member
C.7 bridged to SERIN my guess :)
Sounds plausible ... were it not for it working for "1" and "2" and only failing on "3" which doesn't use any lines not already used before then. It's a bit of a mystery if legs are shorted somewhere.
 

kenmac

Member
I did some further testing.
I tried starting the program at different points in the list and this is what happened:
Start at one ......... displays 1,2,1,2,,etc
two ........ displays 2,2,2,2, etc
three ........ displays 3,3,3,3, etc
four .......... displays 4,4,4,4,etc
five .......... displays 5,5,5,5, etc
six .......... displays 6,6,6,6, etc
seven ......... displays 7,8,7,8,etc
eight .......... displays 8,8,8,8,etc
nine .......... displays 9,9,9,9,etc

It seems that the program is resetting after one or two numbers are called.
It does the same when working from batteries.
I terminated the unused C.6 input, but no effect.
When I have time, I'll download and install the laterest version of the editor, and try that.
Also, I may try my laptop to see if works better.

kenmac
 

erco

Senior Member
The editor/compiler that you're using dates back to 2011. Your 20M2 may need a later version. What version is the firmware in the chip?
Surely you jest, 2011 isn't all that long ago. Is there actually an M2 firmware revision which is not backward compatible with PE5?

I'm betting kenmac pulled out old hardware for this project anyway. Most likely a power or wiring problem. kenmac, do you also have a 10uF or so electrolytic filter cap in parallel with your 0.1 uF decoupling cap?
 

erco

Senior Member
kenmac: Is there a chance that your 20M2 is damaged? You did say that everything worked fine on port B. If your setup is on a breadboard and easily rewired, start by moving everything back to port B to verify function. Then change LED segment A from B.0 to C.0 (modifying hardware and software to match) and retest. Then change LED segment B from B.1 to C.1 and retest, etc. You'll find something along the way.
 

premelec

Senior Member
@kenmac - I have had occasional situations in the past with characters that don't show on the editor screen... I just had to re-type stuff to get it to work and never did find out how the oddities got in the basic listings... I suggest turning on only one segment at a time and seeing if all of them work correctly - you have an odd situation - I'm looking forward to knowing what the solution is!
 

Technical

Technical Support
Staff member
You mentioned a 5V regulated source - is the regulator on the PCB itself? It looks like the power supply is collapsing upon load, hence causing a reset.
 

Goeytex

Senior Member
It appears to reset when more than two segments are turned on at the same time. This suggest a power supply/wiring problem. I would confirm that by modifying the code so that for "2" to "9" only two segments are turned on, but make them different segment pairs.

Temporarily Add "disablebod" as the first line before the main loop. Does the behavior change?

Load the program below and measure the voltage directly across Picaxe Pins (legs) 1 & 20. What is the voltage?

(You will need to do a "hard reset" after loading this code)


Code:
#Picaxe 20M2

Disablebod
Disconnect
DirsC  = %10111111
PinsC  = %10111111

Do
Loop
 

erco

Senior Member
kenmac: Please post a photo of your exact setup. What type of LED display is this that works with a 10K resistor (per bill in post #8)? At most, that's half a milliamp flowing, not enough to light up an LED directly. Seems like this must be module with driver transistors and support circuitry. That may or may not be the problem, but it would still be helpful to know what we're dealing with.

Great thread, lots of people helping, everyone loves a good mystery. kenmac, if you can add a bit of conspiracy and a bomb with a countdown timer, we can make a movie out of it.

After this problem gets solved, we all need to pitch in and help this poor bloke, who has even more serious wiring issues: https://www.youtube.com/watch?v=lw9MGa7iQq4
 

kenmac

Member
It seems that the reset is ocurring after all digits except one and seven.
These two use the least segments - driving three or more segments causes a reset.
The 7 segment displays I'm using are just standard 0.5" type obtained from Altronics (Cat. Z0190).

They actually do display when driven thru 10K but are much brighter with 1K.
I thought that maybe the low load may be the cause, but increasing it using 1K didn't have any effect, except to brighten up.
I tried an electro capacitor across the power pins, to no effect - I had previously tried batteries for same result.

The Firmware version for the 20M2 is 8A.

I tried the Port B again - it still works OK.

It seems that the answer may be in the way Port C outputs work - I don't know enough about that.

kenmac
 

erco

Senior Member
I tried the Port B again - it still works OK.
That's good news. Is this a new chip or one which may have been previously damaged? Try moving one segment at a time from b.0 to c.0 and test, then b.1 to c.1 and test, etc until you can isolate the problem.
 

premelec

Senior Member
very strange - perhaps a closeup picture of your board could reveal something - it's not the usual behavior...
 

kenmac

Member
I tried something different - the 20M2 was setup on a breadboard with LED's on all Port C pins.
Then I programmed it to sequentially light up the LED's until all were lit.
The result was exactl;y as you would expect and no sign of any resetting action.
So, it is pointing to some effect from the display.
I tried another display (same type) and the chip behaves the same.
I think I'll have a closer look on the pins with a CRO and see if I can spot something

kenmac
 

premelec

Senior Member
With resistors to the segments that's _really_ odd- you'd think the worst load that could happen to the PICAXE would be the resistor value...
 

Technical

Technical Support
Staff member
The 10k/22k resistors on serrxd are really wired correctly?... noise on the serial programming pin is more likely to come from C.7 then any other pin (if serrxd is not correctly wired).

It seems that the reset is ocurring after all digits except one and seven.
These two use the least segments - driving three or more segments causes a reset.
one and seven don't use C.7 - all the others do...
 
Last edited:

premelec

Senior Member
I suspect you may have cleared a fault I suggested in Post#10 and Tech has surmised in #24 - If your SERIN pin is not properly connected even small capacitive coupling can cause problems. Anyhow check the LED# segments with a resistor and power supply and when they appear all to work OK reconnect to port C [through resistors] and likely it'll work... :)
 

erco

Senior Member
Sounds like this project is breadboard-mounted. The breadboard might have an internal fault causing an errant connection or cap coupling. kenmac, have you tried swapping breadboards?
 

kenmac

Member
The original setup was as follows:
The chip was plugged into a socket mounted on a small PCB, c/w resisitors for the displays.
The connection to the displays was via a small length of ribbon cable (about 100mm).
The displays were plugged into sockets on another small board.
The whole arrangement was supposed to fit in a small box.
Anyway, I have set it up on one of those quick connect protoboards and it works OK there.
The display steps thru the digits as designed.
So, it points to the original wiring having a problem.
I've been over it with a meter and can't find any thing wrong.
The only difference between the two setups was the use of ribbon cable, so I decided to try stripping the cable to be individual wires.
Unfortunately this had no effect whatsoever - back to square one!
I think I'll rebuild the 20M2 board completely and see if that fixes it.

kenmac
 

inglewoodpete

Senior Member
My question:
...Do you have the 10k + 22k 'programming' resistors in place at all times?...
The reply:
Re the hardware:
I'm using a USB programming cable and the chip is connected correctly....
Technical's question:
The 10k/22k resistors on serrxd are really wired correctly?....
No reply.

kenmac, this problem and thread have been running for a while now. A lot of experienced people are trying to help. The symptoms you are describing are so similar to those that you would get if the 10k + 22k resistors on the SerIn pin were missing or open circuit.

Please confirm that you have the 22k + 10k resistors on the programming (SerIn) pin at all times. That means: during programming and at all times while you are running the program in the PICAXE.
 

kenmac

Member
The 10/22K resistors are permanently connected.
Also, pin c.6 is terminated with 10K to ground.
As I mentioned in my last post I have proved that the problem is in the wiring , albeit not obvious.
So, I have decided to rebuild the 20M2 board - it shouldn't take long.
I'll report the result when completed.

kenmac
 

kenmac

Member
I completed a rebuild of the 20M2 board - identical to the original.
I completed a rebuild of the 20M2 board - identical to the original.
Success - the new board operates correctly on both Ports.
I didn't find the actual cause, just that it was associated with the wiring.
I'm not interested in doing any more on this, but will now complete the project.
Thanks for all the support in your posts - consider this thread closed.

kenmac
 
Top