Measurement Task:
char MeasureTask(void) begin if(OSGetState()==MeasurePrep) { if((OSGetMessSrc & 0x01) !=0x01) return 1; //halt if the message isn'tfrom keyboard else //discharge capacitor { DDRB = 0b11110111; //set PIN2 output PORTB = 0x00; //pull-down to discharge capacitor OSSetTimeout(25); //wait 25 ms before we start OSSetState(MeasureStart); return 0; } } if(OSGetState()==MeasureStart) { DDRB = 0b11110011; //set PIN2 input again TCNT1 = 0; //clear timer PORTB.0 = 1; //raise Vcc to start charging TCCR1B = 0b01000011; //capture on rising edge, 64x clock div. OSSetMessMask(0x08); //wait for on the completion of charging OSSetTimeout(0); OSSetState(MeasureDone); // OSUARTTransmitBytes(ping,4); return 0; //note to self, creat a task that monitors TCNT1 and see what's going on in there. } if(OSGetState()==MeasureDone) { if( (OSGetMessSrc() & 0x08) !=0x08) return 1; //halt if the message isn't from ISR else { //fix the OSGetMessSrc problem TCCR1B=0; //shut off timer PORTB.0=0; //Drop Vcc to discharge capacitortemp = ICR1L; //Grab the capacitance value OSSendMess(2, temp); //send the value to be displayed OSSetState(MeasurePrep); //set the state back to original OSSetMessMask(0x01); // OSUARTTransmitBytes(pong,4); return 0; } }end Previous Next