Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <objdefs>
- <obj.normal id="4051 4x4" uuid="61f6605bb412dfc50f7ba959e7bdbaf8546fc56" sha="3615964f19c774fcbc059acafcad0e8b66ebd10a">
- <sDescription>4051 4x Inputs 4x Outputs(PA4)</sDescription>
- <author>rbrt</author>
- <license>BSD</license>
- <inlets>
- <frac32 name="i0"/>
- <frac32 name="i1"/>
- <frac32 name="i2"/>
- <frac32 name="i3"/>
- </inlets>
- <outlets>
- <frac32 name="o0"/>
- <frac32 name="o1"/>
- <frac32 name="o2"/>
- <frac32 name="o3"/>
- </outlets>
- <displays/>
- <params/>
- <attribs/>
- <code.declaration><![CDATA[
- int i;
- uint32_t z;
- uint32_t y;
- ]]></code.declaration>
- <code.init><![CDATA[
- i = 0 ;
- // 4051 pinout setup
- palSetPadMode(GPIOA,0,PAL_MODE_OUTPUT_PUSHPULL); // s0 Pin of 4051
- palSetPadMode(GPIOA,1,PAL_MODE_OUTPUT_PUSHPULL); // S1 Pin of 4051
- palSetPadMode(GPIOA,2,PAL_MODE_OUTPUT_PUSHPULL); // s2 Pin of 4051
- // Setup analog output A4
- palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); //axoloti analog out
- // Setup analog inputs A6, A7, B0, B1
- palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_ANALOG);
- palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_ANALOG);
- RCC->APB1ENR |= 0x20000000;
- DAC->CR |= 0x00030003;
- ]]></code.init>
- <code.krate><![CDATA[
- i ++; // count up
- if(i > 4){i = 0;} // Reset to 0, if i is greater than 4
- // set the 4051's destination
- palWritePad(GPIOA,0,((i& 0x01) > 0)); // write s0
- palWritePad(GPIOA,1,(((i>>1)& 0x01) > 0)); // write s1
- palWritePad(GPIOA,2,(((i>>2)& 0x01) > 0)); // write s2
- //selects input 1-4 AND writes to A4
- switch(i){
- case 0:
- DAC->DHR12R1 = inlet_i0 >>15;
- break;
- case 1:
- DAC->DHR12R1 = inlet_i1 >>15;
- break;
- case 2:
- DAC->DHR12R1 = inlet_i2 >>15;
- break;
- case 3:
- DAC->DHR12R1 = inlet_i3 >>15;
- break;
- default:
- DAC->DHR12R1 = inlet_i0 >>15;
- break;
- }
- // Reads and outputs analog values of A6, A7, B0, B1
- o1 = PalReadPad(GPIOA,6)<<15;
- o2 = PalReadPad(GPIOA,7)<<15;
- o3 = PalReadPad(GPIOB,0)<<15;
- o4 = PalReadPad(GPIOB,1)<<15;
- chThdSleepMilliseconds(5); // short delay
- ]]></code.krate>
- </obj.normal>
- </objdefs>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement