Setting PDB frequency for two ADC-Channels Simultanously

Status
Not open for further replies.

Bimli

New member
Hi,

I found a code on this forum which sets the PDB-frequency for both ADC channels simultanously and modified it a little bit for my needs here is my created function(which also works):
[ CODE]
void setPdbFreq() {
constexpr uint32_t prescaler = 7; // from 0 to 7: factor of 1, 2, 4, 8, 16, 32, 64 or 128
constexpr uint32_t prescaler_multiplier = 1; // from 0 to 3: factor of 1, 10, 20 or 40
constexpr uint32_t pdb_trigger_frequency = 10000;
constexpr uint32_t mod = (F_BUS / 128 / 10 / pdb_trigger_frequency);
static_assert(mod <= 0x10000, "Prescaler insufficient.");
PDB0_MOD = (uint16_t)(mod-1);
constexpr uint32_t PDB_CHnC1_TOS_1 = 0x0100;
constexpr uint32_t PDB_CHnC1_EN_1 = 0x01;
PDB0_CH0C1 = PDB_CHnC1_TOS_1 | PDB_CHnC1_EN_1; // PDB triggers ADC0 SC1A
PDB0_CH1C1 = PDB_CHnC1_TOS_1 | PDB_CHnC1_EN_1; // PDB triggers ADC1 SC1A
PDB0_SC = PDB_SC_PRESCALER(prescaler) | PDB_SC_MULT(prescaler_multiplier) | PDB_SC_LDOK |
PDB_SC_TRGSEL(0b1111) | PDB_SC_PDBEN | PDB_SC_LDMOD(0) | PDB_SC_CONT;
}
[ /CODE]

Now I am really unsure how to set a propper "mod", so where does 128 and 10 come from and why can't I just divide by pdb_trigger_frequency? And also why is the multiplier and prescaler set here, as far as I understood, you only have to set these values, if they are higher than a 16-Bit value or am I wrong?
A complete Link to my project:
https://github.com/SebastianVol/EOD...gger_2channel_barebone/eodlogger_8channel.ino
 
Status
Not open for further replies.
Back
Top