' ================================================== ======================= ' ' File...... Zero.spin ' Purpose... This program will run identically-random on infinite? Zeros programmed from a prop plug in proper parallel config or using a master prop.. It self generates a random "life" that it waits with. ' Author.... Clock Loop @ parallax forums ' E-mail.... thereisnoelectron@gmail.com ' Started... 1-Jan-2014 ' Updated... 25-Feb-2014 ' ' ================================================== ======================= CON _clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz _xinfreq = 5_000_000 Blue1 = 27 Green1 = 30 Red1 = 31 Vpos1 = 25 Blue2 = 24 Green2 = 28 Red2 = 29 Vpos2 = 26 Blue3 = 20 Green3 = 21 Red3 = 22 Vpos3 = 23 Blue4 = 16 Green4 = 17 Red4 = 18 Vpos4 = 19 Blue5 = 11 Green5 = 12 Red5 = 14 Vpos5 = 15 Blue6 = 8 Green6 = 9 Red6 = 13 Vpos6 = 10 Blue7 = 4 Green7 = 5 Red7 = 6 Vpos7 = 7 Blue8 = 0 Green8 = 1 Red8 = 2 Vpos8 = 3 Tx = 30 'serial Rx = 31 'serial 'Eeprom = 28 'eeprom. 'Eeprom = 29 'eeprom. VAR long cogon[8], cog[8], pile[1000] ' cog management long blinkwait, readwait, AzizLeit, random1 word random OBJ Comm : "fullDuplexSerialPlus" 'Communication pc for diagnositc. RC : "RCTIME3" rr : "RealRandom" PUB Start 'Assuming that a 80 MHz core clock is being used, 800 cycles is about 10us. 'waitcnt(800 + cnt) 'Wait for 10us -100 khz 'waitcnt(8_000 + cnt) 'Wait for 100 us -10 khz 'waitcnt(80_000 + cnt) 'Wait for 1ms -1000 hz 'waitcnt(800_000 + cnt) 'Wait for 10 ms -100 hz 'waitcnt(8_000_000 + cnt) 'Wait for 100 ms -10hz human reaction speed 'waitcnt(80_000_000 + cnt) 'Wait for 1000 ms -1hz 'waitcnt(80_000_000 + cnt) 'Wait for 1000 ms -1hz stop ' stop all cogs if running rr.start blinkwait := 750_000 'Repeat 3 Red Green Blue GetRandom 'rr.stop RedData := 0 cogon[0] := (cog[0] := cognew(Main, @pile[0]) > 0) 'cogon[1] := (cog[1] := cognew(Light, @pile[600]) > 0) 'cogon[2] := (cog[2] := cognew(GreenGo, @pile[400]) > 0) 'cogon[3] := (cog[3] := cognew(BlueGo, @pile[600]) > 0) 'cogon[6] := (cog[6] := cognew(Diag, @pile[800]) > 0) Pub Main Repeat If RedData > 0 random1 := 256 * random waitcnt(random1 + cnt) blinkwait := random1 'Repeat 10 Red Green Blue Red RedData := 0 GetRandom Read Pub GetRandom waitcnt(20_000 + cnt) random := rr.random If random < 100 GetRandom If random > 30_000 GetRandom Pub Read outa[Vpos1] := 0 dira[Vpos1] := 0 'waitcnt(100_000 + cnt) dira[Vpos1] := 1 If RC.RCTIME(Red1, 10, 1, 30) > 0 RedData := 1 outa[Vpos2] := 0 dira[Vpos2] := 0 'waitcnt(100_000 + cnt) dira[Vpos2] := 1 If RC.RCTIME(Red2, 10, 1, 30) > 0 RedData := 1 outa[Vpos3] := 0 dira[Vpos3] := 0 'waitcnt(100_000 + cnt) dira[Vpos3] := 1 If RC.RCTIME(Red3, 10, 1, 30) > 0 RedData := 1 outa[Vpos4] := 0 dira[Vpos4] := 0 'waitcnt(100_000 + cnt) dira[Vpos4] := 1 If RC.RCTIME(Red4, 10, 1, 30) > 0 RedData := 1 outa[Vpos5] := 0 dira[Vpos5] := 0 'waitcnt(100_000 + cnt) dira[Vpos5] := 1 If RC.RCTIME(Red5, 10, 1, 30) > 0 RedData := 1 outa[Vpos6] := 0 dira[Vpos6] := 0 'waitcnt(100_000 + cnt) dira[Vpos6] := 1 If RC.RCTIME(Red6, 10, 1, 30) > 0 RedData := 1 outa[Vpos7] := 0 dira[Vpos7] := 0 'waitcnt(100_000 + cnt) dira[Vpos7] := 1 If RC.RCTIME(Red7, 10, 1, 30) > 0 RedData := 1 outa[Vpos8] := 0 dira[Vpos8] := 0 'waitcnt(100_000 + cnt) dira[Vpos8] := 1 If RC.RCTIME(Red8, 10, 1, 30) > 0 RedData := 1 Pub Red dira[0..31]~~ outa[0..31]~~ '----------------------------------------- waitcnt(blinkwait + cnt) outa[Red1] := 0 waitcnt(blinkwait + cnt) outa[Red1] := 1 waitcnt(blinkwait + cnt) outa[Red2] := 0 waitcnt(blinkwait + cnt) outa[Red2] := 1 waitcnt(blinkwait + cnt) outa[Red3] := 0 waitcnt(blinkwait + cnt) outa[Red3] := 1 waitcnt(blinkwait + cnt) outa[Red4] := 0 waitcnt(blinkwait + cnt) outa[Red4] := 1 waitcnt(blinkwait + cnt) outa[Red5] := 0 waitcnt(blinkwait + cnt) outa[Red5] := 1 waitcnt(blinkwait + cnt) outa[Red6] := 0 waitcnt(blinkwait + cnt) outa[Red6] := 1 waitcnt(blinkwait + cnt) outa[Red7] := 0 waitcnt(blinkwait + cnt) outa[Red7] := 1 waitcnt(blinkwait + cnt) outa[Red8] := 0 waitcnt(blinkwait + cnt) outa[Red8] := 1 dira[0..31]~ Pub Blue '----------------------------------------- dira[0..31]~~ outa[0..31]~~ waitcnt(blinkwait + cnt) outa[blue1] := 0 waitcnt(blinkwait + cnt) outa[Blue1] := 1 waitcnt(blinkwait + cnt) outa[Blue2] := 0 waitcnt(blinkwait + cnt) outa[Blue2] := 1 waitcnt(blinkwait + cnt) outa[Blue3] := 0 waitcnt(blinkwait + cnt) outa[Blue3] := 1 waitcnt(blinkwait + cnt) outa[Blue4] := 0 waitcnt(blinkwait + cnt) outa[Blue4] := 1 waitcnt(blinkwait + cnt) outa[Blue5] := 0 waitcnt(blinkwait + cnt) outa[Blue5] := 1 waitcnt(blinkwait + cnt) outa[Blue6] := 0 waitcnt(blinkwait + cnt) outa[Blue6] := 1 waitcnt(blinkwait + cnt) outa[Blue7] := 0 waitcnt(blinkwait + cnt) outa[Blue7] := 1 waitcnt(blinkwait + cnt) outa[Blue8] := 0 waitcnt(blinkwait + cnt) outa[Blue8] := 1 dira[0..31]~ Pub Green '----------------------------------------- dira[0..31]~~ outa[0..31]~~ waitcnt(blinkwait + cnt) outa[green1] := 0 waitcnt(blinkwait + cnt) outa[green1] := 1 waitcnt(blinkwait + cnt) outa[green2] := 0 waitcnt(blinkwait + cnt) outa[green2] := 1 waitcnt(blinkwait + cnt) outa[green3] := 0 waitcnt(blinkwait + cnt) outa[green3] := 1 waitcnt(blinkwait + cnt) outa[green4] := 0 waitcnt(blinkwait + cnt) outa[green4] := 1 waitcnt(blinkwait + cnt) outa[green5] := 0 waitcnt(blinkwait + cnt) outa[green5] := 1 waitcnt(blinkwait + cnt) outa[green6] := 0 waitcnt(blinkwait + cnt) outa[green6] := 1 waitcnt(blinkwait + cnt) outa[green7] := 0 waitcnt(blinkwait + cnt) outa[green7] := 1 waitcnt(blinkwait + cnt) outa[green8] := 0 waitcnt(blinkwait + cnt) outa[green8] := 1 dira[0..31]~ Pub White 'waitcnt(blinkwait + cnt) 'outa[Red1] := 0 'waitcnt(blinkwait + cnt) 'outa[Red1] := 1 '------------------------------ 'waitcnt(blinkwait + cnt) 'outa[Blue1] := 0 'waitcnt(blinkwait + cnt) 'outa[Blue1] := 1 '------------------------------ 'waitcnt(blinkwait + cnt) 'outa[Green1] := 0 'waitcnt(blinkwait + cnt) 'outa[Green1] := 1 '-2--------------------------------------------------------------------------------------- waitcnt(blinkwait + cnt) outa[Red2] := 0 waitcnt(blinkwait + cnt) outa[Red2] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Blue2] := 0 waitcnt(blinkwait + cnt) outa[Blue2] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Green2] := 0 waitcnt(blinkwait + cnt) outa[Green2] := 1 '-3--------------------------------------------------------------------------------------- waitcnt(blinkwait + cnt) outa[Red3] := 0 waitcnt(blinkwait + cnt) outa[Red3] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Blue3] := 0 waitcnt(blinkwait + cnt) outa[Blue3] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Green3] := 0 waitcnt(blinkwait + cnt) outa[Green3] := 1 '-4--------------------------------------------------------------------------------------- waitcnt(blinkwait + cnt) outa[Red4] := 0 waitcnt(blinkwait + cnt) outa[Red4] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Blue4] := 0 waitcnt(blinkwait + cnt) outa[Blue4] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Green4] := 0 waitcnt(blinkwait + cnt) outa[Green4] := 1 '-5--------------------------------------------------------------------------------------- waitcnt(blinkwait + cnt) outa[Red5] := 0 waitcnt(blinkwait + cnt) outa[Red5] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Blue5] := 0 waitcnt(blinkwait + cnt) outa[Blue5] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Green5] := 0 waitcnt(blinkwait + cnt) outa[Green5] := 1 '-6--------------------------------------------------------------------------------------- waitcnt(blinkwait + cnt) outa[Red6] := 0 waitcnt(blinkwait + cnt) outa[Red6] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Blue6] := 0 waitcnt(blinkwait + cnt) outa[Blue6] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Green6] := 0 waitcnt(blinkwait + cnt) outa[Green6] := 1 '-7--------------------------------------------------------------------------------------- waitcnt(blinkwait + cnt) outa[Red7] := 0 waitcnt(blinkwait + cnt) outa[Red7] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Blue7] := 0 waitcnt(blinkwait + cnt) outa[Blue7] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Green7] := 0 waitcnt(blinkwait + cnt) outa[Green7] := 1 '-8--------------------------------------------------------------------------------------- waitcnt(blinkwait + cnt) outa[Red8] := 0 waitcnt(blinkwait + cnt) outa[Red8] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Blue8] := 0 waitcnt(blinkwait + cnt) outa[Blue8] := 1 '------------------------------ waitcnt(blinkwait + cnt) outa[Green8] := 0 waitcnt(blinkwait + cnt) outa[Green8] := 1 PUB Diag comm.start(Rx, TX, 0, 250000) Repeat 'This is all for debug, enable if you want it. 'in_pasm(1 + cnt) 'Wait for 12.5 ns -80 Mhz 'in_pasm(8 + cnt) 'Wait for 100 ns -10 Mhz 'in_pasm(80 + cnt) 'Wait for 1us -1 Mhz 'waitcnt(800 + cnt) 'Wait for 10us -100 Khz 'waitcnt(8_000 + cnt) 'Wait for 100 us -10 Khz 'waitcnt(80_000 + cnt) 'Wait for 1ms -1 Khz 'waitcnt(200_000 + cnt) 'waitcnt(800_000 + cnt) 'Wait for 10 ms -100 Hz waitcnt(8_000_000 + cnt) 'Wait for 100 ms -10 Hz human reaction speed 'waitcnt(80_000_000 + cnt) 'Wait for 1000 ms -1 Hz comm.str(string(16)) 'clear screen Comm.str(string(1)) 'home 'comm.str(string(13)) 'cr Comm.str(string("Red:")) Comm.dec(RedData) comm.str(string(13)) 'cr Comm.str(string("Blue:")) Comm.dec(BlueData) comm.str(string(13)) 'cr Comm.str(string("Green:")) Comm.dec(GreenData) comm.str(string(13)) 'cr PUB stop '' Unload timer object - frees a cog if cogon[0]~ ' if object running, mark stopped cogstop(cog[0]) if cogon[1]~ ' if object running, mark stopped cogstop(cog[1]) if cogon[2]~ ' if object running, mark stopped cogstop(cog[2]) if cogon[3]~ ' if object running, mark stopped cogstop(cog[3]) if cogon[4]~ ' if object running, mark stopped cogstop(cog[4]) if cogon[5]~ ' if object running, mark stopped cogstop(cog[5]) if cogon[6]~ ' if object running, mark stopped cogstop(cog[6]) if cogon[7]~ ' if object running, mark stopped cogstop(cog[7]) DAT RedData long 0 GreenData long 0 BlueData long 0 {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}