Two trimmers are connected to the ADC one on channel 1 and the other on channel 2. The pressure sensor is connected to channel 0.
The two trimmers will be adjusting a low threshold and a high threshold for the pressure sensor and pin output function.
#include <avr/io.h>
#include "MrLCD.h"
#include <avr/interrupt.h>
int static volatile InchesOfHg, High, Low = 0;
int main(void)
{
InitializeMrLCD();
Send_A_StringToMrLCDWithLocation(1, 1, "Inches of Hg:");
Send_A_StringToMrLCDWithLocation(1, 2, "H: L:");
DDRD |= 1<<PIND0;
ADCSRA |= 1<<ADPS2;
ADMUX |= 1<<REFS0;
ADCSRA |= 1<<ADIE;
ADCSRA |= 1<<ADEN;
sei();
ADCSRA |= 1<<ADSC;
uint8_t enoughVacuum = 0;
while (1)
{
if (InchesOfHg > High) enoughVacuum = 1;
if (InchesOfHg < Low) enoughVacuum = 0;
if (enoughVacuum == 0 && bit_is_clear(PORTD, PIND0)) PORTD |= 1<<PIND0;
if (enoughVacuum == 1 && bit_is_set(PORTD, PIND0)) PORTD &= ~(1<<PIND0);
}
}
ISR(ADC_vect)
{
uint8_t theLowADC = ADCL;
uint16_t TenBitResult = ADCH<<8 | theLowADC;
switch (ADMUX)
{
case 0x40:
InchesOfHg = -0.0376 * TenBitResult + 35.532;
Send_An_IntegerToMrLCD(15, 1, InchesOfHg, 4);
ADMUX = 0x41;
break;
case 0x41:
High = .034 * TenBitResult -.68;
Send_An_IntegerToMrLCD(4, 2, High, 3);
ADMUX = 0x42;
break;
case 0x42:
Low = .034 * TenBitResult -.68;
Send_An_IntegerToMrLCD(14, 2, Low, 3);
ADMUX = 0x40;
break;
default:
//Default code
break;
}
ADCSRA |= 1<<ADSC;
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.