-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(temperature):implement header file
-add function TEMPERATURE_Init() -add function TEMPERATURE_Read()
- Loading branch information
1 parent
a52ff79
commit 4b7cfd7
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
@module: TEMPERATURE | ||
@author: Abdullah Bagyapan | ||
@date: 19/04/2024 | ||
*/ | ||
|
||
/*================================== Libraries ==================================*/ | ||
|
||
|
||
#include "temperature.h" | ||
|
||
#include "pico/stdlib.h" | ||
#include "hardware/adc.h" | ||
|
||
|
||
/*================================== Functions ==================================*/ | ||
|
||
|
||
/* | ||
@brief: Calculate ADC value according to the formula | ||
@author Abdullah Bagyapan | ||
@date 19/04/2024 | ||
@param uint16_t ui16ADC_voltage, The analog data from temperature sensor | ||
@return The temperature, in celsius format | ||
*/ | ||
static inline uint8_t _TEMPERATURE_Calculate_Celsius(uint16_t ui16ADC_voltage) { | ||
|
||
// T = 27 - (ADC_voltage - 0.706)/0.001721 | ||
// The given above formula according to the RP2040 datasheet | ||
|
||
return 27 - (ui16ADC_voltage - 0.706) / 0.001721; | ||
|
||
} | ||
|
||
|
||
void TEMPERATURE_Init(void) { | ||
|
||
// Initialize onboard temperature sensor | ||
adc_gpio_init(TEMPERATURE_GPIO_PIN); | ||
|
||
// Set onboard temperature sensor as ADC | ||
adc_select_input(TEMPERATURE_ADC_PIN); | ||
|
||
} | ||
|
||
uint8_t TEMPERATURE_Read(void) { | ||
|
||
uint8_t ui8TemperatureCelsius; | ||
|
||
uint16_t ui16ADC_voltage = adc_read(); | ||
|
||
ui8TemperatureCelsius = _TEMPERATURE_Calculate_Celsius(ui16ADC_voltage); | ||
|
||
return ui8TemperatureCelsius; | ||
} |