Hi everyone,
here is a short example for a 4051 de/multiplexer. The 4051 can be used for extra 8 analog outputs or inputs. The Y0-7 pins are choosen by HIGH/LOW state of the S0-2 pins. It's not the fastest way to expand the analog input or output, but the IC are very cheap and I own a lot of them
It's good thing to decouple the analog inputs and VCC with a 100n capacitor.
A MCP3008 or MCP3208 SPI is much faster and has an input protection build in. An examples for this IC will be followed the next week.
Check hesspet important hint about 4051 characteristics on this thread.
By editing the number between the brace at line "adcvalues[8]", you can select the adc input pin.
Here is a short overview about the possible adc pins.
PA1 (ADC1_IN1) = 1
PA2 (ADC1_IN2) = 2
PA3 (ADC1_IN3) = 3
PA4 (ADC1_IN4) = 4
PA5 (ADC1_IN5) = 5
PA6 (ADC1_IN6) = 6
PA7 (ADC1_IN7) = 7
PB0 (ADC1_IN8) = 8
PB1 (ADC1_IN9) = 9
PC0 (ADC1_IN10) = 10
PC1 (ADC1_IN11) = 11
PC2 (ADC1_IN12) = 12
PC3 (ADC1_IN13) = 13
PC4 (ADC1_IN14) = 14
Download Patch: 4051 demultiplex.axp (4.6 KB)
Schematic: