'******************************************************* '* Armite Software * '* data acquisition code for midi controllers * '* HY1 hybrid sensor * '* by * '* dr.Godfried-Willem Raes * '* version 2.1 * '******************************************************* ' Program history: ' 29.09.2007: Version 1.0 - convert and transmit continously ' Two sensor channels on pins 16 and 17 ' We cannot get the 8 available channels... ' 30.09.2007: Try using AD(0)-AD(7) syntax. Documentation is very confused ' in this point. Now it works fine. ' New design for a one-dimensional sensor ' Using a Pepperl+Fuchs sonar and a KMY24 Siemens radar sensor on 2.47GHz ' Output channel 0 = distance (Pulsed Sonar Measurement) ' Output channel 1 = doppler frequency phase a (Tacho 1) ' Output channel 2 = doppler frequency phase b (Tacho 2) ' Output channel 3 = doppler amplitude phase a (True RMS 1) ' Output channel 4 = doppler amplitude phase b (True RMS 2) ' Sampling rate 10S/s per channel. Data rate: 50 measurements/second or 150 bytes/second. ' 02.10.2007: parts soldered on prototype area: dip switch, 74HCT14 chip and midi out connection ' 03.10.2007: Prototype board with radar 2.4GHz sensor and analog computer soldered and tested. ' 04,10.2007: Stainless steel chassis welded and components mounted. ' First tests: processor works, sonar works, radar works but midi out fails... ' 05.10.2007: Hardware o.k. now. Seems working with midi out. ' Start implementation of listen task in GMT ' 06.10.2007: GMT g_lib.dll upgraded with support for this sensor. ' application test code added in g_interfaces (g_sens.exe compilation) ' 07.10.2007: Midimon reports nothing but errors in the serial data stream... ' this due to the serout instruction. ' Changing back to TXD(0) made verything work fine. ' 09.10.2007: Intelligent surface calculation implemented. ' This version uploaded in ARM processor. ' 12.10.2007: scaling changed to compensate for assymmetry in radar amplitudes. ' program flashed. 16h00 ' bug: amplitude 2 returns nothing but zero's now... - this was a typo... ' program flashed. 16h40 ' bug: surface2 must have a scaling bug - two times >>7 was the bug... ' program flashed. 17h15 ' the surfaces values with valid distance can still be multiplied by 2 ' implemented. now >>16 after quadratic law. ' flashed 17h30 ' 13.10.2007: correction scaling for amplitude channel 2 changed, now factor * 2.1575 ' 15.10.2007: changed: internal sampling rate for tacho channels is now 40S/s ' changed: internal sampling for amplitude channels is now 20S/s ' data output remains 10S/s for each data channel. DIR(0) = 1 ' output pin - for midi output DIR(11) = 0 ' midi channel select pins msb (bit 3) DIR(12) = 0 ' midi channel select bit 2 DIR(13) = 0 ' midi channel select bit 1 DIR(14) = 0 ' midi channel lsb (bit 0) DIR(15) = 1 ' on board LED BAUD(0) = 31250 ' midi baudrate, transmit using pin 0 kanaal = 15 ' midi channel - low nibble status byte ' read from dip switch setting statusbyte = 160 ' 160 voor poly aftertouch - high nibble status byte lsb = 0 msb = 0 distance = 0 afstand = 0 tacho1 = 0 tacho2 = 0 amp1 = 0 amp2 = 0 valid = 1 ' becomes 0 when distance cannot be measured. ' read dip switches for midi channel used for transmit ' note: this is signed integer basic: true = -1 IF IN(14) > -1 THEN kanaal = kanaal - 1 'OR 1 IF IN(13) > -1 THEN kanaal = kanaal - 2 'OR 2 IF IN(12) > -1 THEN kanaal = kanaal - 4 'OR 4 IF IN(11) > -1 THEN kanaal = kanaal - 8 'OR 8 statusbyte = statusbyte + kanaal ' other input pins can be used for program selection on startup ' for debug: 'PRINT kanaal 'PRINT statusbyte 'PRINT BAUD(0) ' for debug 'DAQ:- hardware connections and mapping ' AD(0) = Pepperl+Fuchs distance data brown ' AD(1) = Radar speed data from tacho phase 1 red ' AD(2) = Radar speed data from tacho phase 2 orange ' AD(3) = Radar surface data phase 1 yellow ' AD(4) = Radar surface data phase 2 green ' AD(5) = NC blue ' may later be used for Sharp trigonometric infrared sensor. (20cm - 150cm) ' on entry for startup: tacho1 = AD(1) + AD(1) + AD(1) ' 3 samples - pin 17 tacho2 = AD(2) + AD(2) + AD(2) ' pin 18 amp1 = AD(3) ' pin 19 amp2 = AD(4) ' pin 20 DO ' pseudo simultaneous sampling update of all channels distance = AD(0) ' pin 16 6 microseconds conversion time sampled at 10S/s ' tacho channels sampled at 40S/s tacho1 = tacho1 + AD(1) ' now 12 bits - sum of 4 new values ==> 12 bits tacho2 = tacho2 + AD(2) ' now 12 bits amp1 = amp1 + AD(3) ' now 11 bits amp2 = amp2 + AD(4) ' now 11 bits ' now: ca. 30 microseconds of sampling ' data is returned in a word format (2 bytes, 10-bit alligned left) ' now we have to convert this into a set of 2 7-bit values distance = distance >> 6 ' shift data 6 bits to the right, save 10 bits resolution ' cfr. ARM basic manual: bits 0-5 are not used afstand = distance ' save 10 bit value for calculation of surface. valid = 1 IF afstand = 0 THEN valid = 0 IF afstand >= 1023 THEN valid = 0 lsb = distance AND 127 ' 7 bit value for midi lsb distance = distance >> 7 ' shift data 7 bits, so msb will have the remaining 3 bits msb = distance ' msb = (n * 16) + a ' the low 3 bits are the msb for the value, the low 3 bits in the high nibble are ' the ADC channel we are sampling ' so: bits 0,1,2 are data - bit 3 is always 0 ' bits 4,5,6 are data channel data, bit 7 is always 0 ' Transmit midi TXD(0) = CHR(statusbyte) ' should take 320 microseconds 32 microcesonds for each bit TXD(0) = CHR(msb) TXD(0) = CHR(lsb) ' so sending the 3 bytes takes ca. 1ms ' now the tacho channels: ' tacho 1: tacho1 = tacho1 + (tacho1 / 2) ' rescale 12.10.2007 tacho1 = tacho1 >> 8 ' save 10 bits resolution, we had twelve, taking 4 samples IF tacho1 > 1023 THEN tacho1 = 1023 ' limiter lsb = tacho1 AND 127 tacho1 = tacho1 >> 7 msb = tacho1 OR 16 ' hi nibble 0001 ' Transmit: TXD(0) = CHR(statusbyte) TXD(0) = CHR(msb) TXD(0) = CHR(lsb) ' tacho 2: tacho2 = tacho2 + (tacho2 / 2) ' rescale 12.10.2007 tacho2 = tacho2 >> 8 ' 7 '6 IF tacho2 > 1023 THEN tacho2 = 1023 lsb = tacho2 AND 127 tacho2 = tacho2 >> 7 msb = tacho1 OR 32 ' hi nibble 0010 ' Transmit: TXD(0) = CHR(statusbyte) TXD(0) = CHR(msb) TXD(0) = CHR(lsb) ' amplitude channel 1: amp1 = amp1 + (amp1 / 2) ' rescale value with factor 1.5 amp1 = amp1 >> 7 ' make 10 bits ' tot 12.10: 'amp2 = amp2 + amp2 + (amp2 / 2 ) ' rescale value with factor 2.5 - take radar assymmetry into account ' scaling factor moet 2.1575 zijn (na meting 13.10.2007, dus in integer math: amp2 = (amp2 * 2157) / 1000 amp2 = amp2 >> 7 ' IF amp1 > 1023 THEN amp1 = 1023 ' limit IF amp2 > 1023 THEN amp2 = 1023 IF valid = 0 THEN lsb = amp1 AND 127 amp1 = amp1 >> 7 msb = amp1 OR 48 ' hi nibble 0011 ' Transmit: TXD(0) = CHR(statusbyte) TXD(0) = CHR(msb) TXD(0) = CHR(lsb) ' amplitude channel 2: lsb = amp2 AND 127 amp2 = amp2 >> 7 msb = amp2 OR 64 ' hi nibble 0100 ' Transmit: TXD(0) = CHR(statusbyte) TXD(0) = CHR(msb) TXD(0) = CHR(lsb) ELSE ' in this case we can calculate the surface exactly, since the distance is known amp1 = afstand * afstand * amp1 ' 31 bits, so will stay unsigned within 32 bit long amp1 = amp1 >> 16 ' eigenlijk >> 20 reduce again to 10 bits ' >> 17 is acht maal te groot, maar dat is een recaling 12.10.2007 - 1 ' >> 16 is zestien maal te groot, maar dekt wel het 10 bit bereik nu IF amp1 > 1023 THEN amp1 = 1023 ' limiter lsb = amp1 AND 127 amp1 = amp1 >> 7 msb = amp1 OR 48 ' hi nibble 0011 ' Transmit: TXD(0) = CHR(statusbyte) TXD(0) = CHR(msb) TXD(0) = CHR(lsb) ' amplitude channel/phase 2: amp2 = afstand * afstand * amp2 amp2 = amp2 >> 16 ' >> 20 IF amp2 > 1023 THEN amp2 = 1023 'limit lsb = amp2 AND 127 amp2 = amp2 >> 7 msb = amp2 OR 64 ' hi nibble 0100 'Transmit: TXD(0) = CHR(statusbyte) TXD(0) = CHR(msb) TXD(0) = CHR(lsb) ENDIF ' WAIT 94 ' cycle rate - 10 bursts per second (100ms - time for the above statements) ' measured: 50.3 S/s ' new 15.10: sample tachos 4 times faster: (40S/s) ' surface 2 times faster: 20S/s wait 31 tacho1 = AD(1) ' 10 bits tacho2 = AD(2) wait 31 tacho1 = tacho1 + AD(1) ' 11 bits tacho2 = tacho2 + AD(2) amp1 = AD(3) ' 10 bits amp2 = AD(4) wait 31 tacho1 = tacho1 + AD(1) ' 3 values... tacho2 = tacho2 + AD(2) ' the 4th value, needed to make a 12 bit number, is added on entry of the DAQ loop LOOP END