pulsed-digit non-blocking inter-chip communication

lbenson

Senior Member
ac21 posted a timing diagram for 2-digit (excluding "0"s) codes transmitted by pulses in this thread: http://www.picaxeforum.co.uk/showthread.php?25341-Decoding-simple-high-low-codes

While not as useful now that M2 chips have 2-character background receive, this method could have been use for older M-series chips to provide non-blocking inter-chip communication.

I already had a 2-chip breadboard set up for instruction timing with 08Ms, so I decided to program sending and receiving codes. An interrupt on the rising edge of the first pulse makes the communication non-blocking.

Note that some time-outs might be helpful in production code.

Below is an example of a run with (more or less) randomly generated codes.

Code:
08_2-digit_pulse_code_receive
27 44 69 31 43 68 36 54 89 72 35 61 22 34 49 82 63 25 39 68 37 57 15 19 28 39 69 32 46 75 51 83 
66 32 53 95 83 57 96 93 85 63 17 16 15 13 98 96 85 69 38 66 25 41 72 36 62 15 19 29 41 63 17 24 
29 48 86 72 36 55 92 76 53 95 91 73 45 79 58 17 24 38 67 35 52 86 72 36 55 11 93 85 69 39 69 31 
51 83 57 96 92 76 52 85 62 16 23 36 62 16 15 19 29 49 88 77 55 93 86 72 44 71 34 49 88 69 31 51 
83 58 17 16 15 12 96 92 75 43 68 36 62 15 21 32 54 91 74 48 78 57 97 94 88 68 29 48 87 74 39 62 
16 15 13 98 97 86 64 27 36 63 18 27 37 64 28 39 62 15 13 98 89 79 58 17 24 31 44 69 31 52 85 63 
17 25 33 47 76 44 78 48 87 66 24 37 64 19 28 39 68 28 38 66 33 55 92 84 61 21 31 52 94 87 74 39 
69 39 69 38 59 18 26 35 53 95
Sender:
Code:
' 08_2-digit_pulse_code_send
#picaxe 08m
' generate 2-digit codes excluding "0"
' e.g., 11-19,21-29, ... 91-99

symbol wRandom=w6
symbol pOut=C.2

wRandom=48611 ' a largish prime
pause 4000    ' allow other picaxe to start up

do
  low pOut
  random wRandom
  b4 = wRandom // 81 ' yields 0-80
  b5 = b4 / 9 ' yields 0-8; adding 1 gives 10s digit
  inc b5
  b4 = b4 // 9 ' yields 0-8; adding 1 give ones digit
  inc b4
  sertxd(#b5,#b4," ")
  pause 1000            ' so you can see the # displayed
  for b6 = 1 to b5      ' tens digit of code
    pulsout pOut, 30000 ' 300 millisecond pulse
    pause 300           ' 300 millisecond pause
  next b6
  pause 1000
  for b6 = 1 to b4      ' ones digit of code
    pulsout pOut, 30000 ' 300 millisecond pulse
    pause 300           ' 300 millisecond pause
  next b6
  
  pause 3000  ' inter-code gap--change as needed
loop
Receiver:
Code:
' 08_2-digit_pulse_code_receive
#picaxe 08m
' read 2-digit codes excluding "0"
' e.g., 11-19,21-29, ... 91-99

symbol pInPin=pinC.2

pause 2000
sertxd("08_2digit_pulse_code_receive",cr,lf)
setint %00000100,%00000100 ' high on c.2

do
  ' any code here
  ' must tolerate up to 11 seconds of delay
loop

interrupt:
'  do while pInPin = 0 : loop ' wait til you see a high
  b4 = 1
  pause 750 ' middle of next high
  do while pInPin = 1
    inc b4
    pause 600 ' middle of next high
  loop
  b4= b4 * 10
  do while pInPin = 0 : loop ' wait for next digit
  inc b4  
  pause 750 ' middle of next high
  do while pInPin = 1
    inc b4
    pause 600 ' middle of next high
  loop
  sertxd(#b4," ")  ' number, e.g., 13
  setint %00000100,%00000100 ' high on c.2
  return
 

Attachments

  • pulse_coms3.jpg
    pulse_coms3.jpg
    65.7 KB · Views: 21
  • pulse_pattern.jpg
    pulse_pattern.jpg
    73.2 KB · Views: 23
Last edited:
Back
Top