Converting a traffic light into a timer

Thread Starter

Transitory

Joined Jan 2, 2013
64
The PICAXE does everything, the Maxim IC simply drives the 7 segment displays, since there aren't enough pins on the PICAXE to drive them. The Maxim does more than that, but essentially, the PICAXE tells it what to display, and it displays it, the "brain" is all in BASIC code on the PICAXE.
So does the code in the PICAXE say that the digit 8 is defined as all LEDs lit up or does the PICAXE tell the maxim "display 8" and the maxim is already programmed to show the 8 as all leds lit up?
 

thatoneguy

Joined Feb 19, 2009
6,359
So does the code in the PICAXE say that the digit 8 is defined as all LEDs lit up or does the PICAXE tell the maxim "display 8" and the maxim is already programmed to show the 8 as all leds lit up?
The IC (Maxim MAX7221)gets 16 bits of data representing the numbers (which digits, brightness, etc). The logic inside the IC then takes care of multiplexing (only one digit is lit at a time, it displays all the numbers one at a time, but so fast your eye sees it as continually on). The Maxim IC also can control the brightness of the display.

Once the data for what to be displayed has been sent, the MAX7221will continually display the last data it received on the display. This offloads a lot of programming cycles from the PICAXE, as multiplexing (displaying the different digits) is a rather menial task, but takes a lot of cycles and I/O pins to complete. Here is The MAX7221 Datasheet, you should be able to understand some parts. Others get a bit technical.
 
Last edited:

tracecom

Joined Apr 16, 2010
3,944
Thanks for that great explanation TOG. :)

I just finished doing some testing for elec_mech. We are now up to revision I in the code. The buttons are working, the 7 segment displays are working, the traffic light LEDs are working, but we are having some trouble with the timing. Elec_mech is doing a great job with the coding and I have confidence that he will iron it out.
 

thatoneguy

Joined Feb 19, 2009
6,359
If the timing is to be a long period (>15 minutes), it might be overall better to throw in a DS1307 and only use the 1 second pulse out (don't bother setting the time or backup battery). Simpler to code too, if you use it as an interrupt.
 

tracecom

Joined Apr 16, 2010
3,944
If the timing is to be a long period (>15 minutes), it might be overall better to throw in a DS1307 and only use the 1 second pulse out (don't bother setting the time or backup battery). Simpler to code too, if you use it as an interrupt.
I was just wondering about that a few minutes ago, and conveniently, I have my own PCB fabricated for the DS1307.
 

Attachments

Last edited:

elec_mech

Joined Nov 12, 2008
1,500
If the timing is to be a long period (>15 minutes), it might be overall better to throw in a DS1307 and only use the 1 second pulse out (don't bother setting the time or backup battery). Simpler to code too, if you use it as an interrupt.
Excellent recommendation, that might be the key. I'm having a heck of a time trying to get the timing to work. I didn't realize just how much time is taken by a BASIC interpreter vs. compiled code. I'm trying to speed up and shave the total number of lines required to run the timing and it just isn't enough. I have to bit bang the SPI out and I'm currently using the BUTTON command to check the buttons in a subroutine while running a timing loop totaling one second. I'm wondering if I should make the button inputs interrupts instead?

So if the DS1307 was employed, the one second clock would trigger an interrupt and when said interrupt occurred, I'd update the display? Is that correct? It would certainly take care of a lot of problems.
 

thatoneguy

Joined Feb 19, 2009
6,359
So if the DS1307 was employed, the one second clock would trigger an interrupt and when said interrupt occurred, I'd update the display? Is that correct? It would certainly take care of a lot of problems.
Yes. The time would be updated in the interrupt, and probably sent to the display.

The rest of the loop simply looks for button presses, since humans are very slow relative to how fast the controller runs. The time count and such would be in the main loop as well, and the SPI, but only send the SPI when a bit flag is set by the interrupt.

That leaves you about 0.99 seconds for everything else.
 

thatoneguy

Joined Feb 19, 2009
6,359
I added the DS1307 circuit to the breadboard assembly, which, along with some code changes, corrected the timing problem. Elec_mech is finetuning the code. Still having a small problem with button response speed.
Find delay statements and call the key polling routine as part of the delays.
 

Thread Starter

Transitory

Joined Jan 2, 2013
64
It seems as if the DC control circuit for the traffic light is finalized. Attached are two photos of my breadboard: a high resolution and a low resolution version.

It may be the world's most complicated egg timer. :D

Elec_mech has the code working well.
That is so awesome! Any shot at taking a look at the code?
 

Thread Starter

Transitory

Joined Jan 2, 2013
64
I am curious as to what progress you are making on your study of PICAXE programming. You are working on it, right? :)

Have you ordered any PICAXE hardware?
I have the editor and started reading through it. Mostly I want the code because I think it'd be a great textbook. If I can study and decipher what it means, I can learn much better. (Learning via a concrete example)

I haven't ordered the hardware except for the USB cord since you guys said earlier in the thread that I shouldn't yet order. Should I start filling up shopping carts?
 

tracecom

Joined Apr 16, 2010
3,944
You are correct. There is no better way to learn what code means than to look at code that runs and watch the results run on the hardware.

I haven't heard from elec_mech today. I know he wanted to add one more improvement to the code, and I also know that he has a real job, too. I can tell you that he is very close.

I was just joking about ordering parts, but the time will soon be upon us. By USB cable, do you mean the AXE-027 or something else?

Do you have the equipment and skills to do electronic soldering? Have you assembled any electronic kits? Do you have a solderless breadboard? In general, what is your electronic experience level?
 

Thread Starter

Transitory

Joined Jan 2, 2013
64
I was just joking about ordering parts, but the time will soon be upon us. By USB cable, do you mean the AXE-027 or something else?
Yes

Do you have the equipment and skills to do electronic soldering?
Equipment, no. Skills, perhaps. I'm a quick learner.

Have you assembled any electronic kits?
No :(

Do you have a solderless breadboard?
I have a loaf of bread! :D

In general, what is your electronic experience level?
I can build personal computers, strip wires, and re-wire outlets. (basic household electric work)
 

tracecom

Joined Apr 16, 2010
3,944
I have a loaf of bread! :D
And a good sense of humor, which will help :) and so will the experience of assembling PCs.

So you know that you are looking at spending some money; you will need a soldering station. It doesn't have to be the very best, but you don't want something that is going to be a hinderance.

And you will need some other small hand tools, unless what you already have is small enough for 22 - 26 AWG wire. A solderless breadboard would be really handy, especially in the beginning.
 

thatoneguy

Joined Feb 19, 2009
6,359
Watch this video first

You'll save money and not regretting some purchases if you decide to make more projects (which most everybody does end up doing).

I'd leave off the scope now, as well as the expensive anti-static mat. Function gnerator optional, only a single power supply (a wall wart is good enough to start), etc. The rest on mulitimeters, soldering, and hand tools are "best advice I've seen".
 

elec_mech

Joined Nov 12, 2008
1,500
I'm getting closer. I was extremely busy at work putting out small fires and rebuilding a computer used as our server of sorts.

I did have a little time right at the end of the day to do some redesign. I'm doing a little testing now.

Yes, I'd suggest waiting on buying anything just yet - we'll finish out the BOM once we've nailed the circuit design. I'm trying to work out some more bugs with the switches. The start button works when released, so holding it down somewhat pauses the code. I was hoping to eliminate this by using a CR circuit, but it only made the button unresponsive. Agh. I did eliminate having the other buttons cause the same effect when in countdown mode. You win some, you lose some. Just trying to add an auto-repeat feature for the minute and second buttons, then, goodness help me, I think we're ready to release this.

As I'm sure tracecom can atest too, you will have plenty to digest and sift through when you see the final code. I've commented everything, but that only covers so much.

Hope to have something in a day or two, but don't hold me to it. :)
 
Top