Problems with Multiplexer and Mozzi

185 views
Skip to first unread message

Dennis Schönhof

unread,
Sep 22, 2013, 9:28:30 AM9/22/13
to mozzi...@googlegroups.com
Hey guys, I'm having a problem that I'm unable to solve.
I'm trying to read on my Arduino some analog values from two different potis with the 4051 Multiplexer. The potis are connected to y0 and y1 on the Multiplexer. The Multiplexer is connected to Analog In 1
The only problem here is that my Arduino only reads the values from the poti that I choose last.
Here is the relevant part of my code:

  choosePoti(0);
  volumeSensor = mozziAnalogRead(1);
  choosePoti(1);
  frequencySensor = mozziAnalogRead(1);

Now if I control the poti on y1 (frequencySensor) I can control volume and frequency with the same poti. If I turn the code around and change it to this:
  
  choosePoti(1);
  frequencySensor = mozziAnalogRead(1);
  choosePoti(0);
  volumeSensor = mozziAnalogRead(1);
  
I control frequency and volume with the volume poti.
Does anyone now whats going on here?

Tim Barrass

unread,
Sep 22, 2013, 8:08:32 PM9/22/13
to mozzi...@googlegroups.com
Hi Dennis,
thanks for the question, you've uncovered an issue with the way mozziAnalogRead() currently works.

mozziAnalogRead(channel) retrieves the reading from an array which holds one reading for each channel, and then puts the channel you specify onto a stack to be read in the background, returning with an interrupt instead of wasting processor time waiting in a loop, each time updateControl() is called.

So when you use the same channel twice in updateControl(), you will be retrieving the same reading twice from the array.

There are a couple of workarounds. 

One option is to change the pot only once each updateControl().  That will keep the efficiency of mozziAnalogRead(), but make longer intervals between your readings as you cycle through your multiplexed pots one at a time.

Or you can edit MozziGuts.cpp so you can use ordinary analogRead(). 
Look for:

    static void updateControlWithAutoADC()
    {
        updateControl();
        adcStartReadCycle();
    }

and comment out adcStartReadCycle();

In the same file, find

    void startMozzi(int control_rate_hz)

and comment out setupMozziADC() in that function.  That will now prevent the ADC interrupt being configured.

You can then use setupFastAnalogRead() in your setup() to get faster conversion times for ordinary analogRead().

Maybe it should become a Mozzi config option for situations like yours...


I hope that helps.
TIm




--
You received this message because you are subscribed to the Google Groups "Mozzi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
To post to this group, send an email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/af722350-3a1d-49a2-a896-1686fd7ea31d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dennis Schönhof

unread,
Sep 23, 2013, 4:28:53 AM9/23/13
to mozzi...@googlegroups.com
I really have to thank you!
Now I can continue with my project and I have learned something new about Mozzi. Thanks!
Reply all
Reply to author
Forward
0 new messages