-
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
3 changed files
with
28 additions
and
26 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 |
---|---|---|
@@ -1,27 +1,28 @@ | ||
#include "../driver/adc.h" | ||
|
||
|
||
void adcInit(void) { | ||
/* Enable ADC */ | ||
ADCSRA = (1 << ADEN) | (1 << ADSC); | ||
/* Left Adjust Results */ | ||
//ADCSRB = (1 << ADLAR); | ||
//printf("ADC has started\n"); | ||
} | ||
|
||
/* | ||
void getPSI(void) { | ||
|
||
void getPascal(void) { | ||
while(ADCSRA & (1 << ADSC)); | ||
ADCSRA |= (1 << ADSC); // Start ADC conversion | ||
float rawPresureData = ADCH; // Max is 8bit value | ||
printf("PSI: %.2f", (rawPresureData / 255.0) * 14.5); | ||
delay_ms(100); | ||
int ten_bit_value = ADCL + (ADCH * 256); | ||
kiloPascal = ten_bit_value / SENSITIVITY; | ||
pascal = fabs(kiloPascal - 0.98) * 1000.00; | ||
printf("Pa: %.2f\n", pascal); | ||
_delay_ms(250); | ||
} | ||
|
||
uint8_t adcStart(void) { | ||
void getFlowRate(void) { | ||
while(ADCSRA & (1 << ADSC)); | ||
ADCSRA |= (1 << ADSC); // Start ADC conversion | ||
loop_until_bit_is_clear(ADCSRA, ADSC); | ||
uint8_t rawPresureData = ADCH; // Max is 8bit value | ||
return rawPresureData; | ||
int ten_bit_value = ADCL + (ADCH * 256); | ||
kiloPascal = ten_bit_value / SENSITIVITY; | ||
pascal = fabs(kiloPascal - 0.98) * 1000.00; | ||
flow = sqrt(pascal / 33); // Bernoulli's equation | ||
printf("Flow rate %.2f cm/s\n", flow); | ||
_delay_ms(250); | ||
} | ||
*/ |
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,11 @@ | ||
#include <stdio.h> | ||
#include <avr/io.h> | ||
#include <stdint.h> | ||
#define OFFSET 44 | ||
#include <math.h> | ||
#include <util/delay.h> | ||
#define SENSITIVITY 44.00 | ||
|
||
float kiloPascal, pascal; | ||
float flow; | ||
void adcInit(void); | ||
//void getPSI(void); | ||
//uint8_t adcStart(void); | ||
void getPascal(void); | ||
void getFlowRate(void); |
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