Code Monkey home page Code Monkey logo

Comments (4)

tfry-git avatar tfry-git commented on July 23, 2024

I don't have a teensy, myself, so my answer is guesswork to a degree. But looking at the code, mozzi uses only ADC_0, and as far as I am aware, not all analog pins are accessible by both ADC units. Likely, this is what you are running into.

Fortunately, it seems rather straight-forward to set up non-synchronous ADC on teensy (and the ADC library is already required; https://github.com/pedvide/ADC). You should be able to use ADC_1, freely.

from mozzi.

sensorium avatar sensorium commented on July 23, 2024

from mozzi.

milan3000 avatar milan3000 commented on July 23, 2024

Thank you both for your help!
I looked through the analog.c and mozzi_analog.h channel mappings and quite frankly didn't understand too much at first. After realizing that the code differentiates the channel mapping based on the chip the Teensy is using, for instance
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
for the Teensy 3.6, I tried copying this whole chunk of code into the mozzi_analog.h file, which didn't work. As suggested by tfry-git, I looked into the ADC library and found this pin scheme:
https://forum.pjrc.com/attachment.php?attachmentid=11811&d=1508341808
which shows that the "problematic" pins are in fact connected to ADC1.

So by using the ADC Library
#include <ADC.h>
Creating an object of it
ADC *adc1 = new ADC();
And using the corresponding reading function
adc1->analogRead(pin) instead of mozziAnalogRead(pin)
the program works.
I am unsure, if this method of reading has disadvantages over the mozziAnalogRead(), since it says in the doc:
"mozziAnalogRead() reads the analog input of a chosen channel, without blocking other operations from running."
However I am calling the ADC reading in updateControl() at 64 Hz without problems so far.
So the issue is resolved and I can keep building the synth of my dreams.
Thank you very much again!

from mozzi.

tfry-git avatar tfry-git commented on July 23, 2024

adc->analogRead() waits for the conversion to complete before returning. I don't know how long that takes on teensy (by default). On the classic AVRs, it simply introduces too long delays. It might be quite ok on teensy, but if you're experiencing buffer underruns, that will be one of the first things to look into.

Alternatively, you can use non-blocking API:

adc->startSingleRead(..., ADC_1); 
[...] 
if (adc->isComplete(ADC_1)) {
    x = adc->readSingle(ADC_1);
} else {
    // keep using the previous value of x until the next iteration
}

It may be a bit cumbersome when reading multiple pins, but it should cause virtually no overhead.

from mozzi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.