PIC to run multiple programs

dpbarry

New Member
Hi..

Is there PIC available that will run a number of programs. I have a coastal marine chart which shows the lighhouses around the coast of Ireland. My father (deceased) has served on a number of these lighthouses so what I would like to do is incorporate a small LED at each 'lighthouse' on the chart which flashes its characteristic and enclose it within a picture frame to put up on a wall in my house. As it stands, I can do them individually but was wondering if there was a chip available that would allow me to program a number of independent programs onto the one chip thus saving me a lot of space.

Regards

Declan Barry
 

Michael 2727

Senior Member
Hi Dpbarry,
A couple of months back was a similar request for channel marker buoys.
Probably your best bet would be to use an 08 or 08M chip for each lighthouse.
How many ?
The others may not agree, I'm sure they will
have their 2 cents worth if not.

<A href='http://www.rev-ed.co.uk/picaxe/forum/Topic.asp?topic_id=6851&amp;forum_id=30&amp;Topic_Title=It%2Bcant%2Bbe%2Bdone&amp;forum_title=No+new+posts+please%21+22' Target=_Blank>External Web Link</a>
http://www.rev-ed.co.uk/picaxe/forum/Topic.asp?topic_id=6851&amp;forum_id=30&amp;Topic_Title=It%2Bcant%2Bbe%2Bdone&amp;forum_title=No+new+posts+please%21+22
 

Michael 2727

Senior Member
Cough, Cough, Choke, Aheeem, sorry.

79 !!!!!
Well each 08/M should do 4 lighthouses.

<A href='http://en.wikipedia.org/wiki/Lighthouses_in_Ireland' Target=_Blank>External Web Link</a>
http://en.wikipedia.org/wiki/Lighthouses_in_Ireland
 

Mycroft2152

Senior Member
Interesting project. How long is each flashing cycle and how complex a pattern?

You may be able to use one of the multi-led drivers discussed recently and play the patterns step by step.
 

dpbarry

New Member
Thanks Michael..

Can the chip run 4 separate circuits independently all on the one chip?

If so, would you have an example that would demonstrate this. How do I set up flowcharts to produce independent timing circuit for 4 lighthouses so that each LED displays its own characteristic independently of the other 3.

Declan
 

dpbarry

New Member
Hi Folks.

To get an understanding of what I'm trying to do, if we look at 3 lighthouses. Each lighthouse has its own characteristic flash. LH1 produces one flash every 3 seconds and just constantly repeats this. LH2 flashes 4 times every 20 seconds (1 second between each flash)and LH3 flashes once every 15 seconds.

Using individual chips I can do this without any problems but with 10 lighthouse to do, the picture frame is going to get a bit crowded. Is there a way of 'grouping' together a number of these onto one chip - each one working independently of the other.

Regards

Declan
 

Tom2000

Senior Member
Declan, could you please post the sequences for all the lighthouses you'd like to display? (seconds on, seconds off, seconds on, seconds off, etc.) With the data at hand, it's possible that we might work up a clever algorithm for you.

Edited to add: our messages must have crossed in the post. OK, that's the pattern for three lighthouses. I have an idea already. Could you please post the patterns for the other seven? Thanks!



My guess is that, with some clever programming, there's no need for more than one Picaxe processor (as long as you have sufficient output lines to handle the desired number of lighthouse LEDs.)

Thanks!

Tom


Edited by - Tom2000 on 25/06/2007 15:22:07
 

Michael 2727

Senior Member
Dpbarry, I have never used Flow Charts, I have only ever used Picaxe Basic.
It is very easy to use once you get started.
There are several ways to make a pin high or low but the Picaxe uses one internal
clock so everything will be internally linked timing wise, here is where creativity
comes in.
If you could provide the timing lengths and durations of 4 different lighthouses, I'm
sure you will get a few different options from the forum.

In the Wiki map, it is broken into 4 sections, if you picked a lighthouse
starting at the beginning of each division e.g. N, E, S, W then working clockwise 1
chip = next 4 lighthouses, etc, etc.
They would seem much more random.
 

dpbarry

New Member
Hi Tom.

I've about 10 lighthouse that my father served on. I'll get back to the board which with the flashing sequences as soon as I can.

Declan
 

dpbarry

New Member
Sorry Michael..

Getting a bit out of sync with replies. I've included 3 lighthouse in a previous post. If you add on LH4 to flash 3 times every 10 seconds (1 second between each flash)

Declan
 

Michael 2727

Senior Member
The wiring is easy, just create a common cathode (NEG) for every LED, then power it
on from the appropriate pin/duration.

May be a little hard to see here, one chip or multi chip will work the same.
<code><pre><font size=2 face='Courier'>
_----#--------#------#--_
| |
| # # # |
# #. | ,&#180; #
| \ | ,&#180; # |
| `\ | / |
| `. ,&#180; |
# # `. ,&#180;|---. #
| \ `. / |###| # |
| \ \.,&#180; |###| |
# #------\-----,&#180;-----.---|-__ |
| \---' \ | ''--__ |
# # |###| `\ | ''# #
| |###| `. | |
| |--- -_ `\ | |
# # '. ''-_\ | |
| | \''-__ | ____--# #
| #-__ | \-- -'--_ |
# ''--__| |##| | '--_ |
| |''--__ |##| | ''# #
| # '| '' -- | |
# | | | |
| '. | | # #
| # | | |
# | | /' |
| # | | .' # #
| | ' ' |
-# |
------#-------#---#----#


(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de) </font></pre></code>
 

Michael 2727

Senior Member
<code><pre><font size=2 face='Courier'>' Sequence -
#picaxe 08M
' Outputs on pin0, pin1, pin2, pin4

L1:
High 0 ' pin0.
Pause 1000 ' = 1 Sec ON.
Low 0 ' pin0.
Pause 3000 ' = 3 Sec OFF.

L2:
High 1 ' pin1.
Pause 1000 ' = 1 Sec ON.
Low 1
Pause 1000 ' = 1 Sec OFF.
High 1
Pause 1000 ' = 1 Sec ON.
Low 1
Pause 1000 ' = 1 Sec OFF.
High 1
Pause 1000 ' = 1 Sec ON.
Low 1
Pause 1000 ' = 1 Sec OFF.
High 1
Pause 1000 ' = 1 Sec ON.
Low 1
Pause 20000 ' = 20 Sec OFF.

L3:
High 2 ' pin2.
Pause 1000 ' = 1 Sec ON.
Low 2 ' pin2.
Pause 15000 ' = 15 Sec OFF.

L4:
High 4 ' pin4.
Pause 1000 ' = 1 Sec ON.
Low 4 ' pin4.
Pause 1000 ' = 1 Sec OFF.
High 4 ' pin4.
Pause 1000 ' = 1 Sec ON.
Low 4 ' pin4.
Pause 1000 ' = 1 Sec OFF.
High 4 ' pin4.
Pause 1000 ' = 1 Sec ON.
Low 4 ' pin4.
Pause 10000 ' = 10 Sec OFF.

' Now meshing it all is the fun part. </font></pre></code>

It's late here so I'm off for now.
Good luck !


 

hippy

Ex-Staff (retired)
I'm going to have to mention that M5450 34-LED Driver chip again :)

Three of those and an 08M could possibly do the job for 102 lighthouses although I'd go for an 18X because of the extra program space and larger SFR (RAM). A 28X1 would be faster still with a 16MHz resonator. You could perhaps have three 08M's each driving a single M5450. Other LED multiplexing options are available. Using an LDR and you may be able to make the display auto-dimmable at night time.

If you only have up to 16 lighthouses a 28X1 by itself can do the job.

All PICAXE's can run multiple programs; but scheduling and running each has to be done within the PICAXE user program. In this case though, one program can be dealing with a set of 78 data entities one after another. The trick is in representing these data entities which will all be mini Finite State Machines as they independently run through their flashing sequences. Then there's the challenge of storing those sequences ( the 18X has an advantage over 08M because it has separate EEPROM and Code space, useful for large tables ).

Doing this in the flowcharter is likely possible, but you'll be much better off coding in native PICAXE Basic.

Edited by - hippy on 25/06/2007 16:43:31
 

hippy

Ex-Staff (retired)
Bereft of comments and not exactly easy to follow without an explanation which isn't there, this will drive eight lighthouses on PICAXE-18X Output Pins ...

http://homepage.ntlworld.com/the.happy.hippy/picaxe/flashing.txt ( <A href='http://homepage.ntlworld.com/the.happy.hippy/picaxe/flashing.txt' Target=_Blank>External Web Link</a> )

Uses 145 bytes which can be reduced ( got it down to 102 bytes on a 14M, but even less readable ), so two 14M's should be easily able to control five lighthouses each, with no extra chips, maybe a single 14M controlling ten !

Only tested on simulator where it looked like it was working.

Edited by - hippy on 25/06/2007 17:53:31
 

Tom2000

Senior Member
OK, Declan, I think I have an approach.

I suggest a 28X1 for both its ability to directly drive up to 16 lighthouses, and for its scratchpad RAM that will come in handy.

My idea is to store the sequence for each lighthouse as a series of bits in an eeprom table. Each table entry will also have one byte to store the maximum length of that lighthouse' sequence. For instance, the sequence for the lighthouse that flashes four times each 20 seconds might look like this:

<code><pre><font size=2 face='Courier'>

byte 1: 20
byte 2: %00000000
byte 3: %00000000
byte 4: %01010101

</font></pre></code>

Maybe analysis of your sequences will show that you need fewer than three bytes to store
the patterns. If so, change the scheme accordingly.

The program would read each sequence, one bit per second, starting with bit 0 of byte 4, working up the entry toward bit 7 of byte 2.

Or, it could be organized to go the other direction, working from bit 7 of byte 2 down toward bit 0 of byte 4, whichever scheme makes the coding simpler.

The address of the first eeprom table location is called something like TblAddr.

In either case, the idea works the same. Once each second, the program reads the appropriate bit of each lighthouse entry. If that bit is a 1, it turns on that lighthouse' LED. If it's a zero, it turns it off.

Here's how it might work:

Each lighthouse entry in eeprom has a corresponding position pointer stored in 28X1 scratchpad RAM, accessed by @ptr. These pointers keep track of the bit currently being &quot;served&quot; by the program.

The program works like this:

<code><pre><font size=2 face='Courier'>



symbol LHNumber = 11 ; Max lighthouses - 1

Main:

Initialization:

for ptr = 0 to LHNumber ; clear position counters
@ptr = 0
next

; this loop does almost all the work:

do

pause 1000 ; 1 second &quot;ticks&quot;

for b0 0 to LHNumber

b1 = b0 * 4 + TblAddr ; b1 = starting address of lighthouse table entry
read b1,b2 ; b2 contains maximum length of that entry in secs
ptr = b0
b3 = @ptr ; b3 contains the current sequence position

gosub GetBit ; GetBit takes table address in b1 and
; sequence position in b3. It parses the
; table entry, returning the state of the
; appropriate bit in flag0

if flag0 = 1 then ; LED_ON and LED_OFF turn on or turn off
gosub LED_ON ; the appropriate LED designated by the value in b0
else
gosub LED_OFF
endif

inc @ptr ; inc the sequence position. If it's longer than
if @ptr &gt; b2 then ; the maximum sequence length, set it back to 0.
@ptr = 0
endif

next ; do the same process for all lighthouses

loop ; continue forever

end



</font></pre></code>


If the pattern table requires only one byte to store the flash pattern, GetBit would
be pretty simple:


<code><pre><font size=2 face='Courier'>



; Lighthouse sequence entry:

byte 1 (addr in b1) contains max sequence length
byte 2 (addr = b1 + 1) contains bit pattern

GetBit:

if b3 &gt; 7 then

flag0 = 0
return

endif

inc b1 ; point to the byte containing the data pattern
b4 = dcd b3 ; generate a mask in b4corresponding to the sequence bit
; position
read b1,b5 ; put the bit sequence in b5

b6 = b4 &amp; b5
if b6 &gt; 0 then
flag0 = 1
else
flag0 = 0
endif

return



</font></pre></code>


All in all, it looks quite workable with the 28X1. You could do the same thing for a maximum of 8 lighthouses using an 18X, but the code would be a bit clumsier without the scratchpad RAM and the DCD function. But you could work it out.

I hope this helps. Your framed, animated lighthouse map will be an amazing keepsake to hang on your wall. Nice project!

Have fun,

Tom








Edited by - Tom2000 on 25/06/2007 18:02:08
 

hippy

Ex-Staff (retired)
Fascinating stuff these lighthouses, and amazing two people should have been interested in the same simulation.

From <A href='http://www.unc.edu/~rowlett/lighthouse/irlw.htm' Target=_Blank>External Web Link</a> it appears that on and off periods are not whole seconds but down to tenths which would be easiest done by holding times in tenths of seconds, but that would limit a byte value to 25.5s max. Shouldn't cause a major problem though.

It's probably also worthwhile offsetting each lighthouse's first flash by a tenth of a second or so to put them slightly out of synch to make the effct more realistic.
 

Tom2000

Senior Member
&quot;Fascinating stuff these lighthouses, and amazing two people should have been interested in the same simulation.&quot;

Oh, yeah, Hippy, you've got that right! Declan's idea, and honoring his father as he is, resonates with the romantic chord in me.

Yes, after I posted the last message, I started really thinking about lighthouses, remembering how they actually look at night from the cockpit of a sailboat. The flashes certainly don't last for a whole second. I suppose Declan could reduce the granularity to 1/2 second, or perhaps 1/4 second. Even at 1/4 second, with 10 lighthouses and 255 bytes of eeprom, there's room to spare. The basic method would work the same, just different eeprom data.

By the way, many thanks for your site. I've learned an incredible amount about the Picaxe from your efforts. Much appreciated.

If you'd like to take a look at the mess in which I'm currently mired up to my earballs, peek at my page:

<A href='http://www.mindspring.com/~tom2000/picaxe/picaxe.html' Target=_Blank>External Web Link</a>

I've dug myself a deep hole. :)

Tom
 

Tom2000

Senior Member
Declan, here's an 18X working version. I didn't have any lighthouse patterns handy, so I built the program to flash the Morse digits 0 through 7 on outputs 0 through 7.

I've ordered a couple of 28X1s, but they haven't arrived yet, so I couldn't try this program on a physical 28X1.

Hope this helps, and that you'll really enjoy looking at your finished work of art.

Best,

Tom


<code><pre><font size=2 face='Courier'>






;
; Lighthouse simulator: tests algorithm for Declan's animated lighthouse artwork
;
; This program just flashes the outputs in Morse code
;
; Morse 0 on out0 through Morse 7 on out7
;
; 152 bytes
;
; Picaxe 18X, PE 5.1.3, Enhanced compiler options turned on
;


; Morse patterns in eeprom

; Record format: sequence length, then three bytes of data which represents
; the state of each output line during each baud interval.
;
; The sequences are stored back-to-front, with the LSB of the
; last byte sent first, working toward the MSB of the first
; sequence byte.
;


symbol TblBase = 0
symbol DSize = 4

data 0,(23,%00000111,%01110111,%01110111) ; 0
data 4,(21,%00000001,%11011101,%11011101) ; 1
data 8,(19,%00000000,%01110111,%01110101) ; 2
data 12,(17,%00000000,%00011101,%11010101) ; 3
data 16,(15,%00000000,%00000111,%01010101) ; 4
data 20,(13,%00000000,%00000001,%01010101) ; 5
data 24,(15,%00000000,%00000101,%01010111) ; 6
data 28,(17,%00000000,%00010101,%01110111) ; 7

symbol Cptr = 32 ; Character position regs in eeprom addr 32 - 39

symbol Baud = 50 ; Sets flash speed

symbol LEDLine = b1
symbol DataAddr = b2
symbol Size = b3
symbol Position = b4
symbol PosAddr = b5


Main:

; Initialize position registers

for LEDLine = 0 to 7
PosAddr = Cptr + LEDLine
write PosAddr,0
next


do

pause Baud

for LEDLine = 0 to 7

DataAddr = LEDLine * DSize + TblBase
read DataAddr,Size
PosAddr = LEDLine + Cptr
read PosAddr,Position

gosub GetBit ; get state of sequence bit in bit0

if bit0 = 1 then
gosub LED_on
else
gosub LED_off
endif

read PosAddr,Position ; inc position register
inc Position
if Position &gt; Size then
Position = 0
endif
write PosAddr,Position

next

loop

end


GetBit:

;
; Input:
;
; b2: DataAddr - sequence base address
; b4: Position - sequence position
;
; Action:
;
; returns state of sequence bit in bit0
;
; Modifies:
;
; bit0 in b0 modified
; b1 through b7 unchanged
; b8-b10 modified
;

if Position &lt; 8 then ; calculate the byte to retrieve from the table
b8 = 3
elseif Position &lt; 16 then
b8 = 2
else
b8 = 1
endif

b9 = DataAddr + b8 ; put sequence byte into b8
read b9,b8

b9 = Position % 8 ; b9 = bit position within the seq byte

b10 = 1 ; generate the mask in b10
do while b9 &gt; 0
b10 = b10 * 2
dec b9
loop

b9 = b8 &amp; b10 ; bit0 = sequence bit
if b9 &gt; 0 then
bit0 = 1
else
bit0 = 0
endif

return


LED_on:

low LEDLine

return


LED_off:

high LEDLine

return



</font></pre></code>

Edited by - Tom2000 on 25/06/2007 22:28:08

Edited by - Tom2000 on 25/06/2007 22:38:19
 

Mycroft2152

Senior Member
Parallax has an EFX-TEK sequencer board for propmasters based on the BS2. There are a lot of good ideas in the design and could be easily converted to a PICAXE. It's always easier to build on current knowledge, than to reinvent the wheel. It never hurts to &quot;borrow&quot; some good ideas ;)

http://www.efx-tek.com/

<A href='http://www.efx-tek.com/' Target=_Blank>External Web Link</a>
 

dpbarry

New Member
Cheers Guys.. Thanks

Off up to the Technology Department to use their equipment to simulate it all out

Declan
 

dpbarry

New Member
Hi Hippy.

The lighthouse at Inishtearaght is one that my father was on for a few years.

On the subject of the project boards, which one is the best to buy in order to 'develop' a project before commiting to an actual final project.. In my case, a 'Picture Frame'

Declan
 

Tom2000

Senior Member
Declan, here's something that worked very well for me in the beginning, and still works very well: <A href='http://www.mindspring.com/~tom2000/picaxe/proto.html' Target=_Blank>External Web Link</a>

Even if you purchase another type of project board, maybe this will give you and idea of how to &quot;doll it up&quot; and make it work best for you.

Good luck!

Tom
 
Top