Sorry for the many questions in a row, I hope that's the last one
I have been reading through the source code employing the PDB, and I noticed that they all set PDB0_MOD to a value that is one less than I would expect.
Using an oscilloscope I did various tests that indeed this is the right thing to do to get the desired frequency.
I wonder however if there is anything that indicates why to do this. In the documentation of the Teensy 3.6 chip, they suggest that this is a modulo value that resets the PDB counter to 0. So if you want 10 counts 0..9 you would use 10 as modulus in normal math.
To get specific, the documentation says:
According to the the doc excerpt above however you would have to set it to 10, because if you set it to 9 it would already reset to 0, which would be one too early.
How did you find out that you need to use modulo - 1? Is that documented somewhere?
This may seem like a very academical question. The reason I ask is that I would have very likely missed this subtelty if I hadn't noticed it in Teensy's source code. So maybe I read something wrong in the docs or missed something, that might be useful in similar situations.
The other question is: why is PDB0_IDLY set to 1 in many places?
If I understand correctly PDB0_MOD sets the maximum counter value, and PDB0_IDLY sets when inside this period (period = 0 to max counter value) the interrupt/DMA request is actually raised. In other words, you can delay the interrupt to happen later in the period, instead of just on the start.
Is this for synchronizing the DAC with the ADC. But in this case, why do both have the same delay?
I have been reading through the source code employing the PDB, and I noticed that they all set PDB0_MOD to a value that is one less than I would expect.
Using an oscilloscope I did various tests that indeed this is the right thing to do to get the desired frequency.
I wonder however if there is anything that indicates why to do this. In the documentation of the Teensy 3.6 chip, they suggest that this is a modulo value that resets the PDB counter to 0. So if you want 10 counts 0..9 you would use 10 as modulus in normal math.
To get specific, the documentation says:
So in our example, you would set PDB0_MOD to 9 because you want to count from 0 to 9 (inclusive) and learned that you have to use the actual modulus -1.PDB Modulus
Specifies the period of the counter. When the counter reaches this value, it will be reset back to zero. If the
PDB is in Continuous mode, the count begins anew. Reading this field returns the value of the internal
register that is effective for the current cycle of PDB.
According to the the doc excerpt above however you would have to set it to 10, because if you set it to 9 it would already reset to 0, which would be one too early.
How did you find out that you need to use modulo - 1? Is that documented somewhere?
This may seem like a very academical question. The reason I ask is that I would have very likely missed this subtelty if I hadn't noticed it in Teensy's source code. So maybe I read something wrong in the docs or missed something, that might be useful in similar situations.
The other question is: why is PDB0_IDLY set to 1 in many places?
If I understand correctly PDB0_MOD sets the maximum counter value, and PDB0_IDLY sets when inside this period (period = 0 to max counter value) the interrupt/DMA request is actually raised. In other words, you can delay the interrupt to happen later in the period, instead of just on the start.
Is this for synchronizing the DAC with the ADC. But in this case, why do both have the same delay?