-
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.
- Loading branch information
Showing
11 changed files
with
2,590 additions
and
39 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
MCU=attiny441 | ||
MCU=attiny841 | ||
PROGRAMMER=atmelice_isp | ||
F_CPU=1000000 | ||
CC=avr-gcc | ||
|
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 |
---|---|---|
@@ -1,27 +1,32 @@ | ||
#include "../driver/adc.h" | ||
|
||
|
||
|
||
|
||
/** @defgroup group1 TinyADC Library | ||
* This is a minimal ADC Library with init and read functions only. | ||
* @{ | ||
*/ | ||
|
||
/** @brief class C1 in group 1 */ | ||
|
||
void adcInit(void) { | ||
/* Enable ADC */ | ||
/// Enables ADC. | ||
ADCSRA = (1 << ADEN) | (1 << ADSC); | ||
/* Left Adjust Results */ | ||
//ADCSRB = (1 << ADLAR); | ||
//printf("ADC has started\n"); | ||
} | ||
|
||
/* | ||
void getPSI(void) { | ||
ADCSRA |= (1 << ADSC); // Start ADC conversion | ||
float rawPresureData = ADCH; // Max is 8bit value | ||
printf("PSI: %.2f", (rawPresureData / 255.0) * 14.5); | ||
delay_ms(100); | ||
float adcRead(void) { | ||
/// Returns calibrated adc values. | ||
float sum = 0; // Sum of averaged adc values | ||
int adc_values_arr[N]; | ||
for (int i = 0; i < N; i++) { | ||
while(ADCSRA & (1 << ADSC)); | ||
ADCSRA |= (1 << ADSC); // Start ADC conversion | ||
int ten_bit_value = ADCL + (ADCH * 256); | ||
adc_values_arr[i] = ten_bit_value; | ||
sum += adc_values_arr[i]; | ||
} | ||
calibrated_adc_value = floor((sum / 55.0) - OFFSET); | ||
return calibrated_adc_value; | ||
} | ||
|
||
uint8_t adcStart(void) { | ||
ADCSRA |= (1 << ADSC); // Start ADC conversion | ||
loop_until_bit_is_clear(ADCSRA, ADSC); | ||
uint8_t rawPresureData = ADCH; // Max is 8bit value | ||
return rawPresureData; | ||
} | ||
*/ |
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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
#ifndef ADC_H | ||
#define ADC_H | ||
|
||
#include <stdio.h> | ||
#include <avr/io.h> | ||
#include <stdint.h> | ||
#define OFFSET 44 | ||
#include <math.h> | ||
#include <util/delay.h> | ||
#define OFFSET 44 // Value which offsets adc to 0 | ||
#define N 55 // Numbers of values averaged from adc | ||
|
||
int adc_values_arr[N]; | ||
float calibrated_adc_value; | ||
void adcInit(void); | ||
//void getPSI(void); | ||
//uint8_t adcStart(void); | ||
float adcRead(void); | ||
|
||
#endif // ADC_H |
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
#ifndef MPX5100_H | ||
#define MPX5100_H | ||
|
||
#include "../driver/adc.h" | ||
// #define SIGNAL_OFFSET // This value corresponds to an air flow of 0 | ||
#define MAX_PRESSURE 120.0 // Pressure in KPa | ||
|
||
float pascal, adc_val; | ||
void getPascal(void); | ||
|
||
#endif // MPX5100_H |
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
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
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
#include "../driver/adc.h" | ||
|
||
|
||
/** @defgroup group2 MPX5100 Library | ||
* This is library interfaces with the mpx5100. | ||
* @{ | ||
*/ | ||
|
||
/** This function return the sensor reading in Pascals. */ | ||
void getPascal(void) { | ||
adc_val = adcRead(); | ||
pascal = ((adc_val / 1023.0) * MAX_PRESSURE) * 1000.0; | ||
printf("%.2f Pa\n" pascal); | ||
_delay_ms(250); | ||
} | ||
|
||
/** @} */ // end of group2 |
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
Oops, something went wrong.