Previous Next

Measurement Task:

  1. Start: Check the message source and be sure the message came from the keyboard. If not, exit with an error. Otherwise, start discharging the capacitor. Use OSSetTimeout to wait 25 ms for the capacitor to discharge. Set the entry point to the MT_startMeasure label. Exit.
  2. Start Measure: Start charging the capacitor. Clear timer 1. Reset timeout value to zero, and set message mask to wait for the capture ISR. Set the next entry point at MT_finishMeasure. Exit.
    Finish Measure: Check the message source and be sure the message came from the ISR. If not, exit with an error.
  3. Otherwise, pull in the capacitance from the capture register and send it as a message to the display task. Reset message mask and entry pointer back to the start condition.
	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 capacitor 
 temp = 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