Advertisement
Herrpaule

Axoloti 4051 4x outs 4 ins

Feb 19th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.67 KB | None | 0 0
  1. <objdefs>
  2.    <obj.normal id="4051 4x4" uuid="61f6605bb412dfc50f7ba959e7bdbaf8546fc56" sha="3615964f19c774fcbc059acafcad0e8b66ebd10a">
  3.       <sDescription>4051 4x Inputs 4x Outputs(PA4)</sDescription>
  4.       <author>rbrt</author>
  5.       <license>BSD</license>
  6.       <inlets>
  7.          <frac32 name="i0"/>
  8.          <frac32 name="i1"/>
  9.          <frac32 name="i2"/>
  10.          <frac32 name="i3"/>
  11.       </inlets>
  12.       <outlets>
  13.          <frac32 name="o0"/>
  14.          <frac32 name="o1"/>
  15.          <frac32 name="o2"/>
  16.          <frac32 name="o3"/>
  17.       </outlets>
  18.       <displays/>
  19.       <params/>
  20.       <attribs/>
  21.       <code.declaration><![CDATA[  
  22.        int i;
  23.        uint32_t z;
  24.        uint32_t y;
  25.      ]]></code.declaration>
  26.       <code.init><![CDATA[
  27.        i = 0 ;
  28.  
  29.        // 4051 pinout setup
  30.         palSetPadMode(GPIOA,0,PAL_MODE_OUTPUT_PUSHPULL);    // s0 Pin of 4051
  31.        palSetPadMode(GPIOA,1,PAL_MODE_OUTPUT_PUSHPULL);    // S1 Pin of 4051
  32.        palSetPadMode(GPIOA,2,PAL_MODE_OUTPUT_PUSHPULL);    // s2 Pin of 4051
  33.  
  34.        // Setup analog output A4
  35.         palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);     //axoloti analog out
  36.        
  37.        // Setup analog inputs A6, A7, B0, B1
  38.        palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_ANALOG);
  39.         palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_ANALOG);
  40.        palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_ANALOG);
  41.        palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_ANALOG);
  42.  
  43.        RCC->APB1ENR |= 0x20000000;
  44.         DAC->CR |= 0x00030003; 
  45.      ]]></code.init>
  46.       <code.krate><![CDATA[
  47.        i ++;              // count up
  48.        if(i > 4){i = 0;}  // Reset to 0, if i is greater than 4
  49.  
  50.        // set the 4051's destination
  51.         palWritePad(GPIOA,0,((i& 0x01) > 0));           // write s0
  52.         palWritePad(GPIOA,1,(((i>>1)& 0x01) > 0));  // write s1
  53.         palWritePad(GPIOA,2,(((i>>2)& 0x01) > 0));  // write s2
  54.  
  55.  
  56.        //selects input 1-4 AND writes to A4
  57.        switch(i){
  58.          case 0:
  59.            DAC->DHR12R1 = inlet_i0 >>15;
  60.          break;
  61.          case 1:
  62.            DAC->DHR12R1 = inlet_i1 >>15;
  63.          break;
  64.          case 2:
  65.            DAC->DHR12R1 = inlet_i2 >>15;
  66.          break;
  67.          case 3:
  68.            DAC->DHR12R1 = inlet_i3 >>15;
  69.          break;
  70.          default:
  71.            DAC->DHR12R1 = inlet_i0 >>15;
  72.          break;
  73.        }
  74.  
  75.        // Reads and outputs analog values of A6, A7, B0, B1
  76.        o1 = PalReadPad(GPIOA,6)<<15;
  77.        o2 = PalReadPad(GPIOA,7)<<15;
  78.        o3 = PalReadPad(GPIOB,0)<<15;
  79.        o4 = PalReadPad(GPIOB,1)<<15;
  80.  
  81.        chThdSleepMilliseconds(5);  // short delay
  82.      ]]></code.krate>
  83.    </obj.normal>
  84. </objdefs>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement