Interrupt / synchronization of PICs

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
TregC
Posts: 10
Joined: 03 Aug 2009 06:07

Interrupt / synchronization of PICs

#1 Post by TregC » 12 Mar 2019 10:14

After a long break I am working on an "old" project again.
The aim is to build a led powered map of the river Elbe and the Port of Hamburg with all the "traffic lights" on the waterways.
This means that some 450 LEDs have to powered by PICs and the light of each LED be transported by a separate fibreoptic…
All the leds are flashing according to the "real world" (e.g. one of the LEDs will have 3 short light flashes of less than a second each within a period of 9 seconds…). At the same time the LEDs shall not just be just switched on and switched off again, PWM is part of programming the PICs.
All of the above is already been taken care of, but one problem remains…

In some cases two lighthouses form a light "beam" that informs the captain of a ship that he is on the right track (rear and fore side) ...when the two lights are above the other.
In order to visualize these beams, in two cases more than 70 LEDs have to be installed. Each of the LEDs to be switched on four milliseconds after the other.
However, 70 LEDs means 3 PICs 18F46K22 to form such a light beam (as I only use the Ports B, C and D of each PIC as 24 x 40 mA = 0,96 A!).
After a few minutes, the three Pics are not synchronous any more… and the clear vision of the light beam is not existing anymore. So what I need is to synchronize the three Pics, for which all of the PORT A Input/Output Pins would generally be available.

I raised the question before and got the reply: use one pf the PICs as master; send a digital signal from the master to the other PICs and restart them by using an "interrupt".

The program code of all the PICs is very simple; however mathematically a nightmare; for 2000
rows it basically looks like:

.program Hamburger_Hafen_PIC_01
'PIC 0.1
'Port B Bein 0 Sommerflethwisch OF Weiss ISO 8s
'Port B Bein 1 Elbe 120 Rot Quick
'Port B Bein 2 Elbe 119 / HN1 Grün Quick
'Port B Bein 3 Mühlenberger Loch Weiss Quick
'Port B Bein 4 Este EZ3 / HN24 Grün Quick
'Port B Bein 5 Finkenwerder Tiefwasser 7B Weiss ISO 8s
'Port B Bein 6 EADS Startbahn Ost Weiss ISO 8s
'Port B Bein 7 Elbe 132 Rot Quick

'Port C Bein 0 Elbe 135 / KS 1 Gelb Quick
'Port C Bein 1 Einfahrt Köhlbrand Gelb Quick
'Port C Bein 2 Einfahrt Kohlenschiffhafen Gelb Quick
'Port C Bein 3 Köhlbrand KS 7 Grün ISO 8s
'Port C Bein 4 Sandauhafen Rot ISO 2s
'Port C Bein 5 Köhlbrand KS 6 Rot Quick
'Port C Bein 6 Vattenfall 2 Gelb Flash
'Port C Bein 7 Köhlbrand KS 8 / RST Rot Quick

'Port D Bein 0 Vattenfall KS 10 Gelb Flash
'Port D Bein 1 Altona HADAG Orange Quick
'Port D Bein 2
'Port D Bein 3
'Port D Bein 4
'Port D Bein 5
'Port D Bein 6
'Port D Bein 7

' Declarations section


main:
' Testing of all LEDs when the map is powered on
PortA = 0xFF
PortB = 0xFF
PortC = 0xFF
PortD = 0x00
TRISA = 0x00
TRISB = 0x00
TRISC = 0x00
TRISD = 0x00
delay_ms(100)


While TRUE
'regular loop
PortB = 0x03
PortC = 0xFF
PortD = 0x07
Delay_ms(4)
PortB = 0x03
PortC = 0xFF
PortD = 0x07
Delay_ms(4)
PortB = 0x03
PortC = 0xFF
PortD = 0x07
Delay_ms(4)
PortB = 0xFF
PortC = 0xFF
PortD = 0xFF
Delay_ms(4)
PortB = 0xFF
PortC = 0xFF
PortD = 0xFF
Delay_ms(4)

...
PortB = 0x0
PortC = 0x0
PortD = 0x80
Delay_ms(4)
PortB = 0x0
PortC = 0x0
PortD = 0x80
Delay_ms(4)
wend ' Endless loop

end.


Proposed solution:
Assumptions:
PIC1 to be the "Master"
PIC2 to be the "Slave"
An electrical bridge to be established between PIC1 PIN A0 and PIC2 PIN A1...

Let us assume PIC1's program loop lasts for 4 seconds and PIC2's loop is 5 seconds long.
That would mean, that PIC1 is going through 5 loops and sending the Interrupt-PING on PIN A0;
at the same time PIC2 is going through 4 loop and thereafter waiting for the Interrupt-PING on PIN A1.
Once PIC2 receives the PING on PIN A1, it will restart with its loop from the beginning...

How is that to be programmed in the PICs 1 and 2 ? Can you please help me out? Counter (step up /
step down) how would the Interrupt be programmed?

I am sure there is help somewhere - please guide my way!
Many thanks in Advance
Gert

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”