Hey Folks,
I have a pretty big project: a complete standalone synth unit with recycled old cheap keyboard keys and a ton of potis and switches all hooked up on a teensy 3.5.
Since i am running out of pins i am relying on muxes and gpio expanders. Whereas the first are easy to handle the latter (using 2 mcp23017s) are wired up via i2c to do keyboard mapping and various other stuff. I really need (probably a very generic statement ) my loop() to go as quick as possible. Due to the size of the project and my own hardware pcb designs etc it is not quite easy to give MWEs for this forum. But i am having 2 quite general and non-related questions, i hope this is the right way of posting this:
First - I2C communication rates:
- I have a teensy 3.5 with audio shield hooked up on a self designed pcb. The i2c (scl0 sda0) is shared for both mcp23017s and pulled up via external resistors (do the resistor sizes limit speed?) the wires aka pcb lines are basically as short as it gets. I am using the i2c_t3 library and the datasheet of the mcps states i2c rates 100k 400k, 1.7M Hz. But it doesnt matter what i change in the code (ie rate on the teensy) the loop that involves the i2c communications always takes up the same amount of time, i somehow have the feeling that any rate change in code does not do any difference...
---> HINT: For all just flying over the text and might be looking for something related to their problem: i got rid of the MCP23017 adafruit library, it produces massive latency. Just reading out my keybed with the i2c_t3 library wire commands takes ~4.5 ms in total (independent for some reason on i2c rate) but took ~80 ms with the adafruit MCP library!!
Can anyone give me a hint what i need to do in order to achieve quicker i2c rates for the mcp communications or experienced something similar? just setting and reading out a couple of digital pins shouldnt introduce ~ 5ms latency per loop. It would probably be alright for the project since overall i am running with ~9 ms per loop for all control stuff (i.e. keys and changing pots and switches) which is not noticeable in the use case. But even my adc mux reads only take about 40 us in total each go. So i would really like to up the digital IO game
I thought this is what does the trick i'nit?
Second:
- I am looking for proper amplitude modulation of my waves (running with 3 oscillators + 1 noise object through a hell of a lot of stuff) and i would look into coding it myself into the waveform objects but wanted to ask here first before maybe reinventing the wheel:
I have not found a way of just creating a simple LFO to control my output volume.
I used an amp object and updated the gain with a ~20 - 40 sample wavetable for OKish results but cant update quick enough due to my overall loop() function timing. So i get glitches on really low (due to limited sample number) and very high (due to limited update rate) LFO rates.
The multiply object doesnt do either (even though the documentation pretends) since it basically is a ring modulator: multiplying two waves does not simply create a wave with an envelope but due to trigonometrics (for the simple case of sine waves):
sin(x)sin= 1/ 2 [cos(x−y)−cos(x+y)],
inputting an 10 Hz LFO and my previously (through a lot of steps) modulated multi wave object (say playing a note A = 440 Hz) i get a 450Hz and 430Hz split output, i.e. i am detuning the note up and down rather than modulating its amplitude. This is a separate feature of my synth but not what i want when trying to copy analog VCA.
Can someone help or hint me on how to do this?! I want the LFO to control the output amplitude of the sound!
Apart from that: I have built a case now, holding it all together, i am constantly trying to optimize the code , still with multiple branches on my git open . I will redo the schematics and pcb files (for the teensy with a power circuit, MIDI IO, gpio expanders and all necessary plugs and separately some basic "modules" with a 8 ch multiplexer each, holding pots and various other stuff, for "easy" modular "build your own" design ), and it will all be up and available on github in the near future. For now i have a monophonic unit but with the power of the later teensys it shouldnt be impossible to do a polyphonic version. I am really excited and will let you all know (in case you want to ),
since i profitted a lot from the audio tool and from the forum!
Thanks in advance and all the best!
Jochen
I have a pretty big project: a complete standalone synth unit with recycled old cheap keyboard keys and a ton of potis and switches all hooked up on a teensy 3.5.
Since i am running out of pins i am relying on muxes and gpio expanders. Whereas the first are easy to handle the latter (using 2 mcp23017s) are wired up via i2c to do keyboard mapping and various other stuff. I really need (probably a very generic statement ) my loop() to go as quick as possible. Due to the size of the project and my own hardware pcb designs etc it is not quite easy to give MWEs for this forum. But i am having 2 quite general and non-related questions, i hope this is the right way of posting this:
First - I2C communication rates:
- I have a teensy 3.5 with audio shield hooked up on a self designed pcb. The i2c (scl0 sda0) is shared for both mcp23017s and pulled up via external resistors (do the resistor sizes limit speed?) the wires aka pcb lines are basically as short as it gets. I am using the i2c_t3 library and the datasheet of the mcps states i2c rates 100k 400k, 1.7M Hz. But it doesnt matter what i change in the code (ie rate on the teensy) the loop that involves the i2c communications always takes up the same amount of time, i somehow have the feeling that any rate change in code does not do any difference...
---> HINT: For all just flying over the text and might be looking for something related to their problem: i got rid of the MCP23017 adafruit library, it produces massive latency. Just reading out my keybed with the i2c_t3 library wire commands takes ~4.5 ms in total (independent for some reason on i2c rate) but took ~80 ms with the adafruit MCP library!!
Can anyone give me a hint what i need to do in order to achieve quicker i2c rates for the mcp communications or experienced something similar? just setting and reading out a couple of digital pins shouldnt introduce ~ 5ms latency per loop. It would probably be alright for the project since overall i am running with ~9 ms per loop for all control stuff (i.e. keys and changing pots and switches) which is not noticeable in the use case. But even my adc mux reads only take about 40 us in total each go. So i would really like to up the digital IO game
Code:
Wire.begin(I2C_MASTER, MCP_KEYS_ADDR, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
Wire.begin(I2C_MASTER, MCP_DIO_ADDR, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
Second:
- I am looking for proper amplitude modulation of my waves (running with 3 oscillators + 1 noise object through a hell of a lot of stuff) and i would look into coding it myself into the waveform objects but wanted to ask here first before maybe reinventing the wheel:
I have not found a way of just creating a simple LFO to control my output volume.
I used an amp object and updated the gain with a ~20 - 40 sample wavetable for OKish results but cant update quick enough due to my overall loop() function timing. So i get glitches on really low (due to limited sample number) and very high (due to limited update rate) LFO rates.
The multiply object doesnt do either (even though the documentation pretends) since it basically is a ring modulator: multiplying two waves does not simply create a wave with an envelope but due to trigonometrics (for the simple case of sine waves):
sin(x)sin= 1/ 2 [cos(x−y)−cos(x+y)],
inputting an 10 Hz LFO and my previously (through a lot of steps) modulated multi wave object (say playing a note A = 440 Hz) i get a 450Hz and 430Hz split output, i.e. i am detuning the note up and down rather than modulating its amplitude. This is a separate feature of my synth but not what i want when trying to copy analog VCA.
Can someone help or hint me on how to do this?! I want the LFO to control the output amplitude of the sound!
Apart from that: I have built a case now, holding it all together, i am constantly trying to optimize the code , still with multiple branches on my git open . I will redo the schematics and pcb files (for the teensy with a power circuit, MIDI IO, gpio expanders and all necessary plugs and separately some basic "modules" with a 8 ch multiplexer each, holding pots and various other stuff, for "easy" modular "build your own" design ), and it will all be up and available on github in the near future. For now i have a monophonic unit but with the power of the later teensys it shouldnt be impossible to do a polyphonic version. I am really excited and will let you all know (in case you want to ),
since i profitted a lot from the audio tool and from the forum!
Thanks in advance and all the best!
Jochen