Buzby
Senior Member
The orrery is started !
I've got some rough code ready, and the PCB design is almost finished.
( When I find a fabricator who can do it for less than £50 inc P&P I'll order the PCB. )
I originally thought I would need multiple PICaxes, but I've got it down to one 40X2.
It really has been a challenge just getting this far. I've had to write VB to automate the main part of the PCB layout, and more VB to connect the LEDs, and even more VB to create the LED lookup table.
I've found out all the planet's orbital characteristics and squashed them into 16-bit numbers. ( I've got a 32-bit system, it's far more accurate but it runs out of variables too soon, so it only works for 4 planets.
I've experimented with Charlieplexing upto 56 LEDs, the orrery will use nearly ten times as many !.
The PCB layout takes nearly 24 hours to Auto-route.
http://www.doghouse.talktalk.net/partofmypcb.png
It is, as eclectic said, 'a gigantic medieval labour of love', but I'm going to do it.
Here is my rough code :
I've got some rough code ready, and the PCB design is almost finished.
( When I find a fabricator who can do it for less than £50 inc P&P I'll order the PCB. )
I originally thought I would need multiple PICaxes, but I've got it down to one 40X2.
It really has been a challenge just getting this far. I've had to write VB to automate the main part of the PCB layout, and more VB to connect the LEDs, and even more VB to create the LED lookup table.
I've found out all the planet's orbital characteristics and squashed them into 16-bit numbers. ( I've got a 32-bit system, it's far more accurate but it runs out of variables too soon, so it only works for 4 planets.
I've experimented with Charlieplexing upto 56 LEDs, the orrery will use nearly ten times as many !.
The PCB layout takes nearly 24 hours to Auto-route.
http://www.doghouse.talktalk.net/partofmypcb.png
It is, as eclectic said, 'a gigantic medieval labour of love', but I'm going to do it.
Here is my rough code :
Code:
#picaxe 40X2
' Orrery
' Hardware
' 24LCxxx on I2C bus address %10100000
' IR receiver on C.1
' Piezo sounder on C.2
' This project uses a technique which addresses each bit of ports ABCD by using the numbers 0 to 31.
' Addressing IO in this way is not usually needed in PICaxe programmes, but in this case it simplifies
' the code considerably.
' The Charlieplexed LED matrix is formed from the signals n1 to n24.
' These 24 IO lines can drive a total of 552 LEDs,the Orrery uses nearly all these.
'
' Num Port Leg Usage Num Port Leg Usage
' 0 B.0 33 n1 ' 16 A.0 2 n13
' 1 B.1 34 n2 ' 17 A.1 3 n14
' 2 B.2 35 n3 ' 18 A.2 4 n15
' 3 B.3 36 n4 ' 19 A.3 5 n16
' 4 B.4 37 n5 ' 20 A.4 7 Serout
' 5 B.5 38 n6 ' 21 A,5 8 -
' 6 B.6 39 n6 ' 22 A,6 9 -
' 7 B.7 40 n8 ' 23 A.7 10 -
' 8 C.0 15 n9 ' 24 D.0 19 n17
' 9 C.1 16 IRin ' 25 D.1 20 n18
' 10 C.2 17 Piezo ' 26 D.2 21 n19
' 11 C.3 18 i2c ' 27 D.3 22 n20
' 12 C.4 23 i2c ' 28 D.4 27 n21
' 13 C.5 24 n10 ' 29 D.5 28 n22
' 14 C.6 25 n11 ' 30 D.6 29 n23
' 15 C,7 26 n12 ' 31 D.7 30 n24
' Common variables
'Symbol LEDold = W27
'Symbol LEDnew = W26
Symbol I2Caddr = W25
Symbol LEDanode = B2
Symbol LEDcathode = B3
Symbol DisplayDelay = W24
Symbol IRval = B4
' Mercury variables
Symbol MercuryCount = W23 ' Current count value
Symbol MercuryLED = W22 ' Current LED number
' Venus variables
Symbol VenusCount = W21
Symbol VenusLED = W20
' Earth variables
Symbol EarthCount = W19
Symbol EarthLED = W18
' Mars variables
Symbol MarsCount = W17
Symbol MarsLED = W16
' Jupiter variables
Symbol JupiterCount = W15
Symbol JupiterLED = W14
' Saturn variables
Symbol SaturnCount = W13
Symbol SaturnLED = W12
' Uranus variables
Symbol UranusCount = W11
Symbol UranusLED = W10
' Neptune variables
Symbol NeptuneCount = W9
Symbol NeptuneLED = W8
' Pluto variables
Symbol PlutoCount = W7
Symbol PlutoLED = W6
' Mercury constants
symbol MercuryCountPerLED = 3 ' Number of counts per LED
Symbol MercuryLEDoffset = 0 ' The starting number for the Mercury LEDS
Symbol MercuryCountPerOrbit = 64 ' The total number of counts for a full orbit.
' Venus constants
symbol VenusCountPerLED = 5
Symbol VenusLEDoffset = 24
Symbol VenusCountPerOrbit = 162
' Earth constants
symbol EarthCountPerLED = 7
Symbol EarthLEDoffset = 60
Symbol EarthCountPerOrbit = 264
' Mars constants
symbol MarsCountPerLED = 10
Symbol MarsLEDoffset = 96
Symbol MarsCountPerOrbit = 497
' Jupiter constants
symbol JupiterCountPerLED = 87
Symbol JupiterLEDoffset = 144
Symbol JupiterCountPerOrbit = 3131
' Saturn constants
symbol SaturnCountPerLED = 162
Symbol SaturnLEDoffset = 180
Symbol SaturnCountPerOrbit = 7777
' Uranus constants
symbol UranusCountPerLED = 309
Symbol UranusLEDoffset = 228
Symbol UranusCountPerOrbit = 22260
' Neptune constants
symbol NeptuneCountPerLED = 410
Symbol NeptuneLEDoffset = 300
Symbol NeptuneCountPerOrbit = 43507
' Pluto constants
symbol PlutoCountPerLED = 546
Symbol PlutoLEDoffset = 406
Symbol PlutoCountPerOrbit = 65496
' Code starts here
' ----------------
Init:
pause 4000
' Load the LED anode and cathode address details into the EEPROM
Gosub LoadI2Ctable1
' Reset counters
MercuryCount = 1
VenusCount = 1
EarthCount = 1
MarsCount = 1
JupiterCount = 1
SaturnCount = 1
UranusCount = 1
NeptuneCount = 1
PlutoCount = 1
' Main loop
' ---------
Orrery_loop:
' The calculation for each planet is the same
' Decrement the counter. When it reaches zero reset it to the full orbit count.
' Convert the count value into an LED number.
' Mercury
Dec MercuryCount
If MercuryCount = 0 then
MercuryCount = MercuryCountPerOrbit
endif
MercuryLED = MercuryCount / MercuryCountPerLED + MercuryLEDoffset
' Venus
Dec VenusCount
If VenusCount = 0 then
VenusCount = VenusCountPerOrbit
endif
VenusLED = VenusCount / VenusCountPerLED + VenusLEDoffset
' Earth
Dec EarthCount
If EarthCount = 0 then
EarthCount = EarthCountPerOrbit
endif
EarthLED = EarthCount / EarthCountPerLED + EarthLEDoffset
' Mars
Dec MarsCount
If MarsCount = 0 then
MarsCount = MarsCountPerOrbit
endif
MarsLED = MarsCount / MarsCountPerLED + MarsLEDoffset
' Jupiter
Dec JupiterCount
If JupiterCount = 0 then
JupiterCount = JupiterCountPerOrbit
endif
JupiterLED = JupiterCount / JupiterCountPerLED + JupiterLEDoffset
' Saturn
Dec SaturnCount
If SaturnCount = 0 then
SaturnCount = SaturnCountPerOrbit
endif
SaturnLED = SaturnCount / SaturnCountPerLED + SaturnLEDoffset
' Uranus
Dec UranusCount
If UranusCount = 0 then
UranusCount = UranusCountPerOrbit
endif
UranusLED = UranusCount / UranusCountPerLED + UranusLEDoffset
' Neptune
Dec NeptuneCount
If NeptuneCount = 0 then
NeptuneCount = NeptuneCountPerOrbit
endif
NeptuneLED = NeptuneCount / NeptuneCountPerLED + NeptuneLEDoffset
' Pluto
' -----
Dec PlutoCount
If PlutoCount = 0 then
PlutoCount = PlutoCountPerOrbit
endif
PlutoLED = PlutoCount / PlutoCountPerLED + PlutoLEDoffset
DisplayOrrery:
' This is the Charlieplex code.
' It lights each required LED one at a time, but does it fast enough to give the impression
' of continuous illumination.
' The LED is illuminated by setting the two IO pins which are connected to it's anode and cathode.
' The particular IO pins needed are looked up by using the LED number as the index into I2C EEPROM.
DisplayDelay = 1000 ' Length of time to light each LED ( 1000mS for simulation )
I2Caddr = MercuryLED * 2 ' Times 2 because we read 2 bytes back, so we index to twice the LED number
Gosub ShowLED ' Light the selected LED
I2Caddr = VenusLED * 2
Gosub ShowLED
I2Caddr = EarthLED * 2
Gosub ShowLED
I2Caddr = MarsLED * 2
Gosub ShowLED
I2Caddr = JupiterLED * 2
Gosub ShowLED
I2Caddr = SaturnLED * 2
Gosub ShowLED
I2Caddr = UranusLED * 2
Gosub ShowLED
I2Caddr = NeptuneLED * 2
Gosub ShowLED
I2Caddr = PlutoLED * 2
Gosub ShowLED
Goto Orrery_loop ' Repeat indefinately
' Subroutines
' ------------
' ----------------------------------------------------
' Light one LED for a short time
' ----------------------------------------------------
ShowLED:
hi2cin I2Caddr, ( LEDanode, LEDcathode ) ' Get the anode and cathode numbers for the LED
High LEDanode ' Turn on the LED
Low LEDcathode
Pause DisplayDelay ' Wait a short while
Gosub CheckIR ' Check for IR. ( Do this during the display time, when we are aready waiting. )
Input LEDanode ' Turn off the LED
Input LEDcathode
Return
' ----------------------------------------------------
' Check for any IR command received
' ----------------------------------------------------
CheckIR:
IRIN [1, EndIR], C.1, IRval ' Get value from IR. Timeout after 1ms if nothing received.
Gosub ProcessIR ' Process any received IR command
EndIR:
Return
' -----------------------------------------------------
' Handle the IR commands
' -----------------------------------------------------
ProcessIR:
If IRval = 6 then ' Temporary code to stop simulation
end
endif
Return
' -----------------------------------------------------
' Preset the Anode and Cathode values in the I2C table
' -----------------------------------------------------
LoadI2Ctable1:
' Setup the I2C communication to the 24LCxxx EEPROM
hi2csetup i2cmaster, %10100000, i2cfast, i2cword
' Write the values to the EEPROM
hi2cout 0,(0,1) ' LED 0
hi2cout 2,(0,2) ' LED 1
hi2cout 4,(0,3) ' LED 2
hi2cout 6,(0,4) ' LED 3
hi2cout 8,(0,5) ' LED 4
hi2cout 10,(0,6) ' LED 5
hi2cout 12,(0,7) ' LED 6
----
---- A lot of LEDs missed out, forum only allows 10,000 chars per post !
---- PM me if you want the full list.
----
hi2cout 1094,(31,26) ' LED 547
hi2cout 1096,(31,27) ' LED 548
hi2cout 1098,(31,28) ' LED 549
hi2cout 1100,(31,29) ' LED 550
hi2cout 1102,(31,30) ' LED 551
Return