Stap 11: Het allemaal samen brengen
Een kort idee van de opeenvolging van gebeurtenissen:
Wanneer de macht wordt toegepast op de drie platen begint de rechter plank langzaam pulserende van één reeks van rode LEDs in een hartslag patroon. Dit wordt gedaan met behulp van software PWM opdrachten (onderdeel van de grote koe Basic suite) variëren van de helderheid van een aantal rode LEDs. Deze code is in een continue lus.
Afhankelijk van de configuratie die is ingesteld door de jumpers, doen de andere twee boards niets, gewoon een lus ronde wachten op een signaal dat aangeeft dat de harde schijf heeft geweest toegankelijk.
Alle drie platen reageren wanneer er een signaal wordt ontvangen om aan te geven dat de harde schijf is bekeken. Elk bord een opeenvolging van LED lichteffecten duurt een paar seconden te doen. Als de harde schijf wordt niet opnieuw krijgen toegankelijk, ga de planken terug naar hun 'standaard' status in een lus. Als de harde schijf blijft bereikbaar (dit gebeurt vaak) dan ze LED-verlichting blijven. De eerste Raad van bestuur houdt een timer gaan en als de harde schijf al herhaaldelijk toegang voor een periode van 30 seconden of langer, dan een 'meer waanzinnige' set LED lichteffecten kicks in en een tweede signaal draad communiceert deze staat aan de andere twee platen te laten verhogen van het tempo van hun LED effecten.
The "LED effects" omvatten:
- 'Roteren' patroon van LEDs op de dummy schotel harde schijf
- 'Bewegende' patroon van LEDs reizen van de wervelkolom
- Willekeurige flitsen van LEDs in 'het brein'
Net omwille van belang, heb ik de grote koe Basic-programma die wordt verzameld en geladen op een PIC 16F88 te geven een smaak van wat het element van de software van dit project kijkt gereproduceerd. Deze veel toegankelijker dan de normale PIC programmering methoden. Iets dergelijks is naar elk van de drie PCB modules geladen. Veel van de code is commentaar, in plaats van actieve code. Om het even wat na een apostrof is een commentaar. Commentaar is zeer belangrijk voor het behoud van de software en dit is een voorbeeld van mijn werkende code - niet speciaal commentaar voor anderen om te lezen!
'Program which drives the "Brain" board (Kicad "LED driver module 01")' it has all of the PortB outputs connected to a ULN2804 driver ' it has PortA.4, PortA.6 and PortA.7 connected to MOSFET drivers ' it has PortA.2 (jumper 0) and PortA.3 (jumper 1)connected as mode jumpers (normally high - jumpers pull low) ' it has PortA.1 and PortA.0 as inputs ' it has no external connection to PortA.5 (pulled high and connected for Vpp)' The software consists of a 41 stage For/Next loop ' which drives the red 'heartbeat'. ' If a demand is made on the hard drive (ie PortA.0 has been driven high by the master board) ' then the blue leds on the dummy hard drive are lit alongside (ie as part of) the ' for/next loop. ' For the dummy hard drive leds to start, the for/next loop has to finish its heartbeat cycles. ' Hence there is a delay before the dummy drive lights start up.' The software uses a software PWM (RB1)'Program options'Hardware settings #chip 16F88, 8 'PIC 16F88 running at 8 MHz #config MCLR = Off, osc=INTRC_IO 'Turn off MCLR, select internal osc. 'WDT and LVP are disabled automatically'Initialise 'HEARTBEAT '~~~~~~~~~ 'Split waveform into 20 values to indicate the brightness of the red leds 'dim = 0 Bright = 60??? Table RedLedBrightness 3 3 2 2 2 2 2 10 30 50 70 90 100 100 100 100 100 100 100 100 90 80 70 60 55 50 45 40 35 30 25 20 15 10 5 5 4 4 3 3 end table'SET PORT DIRECTIONS Dir PORTB Outdir PORTA.4 out dir PORTA.6 out dir PORTA.7 out dir PORTA.0 in 'input line - demand being made dir PORTA.1 in 'input line dir PORTA.2 in 'mode jumper dir PORTA.3 in 'mode jumperdir PORTA.5 in 'MCLR connected to pin A5 - not used' next line sets up the software PWM channel #define PWM_Out1 PORTA.7'Set initial state of port B PORTB = b'10000000'set PORTA.4 off set PORTA.6 off set PORTA.7 offwait 2 s ' give the programmer a moment to kick in AllLedsOff'###################################################### 'Software PWM 'PWMOut channel, duty cycle, cycles in 0.5us cycles (for an 8MHz chip) ' , 0-255 , 100 = 50us 'not convinced about the 255 value being 100% ! Using 0 - 100 seems to cover the full brightness range??? '###################################################### 'Main routineDemandMade=falseDo'##### Check for jumper positions '================================ modeLSB=PORTA.2 ' jumper nearest to the power block modeHSB=PORTA.3 ' jumper away from the power block mode = modeLSB+(modeHSB*2)'no jumpers = 3 'jumper A.3 in = 2 'On user instruction - referred to as "J5 in J6 out (2): High demand causes random flashing of the blue lights." 'jumper A.2 in = 1 'On user instruction - referred to as "J5 out J6 in (1): High demand is ignored. Heartbeat and dummy disc are normal, blue plate lights off." 'both jumpers in = 0 'On user instructions - referred to as "J5 in J6 in: High demand causes dummy disc, red heartbeat and blue plate lights to randomly flash." 'REMEMBER jumper positions in the user guide are numbered in reverse 'to the markings on the physical wires (wire 1 = jumper 8, etc) '#### Check for demand and demand level '====================================== if Porta.0=on then DemandMade=true else DemandMade=false end ifif PORTA.1=on then PeakDemand=true else PeakDemand=false end if'#### Do the code required by the jumper position '================================================ Select case mode case 3 ' no jumpers in 'PORTB is sequenced in a circle for normal demand levels and sparkles for high levels 'Red LEDs have heartbeat in all circumstances 'Other 2 outputs have random sparkling at high levels - otherwise off if DemandMade=true then PORTB = b'10000000' For cycle = 1 to 40 ReadTable RedLedBrightness, cycle, brightness PWMOut(1, brightness , 25) if DemandMade=true and PeakDemand=False then Rotate PORTB Right simple if DemandMade=true and PeakDemand=True then PORTB = random ' makes output leds 'sparkle' PORTA.4=random/128 ' just a random 0 or 1 value PORTA.6=random/128 end if next case 1 'PORTB is sequenced in a circle for All demand levels 'Red LEDs have heartbeat in all circumstances 'Other 2 outputs are off off if DemandMade=true then PORTB = b'10000000' For cycle = 1 to 40 ReadTable RedLedBrightness, cycle, brightness PWMOut(1, brightness , 25) if DemandMade=true then Rotate PORTB Right simple next case 2 'PORTB is sequenced in a circle for all demand levels 'Red LEDs have heartbeat in all circumstances 'Other 2 outputs have random sparkling at high levels - otherwise off if DemandMade=true then PORTB = b'10000000' For cycle = 1 to 40 ReadTable RedLedBrightness, cycle, brightness PWMOut(1, brightness , 25) if DemandMade=true then Rotate PORTB Right simple if DemandMade=true and PeakDemand=True then PORTA.4=random/128 ' just a random 0 or 1 value PORTA.6=random/128 end if next case 0 'both jumpers in 'PORTB is sequenced in a circle for normal demand levels and sparkles for high levels 'Red LEDs have heartbeat unless there is high demand 'Other 2 outputs have random sparkling at high levels - otherwise off if DemandMade=true then PORTB = b'10000000' For cycle = 1 to 40 if DemandMade=true and PeakDemand=False then Rotate PORTB Right simple ReadTable RedLedBrightness, cycle, brightness PWMOut(1, brightness , 25) end if if DemandMade=true and PeakDemand=True then ' All ports just flash randomly 40 TIMES ' Great for MAXED-OUT brain (bright and vibrant!) PORTB = random ' makes output leds 'sparkle' if random>128 then set PORTA.4 on else set PORTA.4 off end if if random>128 then set PORTA.6 on else set PORTA.6 off end if if random>128 then set PORTA.7 on else set PORTA.7 off end if wait 40 ms end if if DemandMade=False then ReadTable RedLedBrightness, cycle, brightness PWMOut(1, brightness , 25) end if next end selectAllLedsOffLoop '###################################################### Function AllLedsOffPORTB = b'00000000' set PORTA.4 off set PORTA.6 off set PORTA.7 offend function