Advertisement
Herrpaule

euxoloti adc object

Feb 19th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 6.28 KB | None | 0 0
  1. <objdefs>
  2.    <obj.normal
  3.         id="CVs and POTs"
  4.         uuid="1e50a73f3460a00a630adb4c31ad60313c82905f"
  5.         sha="d5a077d1b5892162ec9cfa7db5eecc1657bde893">
  6.       <upgradeSha>26b0e9edf07d4a6d8f04db3682899c48c85cc389</upgradeSha>
  7.       <sDescription>reads pots and cv inputs of euxoloti</sDescription>
  8.       <author>Paul</author>
  9.       <license>BSD</license>
  10.  
  11.       <inlets/>
  12.  
  13.       <outlets>
  14.          <frac32 name="cv1"/>
  15.          <frac32 name="cv2"/>
  16.          <frac32 name="cv3"/>
  17.          <frac32 name="cv4"/>
  18.          <frac32 name="cv5"/>
  19.          <frac32 name="cv6"/>
  20.          <frac32 name="cv7"/>
  21.          <frac32 name="cv8"/>
  22.  
  23.          <frac32 name="pot1"/>
  24.          <frac32 name="pot2"/>
  25.          <frac32 name="pot3"/>
  26.          <frac32 name="pot4"/>
  27.          <frac32 name="pot5"/>
  28.          <frac32 name="pot6"/>
  29.          <frac32 name="pot7"/>
  30.          <frac32 name="pot8"/>
  31.       </outlets>
  32.  
  33.       <displays/>
  34.       <params/>
  35.  
  36.       <attribs>
  37.          <combo name="clock_polarity">
  38.             <MenuEntries>
  39.                <string>CPOL=0</string>
  40.             </MenuEntries>
  41.  
  42.             <CEntries>
  43.                <string></string>
  44.             </CEntries>
  45.          </combo>
  46.  
  47.          <combo name="clock_phase">
  48.             <MenuEntries>
  49.                <string>CPHA=0</string>
  50.             </MenuEntries>
  51.  
  52.             <CEntries>
  53.                <string></string>
  54.             </CEntries>
  55.          </combo>
  56.  
  57.          <combo name="baudrate">
  58.             <MenuEntries>  
  59.                <string>FPCLK/64</string>
  60.             </MenuEntries>
  61.  
  62.             <CEntries>
  63.                <string>|(5&lt;&lt;3)</string>
  64.             </CEntries>
  65.          </combo>
  66.  
  67.          <combo name="format">
  68.             <MenuEntries>
  69.                <string>LSB first</string>
  70.             </MenuEntries>
  71.  
  72.             <CEntries>
  73.                <string>|SPI_CR1_LSBFIRST</string>
  74.             </CEntries>
  75.          </combo>
  76.  
  77.       </attribs>
  78.  
  79.       <includes/>
  80.  
  81.       <code.declaration><![CDATA[
  82.         uint8_t *txbuf;
  83.         uint8_t *rxbuf;
  84.         uint32_t z;
  85.         uint8_t pin;
  86.  
  87.         uint32_t pot1, pot2, pot3, pot4, pot5, pot6, pot7, pot8;
  88.         uint32_t cv1, cv2, cv3, cv4, cv5, cv6, cv7, cv8;
  89.      ]]></code.declaration>
  90.      
  91.       <code.init><![CDATA[
  92.  
  93.         //org. from spi.axo
  94.         // setup the spi pins
  95.         palSetPadMode(GPIOA, 4, PAL_MODE_OUTPUT_PUSHPULL);// NSS
  96.         palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL);// SCK
  97.         palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL);// MOSI
  98.         //palSetPadMode(GPIOA, 4, PAL_MODE_ALTERNATE(5));// NSS
  99.         palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(5));// SCK
  100.         palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5));// MISO
  101.         palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(5));// MOSI
  102.  
  103.         static const SPIConfig spicfg =
  104.            {NULL, GPIOA, 4, 0 attr_clock__polarity attr_clock__phase attr_baudrate attr_format};
  105.         // end spi.axo
  106.  
  107.         static uint8_t _txbuf[8] __attribute__ ((section (".sram2")));
  108.         static uint8_t _rxbuf[8] __attribute__ ((section (".sram2")));
  109.         txbuf = _txbuf;
  110.         rxbuf = _rxbuf;
  111.  
  112.         // ADC2 CS2 PIN(CV IN)
  113.         palSetPadMode(GPIOA,2,PAL_MODE_OUTPUT_PUSHPULL);
  114.         palWritePad(GPIOA,2,1);
  115.         // ADC1 CS1 PIN(CV IN)
  116.         palSetPadMode(GPIOA,3,PAL_MODE_OUTPUT_PUSHPULL);
  117.         palWritePad(GPIOA,3,1);
  118.  
  119.         pin = 0;  
  120.  
  121.         spiStart(&SPID1, &spicfg); // org. from spi.axo
  122.      ]]></code.init>    
  123.  
  124.       <code.krate><![CDATA[
  125.         txbuf[2] = 0b00000000;
  126.  
  127.         for(int pin=0; pin<8; pin++){
  128.    
  129.            txbuf[0] = pin < 4 ? 0b01100000 : 0b11100000;
  130.    
  131.            if (pin % 4 == 0) { txbuf[1] = 0b00000000; }
  132.            else if (pin % 4 == 1) { txbuf[1] = 0b00000010; }
  133.            else if (pin % 4 == 2) { txbuf[1] = 0b00000001; }
  134.            else { txbuf[1] = 0b00000011;}
  135.      
  136.            palWritePad(GPIOA,3,0);
  137.            spiSelect(&SPID1);    
  138.            spiSend(&SPID1,3,txbuf);
  139.            spiReceive(&SPID1,3,rxbuf);
  140.            spiUnselect(&SPID1);
  141.            palWritePad(GPIOA,3,1);
  142.  
  143.            z = (rxbuf[1] << 8| rxbuf[0]) << 16;
  144.  
  145.            switch (pin) {
  146.               case 0: outlet_pot2 = z; break;
  147.               case 1: outlet_pot1 = z; break;
  148.               case 2: outlet_pot3 = z; break;
  149.               case 3: outlet_pot4 = z; break;
  150.               case 4: outlet_pot6 = z; break;
  151.               case 5: outlet_pot5 = z; break;
  152.               case 6: outlet_pot7 = z; break;
  153.               case 7: outlet_pot8 = z; break;
  154.            }
  155.         }
  156.        
  157.         txbuf[2] = 0b00000000;
  158.      
  159.         for(int pin=0; pin<8; pin++){
  160.    
  161.            txbuf[0] = pin < 4 ? 0b01100000 : 0b11100000;
  162.    
  163.            if (pin % 4 == 0) { txbuf[1] = 0b00000000; }
  164.            else if (pin % 4 == 1) { txbuf[1] = 0b00000010; }
  165.            else if (pin % 4 == 2) { txbuf[1] = 0b00000001; }
  166.            else { txbuf[1] = 0b00000011;}
  167.        
  168.            palWritePad(GPIOA,2,0);
  169.            spiSelect(&SPID1);      
  170.            spiSend(&SPID1,3,txbuf);
  171.            spiReceive(&SPID1,3,rxbuf);
  172.            spiUnselect(&SPID1);
  173.            palWritePad(GPIOA,2,1);
  174.  
  175.            z = 0x07FFFFFF - ((rxbuf[1] << 8| rxbuf[0]) << 16);
  176.      
  177.      
  178.            switch (pin) {
  179.               case 0: outlet_cv1 = z; break;
  180.               case 1: outlet_cv2 = z; break;
  181.               case 2: outlet_cv3 = z; break;
  182.               case 3: outlet_cv4 = z; break;
  183.               case 4: outlet_cv5 = z; break;
  184.               case 5: outlet_cv6 = z; break;
  185.               case 6: outlet_cv7 = z; break;
  186.               case 7: outlet_cv8 = z; break;
  187.            }
  188.        
  189.            chThdSleepMilliseconds(5);
  190.         }
  191.      ]]></code.krate>
  192.  
  193.       <code.srate><![CDATA[
  194.      ]]></code.srate>
  195.  
  196.       <code.dispose><![CDATA[
  197.         //org. from spi.axo
  198.         spiStop(&SPID1);
  199.         palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
  200.         palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
  201.         palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_ANALOG);
  202.         palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_ANALOG);
  203.         // end spi.axo
  204.      ]]></code.dispose>
  205.      
  206.    </obj.normal>
  207. </objdefs>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement