PIC Mapping for midi to LPT decoder for musical robots using Intel 8254 Timer chips: ************************************************************************************ last update: 28.04.2004 Workout for data-port: RB0-RB7 Port B van de PIC, alle bits geflipt: RB7 ==> D0 pic pin 28 RB6 ==> D1 pic pin 27 RB5 ==> D2 pic pin 26 RB4 ==> D3 pic pin 25 RB3 ==> D4 pic pin 24 RB2 ==> D5 pic pin 23 RB1 ==> D6 pic pin 22 RB0 ==> D7 pic pin 21 adres-bus using port A, bits 0-5 Port A van de PIC: RA0 = A1 pic pin 2 RA1 = A2 pic pin 3 RA2 = A3 pic pin 4 RA3 = A4 pic pin 5 RA4 = A5, pull up 4k7 - channel select dil switch pic pin 6 bit0 RA5 = A6, channel select DIL switch pic pin 7 bit1 Port C van de PIC: RC0 = Timer 1 output. Test LED op PIC board (zoals op het board) LED via 1k2 naar GND. pic pin 11 RC1 = nc ? PWM output pic pin 12 RC2 = PWM output - connected to mosfet gate for PWM. pic pin 13 RC3 = A0 - strobe bit pic pin 14 RC4 = A7 - channel select DIL switch bit2 pic pin 15 RC5 = A8 - channel select DIL switch bit3 pic pin 16 RC6 = n.c. (cannot be used) pic pin 17 RC7 = serial input for MIDI data pic pin 18 (zoals op het board) GROUND: pic pin 19 pic pin 8 POSITIVE SUPPLY: 5V dc pic pin 20 Note1: with this design we can implement note-pulse with velo automats with up to 127 notes plus one pwm output. Note3: we connect RA4, RA5, RC4, RC5 to a DIL switch for setting the midi-channel (0-F) (read only only on startup or after PIC reset). Note4: it is essential that all data on the ports be stable before the strobe goes low. Software implementation: ' constants: strobe = RC3, at rest should always be high. aport = RA0-RA2 ( 3bits) (RA3 can be kept always low, such that we can always send a nibble) reg0 => RA0 = 1, RA1 = 0, RA2 = 1 (dec. 5) reg1 => RA0 = 0, RA1 = 0, RA2 = 1 (dec. 1) reg2 => RA0 = 1, RA1 = 1, RA2 = 1 (dec. 7) reg3 => RA0 = 0, RA1 = 1, RA2 = 1 (dec. 3) reg4 => RA0 = 1, RA1 = 0, RA2 = 0 (dec. 4) reg5 => RA0 = 0, RA1 = 0, RA2 = 0 (dec. 0) reg6 => RA0 = 1, RA1 = 1, RA2 = 0 (dec. 6) reg7 => RA0 = 0, RA1 = 1, RA2 = 0 (dec. 2) dport = RB0-RB7 (1 byte) ' procedure prototypes: Dripper_Initialize for n = 0 to 11 Dripper_NoteOff n ' zie proc. next n dripper_start ' zie proc. end Dripper_Start ' sends pincode to board: out dport, 239 ' pincode number out aport, reg2 out dport, 239 strobe (RC3 high to low and back to high for 1 microsecond) end Dripper_Stop ' sends pincode to board: out dport, 16 ' inverted pincode out aport, reg2 out dport, 16 strobe (RC3 high to low and back to high for 1 microsecond) end Dripper_NoteOff (note as byte) cw = note MOD 3 ' 00 , 01 or 10 selects one of the 3 timer inside 8254 shift left cw, 6 cw = cw OR &B00010010 ' set timer mode: out aport, reg1 out dport, 3 ' command = write to 8254 chip strobe ' set programmabyte cw op de databus: out aport, reg0 out dport, cw strobe 'send control word data to latches out aport,reg5 out dport, note \ 3 ' integer divide, selects chip number strobe ' send this to the correct timer out aport, reg7 strobe end Dripper_PulsOut (note as byte, velo as byte) local wvelo as word if velo = 0 then exit function ' following optional: note = note mod 12 ' so we get notes 0-11 in any octave ' end optional wvelo = velo ' must be 16 bit word variable shift left wvelo, 8 ' in 256 microsecond increments ' write control word: cw = note MOD 3 shift left cw,6 bit set cw,5 out aport, reg1 out dport, 3 strobe out aport, reg0 out dport, cw strobe out aport, reg5 out dport, note \ 3 strobe out aport, reg7 strobe ' now send the required data to the timer: out aport, reg1 out dport, note mod 3 strobe out aport, reg5 out dport, note \ 3 strobe out aport, reg0 out dport, HIBYT(wvelo) strobe out aport, reg7 strobe end Volume controller: controller nr. 7 channel 14 The received value for this controller should be output as a repeated PWM signal on pin 13 (RC2) of the PIC. For parameter value 0, the RC2 pin should be 0. (no PWM) For parameter value 127 ,RC2 should be 1. (no PWM) Although not yet implemented, we may use it for steering a water refill valve. Midi implementation: Dripper should listen to Note On + Velo commands for notes 0-11. The pincode command can be implemented as a binary midi controller >= 64 (on/off) The PWM mapped on volume controll. Candidates for this design: -Dripper -Tubi -Vibi (+ 2 stepping motors) [ needs note-off + release velocity implementation] -Belly -Rotomoton