Skip to content

Commit

Permalink
Module17: added VBat measurement to ADC1 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
mdiepart authored and silseva committed May 4, 2024
1 parent 26665a9 commit 37c1c4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion platform/drivers/ADC/ADC1_Mod17.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,28 @@ void adc1_terminate()

uint16_t adc1_getRawSample(uint8_t ch)
{
if(ch > 15) return 0;
if(ch > 18)
return 0;

pthread_mutex_lock(&adcMutex);

/* Channel 18 is Vbat, enable it if requested */
if(ch == 18)
ADC123_COMMON->CCR |= ADC_CCR_VBATE;


ADC1->SQR3 = ch;
ADC1->CR2 |= ADC_CR2_SWSTART;
while((ADC1->SR & ADC_SR_EOC) == 0) ;
uint16_t value = ADC1->DR;

/* Disconnect Vbat channel. Vbat has an internal x2 voltage divider */
if(ch == 18)
{
value *= 2;
ADC123_COMMON->CCR &= ~ADC_CCR_VBATE;
}

pthread_mutex_unlock(&adcMutex);

return value;
Expand Down
1 change: 1 addition & 0 deletions platform/drivers/ADC/ADC1_Mod17.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum adcCh
{
ADC_HWVER_CH = 3,
ADC_HMI_HWVER_CH = 13,
ADC_VBAT_CH = 18
};

/**
Expand Down

0 comments on commit 37c1c4a

Please sign in to comment.