[QUESTION] problem with DACSIZE
othmar52 opened this issue · comments
Hi,
First of all: thank you very much for this library!
I use it for a vibrato feature for an eurorack keyboard
it works perfectly for sine
and square
wave but i did not manage to get saw
and triangle
applied to my note pitch.
Disclaimer: i am not an electronic engineer nor an expert C++ programmer. I just play around with informations i find in the web.
in my cuircuit i have an Arduino Uno
with a MCP4821 (12-Bit Single Output DAC with SPI)
based on this line i assume that it's DACSIZE is 4096
for sending 0V
to 5V
when i use lfo lfo_class(4096);
your lfo gets perfectly added to my base note pitch for waves sine
& square
but nothing gets added for waves saw
nor triangle
in your instructions i found
Reduce the DACSIZE to 256
when i use lfo lfo_class(256);
your lfo works perfectly for all 4 waves. but unfortunately my other code for sending the "base pitch" (the lfo should oscillate around) does not work at all.
do you think i have to find the reason in my code or is it possible that you have some kind of limitation in your library (saw+triangle not compatlble to DACSIZE 4096)?
@mo-thunderz i managed to get my sketch to work with 2 dacsizes
256 for your lfo
4096 for my note pitch
by dividing and multiplying some values with 16 everything seems to work now...
I figured out that my workaround is pretty bad
due to the low resolution of DACSIZE 256
the lfo generated output signal sounds pretty bad (more like a sample & hold) on very low frequencies.
@mo-thunderz do you have any idea how to solve this?
Sorry for my late reply, I have been pretty loaded at work. I have tried my code on all platforms I have laying around here (Arduino Mega, Arduino Due) and it works fine. However, I did not have an Uno free at the moment. To figure out if it is the DAC or the library I uploaded a simple test code so that you can check if the code works on the Uno. Can you upload this code to your Uno and look at the serial interface:
https://github.com/mo-thunderz/lfo/tree/main/examples/LFO_example_no_dac
This will simply print the waveform to the serial port. By setting lfo_waveform you can change the waveform. For a saw wave (lfo_waveform = 1), the code will print something like this:
737
491
245
4095
3850
3604
3358
3112
2867
2621
2375
2129
1884
1638
1392
1146
901
655
409
163
4014
3768
3522
You can see that the value starts close to 4096 and goes down linearly to 0. If this is the case on your system as well, then you know that that at least is working. Another problem you could have in your code is that you have defined an amplitude offset, or that you have reduced the amplitude. As such pls make sure that these parameters are set correctly:
lfo_class.setAmpl(DACSIZE-1); // set amplitude to maximum
lfo_class.setAmplOffset(0); // no offset to the amplitude
lfo_class.setMode(0); // set sync mode to mode0 -> no sync to BPM
Good luck with the code!
Dear othmar52, I have another question related to the problem you are seeing. Do you see the problem for both the free-running mode (_mode = 0) and the synced mode (_mode = 1)?
@mo-thunderz thank you for your reply!
the problem with saw
& triangle
is in both modes
the serial output of /LFO_example_no_dac explains somehow why it isn't working on my Arduino Uno:
4096 | 4096 | 4096 | 4096 | 256 | 256 | 256 | 256 | |
---|---|---|---|---|---|---|---|---|
1: saw | 2: triangle | 3: sine | 4:square | 1: saw | 2: triangle | 3: sine | 4:square | |
7 | 2 | 4094 | 4094 | -2 | 2 | 254 | 254 | |
1 | 3 | 3950 | 4094 | -17 | 32 | 245 | 254 | |
-4 | 7 | 3539 | 4094 | -32 | 63 | 219 | 254 | |
6 | 3 | 2919 | 4094 | -48 | 94 | 181 | 254 | |
0 | 0 | 2177 | 4094 | -63 | 124 | 135 | 254 | |
-5 | 5 | 1416 | 4094 | -78 | 102 | 87 | 254 | |
4 | 6 | 744 | 4094 | -94 | 71 | 46 | 254 | |
-2 | 1 | 254 | 4094 | -109 | 40 | 15 | 254 | |
-6 | 2 | 16 | 4094 | -124 | 10 | 1 | 254 | |
3 | 5 | 63 | 0 | 117 | 19 | 3 | 0 | |
-2 | 1 | 388 | 0 | 102 | 50 | 24 | 0 | |
7 | 3 | 946 | 0 | 87 | 80 | 58 | 0 | |
2 | 7 | 1658 | 0 | 71 | 111 | 102 | 0 | |
-3 | 3 | 2425 | 0 | 56 | 115 | 150 | 0 | |
6 | 1 | 3139 | 0 | 40 | 84 | 194 | 0 | |
0 | 5 | 3699 | 0 | 25 | 54 | 229 | 0 | |
-4 | 6 | 4028 | 0 | 10 | 23 | 249 | 0 | |
5 | 4 | 4078 | 4094 | -7 | 12 | 253 | 254 | |
0 | 0 | 3844 | 4094 | -22 | 42 | 238 | 254 | |
-6 | 4 | 3357 | 4094 | -37 | 73 | 208 | 254 | |
4 | 7 | 2686 | 4094 | -53 | 104 | 166 | 254 | |
-1 | 2 | 1926 | 4094 | -68 | 122 | 119 | 254 | |
-7 | 1 | 1183 | 4094 | -83 | 92 | 73 | 254 | |
2 | 6 | 560 | 4094 | -99 | 61 | 34 | 254 | |
-2 | 5 | 147 | 4094 | -114 | 30 | 9 | 254 |
i am going to debug this within the next few days.
obviously the amplitude ends up far to low in the calculation
maybe i am able to find the reason and fix it myself
EDIT i also added serial output of all 4 waves with DACSIZE 256
within /LFO_example_no_dac