Shop OBEX P1 Docs P2 Docs Learn Events
4051 Multiplexer with Propeller — Parallax Forums

4051 Multiplexer with Propeller

axeonaxeon Posts: 7
edited 2012-09-16 21:22 in Propeller 1
Hello,

I was wondering if anyone might be able to point me in the right direction for info on using a 4051 analog mux with the Prop. I need info on connections and coding. (Couldn't seem to find schematic or code examples in the forum archive, or google).

I'd like to experiment with adding various resistive components (pots, fsr, photocells, etc.) via analog mux.

Thanks for any help or references.

Tony

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-09-15 19:35
    Can't really say that it is Prop specific so it belongs more to General discussions because you are asking for info on connections and coding plus this is your first post (Welcome!). First off, connections are really simple and you should be able to glean that information from the datasheets, app notes, etc. Second, since it is just a dumb chip there really isn't any coding involved other than a couple of dumb I/O lines to select the channel.

    Now, if you described your project in a little more detail and made it more interesting then maybe.....
  • StefanL38StefanL38 Posts: 2,292
    edited 2012-09-15 23:40
    Hi Axeon,

    welcome to the propeller-forum!

    The members in this forum are really friendly and patient even with the
    most basic questions. I often think the propeller-chip is a microcontroller
    that is attractive to people that are very open-minded and therefore patient.

    Please do the "medium-neewbees" a big favor and ask really basic questions that can be answered by "medium-newbees".

    If you look through the threads of this forum you will find basic questions
    and high advanced questions and threads. So this is a place for everyone.

    From beginners learning how to code for the first time up to assembler-tweaking-freakin-freaks
    doing things that make the brains of other assembler-tweaking-freaks SPIN in twisted-circles ;-)

    Parallax and the members of this forum always like to improve the
    "feel-at-home-factor" as much as possible.

    You wil NEVER get a "RTFM" (read that f... manual) as an answer.
    You will get good will and direct help or a detailed hints WHERE in the manual more detailed information can be found.

    So just start write a 10-20 lines description what you want to do and how far you did come and a question.
    In most cases it is good to add your code or datasheets as attachment.
    If others can see that you have tried even a little bit on your own and now have questions you will get answers.
    Start using the mentioned sources and come back as soon as you have a question.

    As a first simple start: Do you think you can connect some Propeller-IO-Pins to the 4051 and two voltage-dividers which produce different voltages then let a test-code switch the 4051 between
    the two analog inputs and measuring the voltage at the 4051-output to check if the switching is working?

    If this is "way above your head" please tell us your experience in coding and in electronics. We (the other forum-members) have to adapt our suggestions to your knowledge-level.

    Keep the questions coming

    best regards

    Stefan
  • axeonaxeon Posts: 7
    edited 2012-09-16 11:27
    Hello,

    Thanks very much. At first I was just thinking of using the Prop's RCTIME to read values from a few pots. However, I don't have enough pins left on my prop. So I looked around for something like the 4021 piso shift register, since I have previously used those to increase digital inputs. I thought the 4051 analog multiplexer is what I need to accomplish this for use with analog inputs?

    I know that using the 4051 mux to read analog inputs would preclude using RCTIME. I've attached a .gif of a schematic of what I would like to accomplish, however using pots instead of switches.

    The schematic image comes from a blog I found last night: http://electronihack.blogspot.com/.

    The author also provides demo code for reading in the analog 4051 (using switches as inputs). Now, although this is helpful, I thought why would you use an anlog mux to read in digital values? (To me, a switch is a digital component, no?) Why not instead use a 4021 shift register in that case?
    I thought the analog mux would be more suited for analog input readings, like pots, not switches?

    So, I thought I would use the example there and just replace those switches in the schematic with pots and change the code a little.

    Please let me know if I've got this all wrong.

    Thanks again for your help,
    Tony
    1024 x 495 - 44K
  • kwinnkwinn Posts: 8,697
    edited 2012-09-16 11:45
    No reason not to use an analog mux for switches. It works just as well as a digital mux or shift register.

    You can use the '4051 to measure the RC time constant of all 8 channels if you have 4 prop pins available. I can post a schematic if you are interested.

    PS - Not sure if RCtime can be used as is. It may need a small change to select the channel, or you may be able to select the channel just before calling RCtime.
  • StefanL38StefanL38 Posts: 2,292
    edited 2012-09-16 12:15
    Hi Axeon,

    please give us an overview about your project. The pots are not a self purpose. The pots are used as input-devices. What kind of input DATA does your code receive from the pots?

    As soon as you give us an overview new ideas will drive in how the same purpose can be done in alternative (and often easier) ways.

    best regards
    Stefan
  • LeonLeon Posts: 7,620
    edited 2012-09-16 13:09
    Using an ADC with several channels would be more sensible.
  • axeonaxeon Posts: 7
    edited 2012-09-16 13:27
    kwinn wrote: »
    You can use the '4051 to measure the RC time constant of all 8 channels if you have 4 prop pins available. I can post a schematic if you are interested.

    PS - Not sure if RCtime can be used as is. It may need a small change to select the channel, or you may be able to select the channel just before calling RCtime.

    That would be great if you could post the schematic. That is what I'd like to do, use all 8 channels.

    I would like to experiment with detecting "touch" by measuring the R/C time constant as was demonstrated here: http://gadgetgangster.com/news/56-jeffs-shop/541-bananaphone-a-touch-capacitance-synth.html. This demo uses "Touch Buttons.spin" The code that reads the R/C time constant is written mostly in PropASM, at least the part of the code that actually does the measuring (I think).

    I'd like to exclude the bananas, and expand my pins through the use of the 4051 analog mux. I don't know how the prop would read input from the 4051. Would measuring R/C time still be the way to go here?
    CON
    
      BUTTON_PINS   = $FF           ' The QuickStart's touch buttons are on the eight LSBs
      SAMPLES       = 32                 ' Require 32 high redings to return true
    
    
    VAR
      
      long  Results
    
    
    PUB Start(Rate)
    
      Results := Rate
      cognew(@Entry, @Results)      ' Launch a new cog to read samples
    
    
    PUB State | Accumulator
    
      Accumulator := Results        ' Sample multiple times and return true
      repeat constant(SAMPLES - 1)  '  if every sample was highw
        Accumulator &= Results
      return Accumulator
    
    
    DAT
    
                            org
    Entry                                                                                                                                    
                  rdlong    WaitTime, par
                  mov       outa, #BUTTON_PINS              ' set TestPins high, but keep as inputs
    
                  mov       Wait, cnt                       ' preset the counter
                  add       Wait, WaitTime
    Loop
                  or        dira, #BUTTON_PINS              ' set TestPins as outputs (high)
                  andn      dira, #BUTTON_PINS              ' set TestPins as inputs (floating)
                  mov       Reading, #BUTTON_PINS           ' create a mask of applicable pins
                  waitcnt   Wait, WaitTime                  ' wait for the voltage to decay
                  andn      Reading, ina                    ' clear decayed pins from the mask
                  wrlong    Reading, par                    ' write the result to RAM
                  jmp       #Loop
    
    Reading       res       1
    WaitTime      res       1
    Wait          res       1
    
    
  • axeonaxeon Posts: 7
    edited 2012-09-16 13:30
    Leon wrote: »
    Using an ADC with several channels would be more sensible.

    Thanks again. Yes, I'm thinking this might be a better way.
  • kwinnkwinn Posts: 8,697
    edited 2012-09-16 18:16
    Touch sensing is a bit different than measuring a pot position using RCtime. Take a look at the touch switch circuitry on the QuickStart board. You can probably use the '4051 to read each switch in turn rather than all 8 in parallel as they did on that board. One pin needed as input data and 3 pins required to select the switch to read.

    PS You can also use the Touch Buttons object with some minor changes to read the state of the buttons.
  • AribaAriba Posts: 2,690
    edited 2012-09-16 20:55
    Here is a schematic and a code to measure 8 variable resistors with a 4051 multiplexer.
    You can vary the capacitor and the variable resistors, the 1nF and 10kOhm are just possible values. With 100kOhm or 1MOhm the measured values will be higher. With a lower capacitor the values will be lower.

    attachment.php?attachmentid=95663&d=1347910576
    CON
      _clkmode  = xtal1 + pll16x
      _xinfreq  = 5_000_000
    
    OBJ
      dbg :  "FullDuplexSerial"
          
    PUB Main : val
      dbg.start(31,30,0,115200)     'debug with PST
      dira[2..0] := %111            'Select pins = output
      ctra := %01100 << 26 + 3      'counter A in NEGDetect mode
      frqa := 1
      repeat
        val := getPot(0)
        dbg.str(string(13,"Pot 0 ="))
        dbg.dec(val)
        val := getPot(1)
        dbg.str(string(13,"Pot 1 ="))
        dbg.dec(val)
        val := getPot(7)
        dbg.str(string(13,"Pot 7 ="))
        dbg.dec(val)
        waitcnt(clkfreq + cnt)
    
    PUB getPot(num)
      outa[2..0] := num             'select channel
      outa[3] := 0                  'discharge 1nF C
      dira[3] := 1                  'P3 = output
      waitcnt(clkfreq/10000 + cnt)  'wait 100us
      phsa := 0
      dira[3] := 0                  'P3=input = start measuring
      waitpeq(1<<3, 1<<3, 0)        'wait until P3 high
      return phsa                   'value in phsa
    
    Copy and paste the code into the PropTool. The code is not full tested (only without a 4051).
    The channels you use in the main code must have a resistor connected, otherwise the getPot methode will wait forever.

    Andy
    298 x 209 - 2K
  • axeonaxeon Posts: 7
    edited 2012-09-16 21:22
    This is great, thanks very much. I did try and use the diagram and code that I posted above from the "Electronihack" blog. It does work, however that code is specifically for reading in switches. I will examine and implement the code/schematic given to me here, as well as checking out the QuickStart board to learn its method of touch sensing.

    Sincere thanks,
    Tony
Sign In or Register to comment.