Skip to content

Commit

Permalink
Merge pull request #112 from mossmann/adc-fix
Browse files Browse the repository at this point in the history
Fix board revision detection in firmware
  • Loading branch information
mossmann authored Aug 1, 2024
2 parents 1b56e9d + 196bbc8 commit 9cab9f2
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions firmware/src/boards/cynthion_d11/board_rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ void detect_hardware_revision(void)

// Retrieve a single ADC reading.
hri_adc_set_SWTRIG_START_bit(ADC);
while (!hri_adc_get_interrupt_RESRDY_bit(ADC));
reading = hri_adc_read_RESULT_reg(ADC);
while (!hri_adc_get_interrupt_RESRDY_bit(ADC));
reading = hri_adc_read_RESULT_reg(ADC);

/*
* Read the ADC a second time and discard the previous reading to eliminate
* error. Initial readings at start-up are typically 0.2% to 1.0% high.
*/
hri_adc_set_SWTRIG_START_bit(ADC);
while (!hri_adc_get_interrupt_RESRDY_bit(ADC));
reading = hri_adc_read_RESULT_reg(ADC);

// Convert ADC measurement to per mille of the reference voltage.
uint32_t permille = (((uint32_t)reading * 1000) + 20480) >> 12;
if (permille > 510) {
uint32_t permille = ((uint32_t)reading * 1000) >> 12;
if (permille > 515) {
permille = 1000 - permille;
gsg_production = true;
}
Expand All @@ -82,15 +90,15 @@ void detect_hardware_revision(void)
uint16_t version;
uint16_t threshold;
} revisions[] = {
{ CYNTHION_REV_0_6, 10 },
{ CYNTHION_REV_UNKNOWN, 195 },
{ CYNTHION_REV_1_4, 220 },
{ CYNTHION_REV_1_3, 240 },
{ CYNTHION_REV_1_2, 260 },
{ CYNTHION_REV_1_0, 280 },
{ CYNTHION_REV_1_1, 310 },
{ CYNTHION_REV_UNKNOWN, 480 },
{ CYNTHION_REV_0_7, 510 },
{ CYNTHION_REV_0_6, 15 },
{ CYNTHION_REV_UNKNOWN, 200 },
{ CYNTHION_REV_1_4, 225 },
{ CYNTHION_REV_1_3, 245 },
{ CYNTHION_REV_1_2, 265 },
{ CYNTHION_REV_1_0, 285 },
{ CYNTHION_REV_1_1, 315 },
{ CYNTHION_REV_UNKNOWN, 485 },
{ CYNTHION_REV_0_7, 515 },
};

int i = 0;
Expand Down

0 comments on commit 9cab9f2

Please sign in to comment.