[Avrora] How to implement a temperature sensor?

Roy roy at cs.hmc.edu
Tue Aug 28 10:13:04 PDT 2007


Howdy,

The plot thickens!

I agree with most of your description below.  Looks like you have done
a fine job tracing the pins "INT1" and "ADC1" back to the ATMega128.
However, "INT1" aka "PE5" does in fact control power to the light
sensor by providing the voltage that is fed through the photo-resistor.

More mysterious is "PC2".  My understanding is that "PC2" is used to
turn the sounder on or off.  Perhaps this is a bug in Avrora's light
sensor object?  I would expect a LightSensor where all occurrences of
"on" and "onPin" are removed.  See attached patch file for the
LightSensor for details of what I have in mind.

Anyone up to take a third look at how "PC2" interacts with the light
sensor to provide another opinion on this?  I can't help thinking that
I have missed something...

Peace,
-Roy

On Tue, Aug 28, 2007 at 11:57:46PM +0800, Zhifeng Lai wrote:
> Dear Roy,
> 
> I am sorry I could not quite follow your pin tracing statements.
> 
> >From the sensor board datasheet, I see the light sensor uses "INT1" and
> "ADC1" (5, 42), which corresponds to "PE5" and "PF1" (7, 60) on the mica2
> schematic (page 4). I still confuse because in the Mica2 class, the light
> sensor is created using
> 
>     lightSensor = new LightSensor(amcu, 1, "PC2", "PE5");
> 
> and I don't understand what corresponds to "PC2". In fact, the declaration
> of light sensor constructor is:
> 
>     public LightSensor(AtmelMicrocontroller m, int adcChannel, String onPin,
> String powPin)
> 
> but I don't think "PE5" is a pin that controls power.
> 
> Best regards,
> 
> Yours sincerely,
> Zhifeng Lai
> 
-------------- next part --------------
--- LightSensor.java	2007-08-28 10:10:27.000000000 -0700
+++ LightSensor_new.java	2007-08-28 10:02:57.000000000 -0700
@@ -47,28 +47,18 @@
 
     protected final FiniteStateMachine fsm;
 
-    protected static final String[] names = { "power down", "off", "on" };
+    protected static final String[] names = { "power down", "off" };
     protected boolean power;
-    protected boolean on;
 
-    public LightSensor(AtmelMicrocontroller m, int adcChannel, String onPin, String powPin) {
+    public LightSensor(AtmelMicrocontroller m, int adcChannel, String powPin) {
         mcu = m;
         channel = adcChannel;
-        mcu.getPin(onPin).connect(new OnPin());
         mcu.getPin(powPin).connect(new PowerPin());
         fsm = new FiniteStateMachine(mcu.getClockDomain().getMainClock(), 0, names, 0);
         ADC adc = (ADC)mcu.getDevice("adc");
         adc.connectADCInput(new ADCInput(), channel);
     }
 
-    class OnPin extends Microcontroller.OutputPin {
-        public void write(boolean val) {
-            // TODO: is there an inverter?
-            on = !val;
-            fsm.transition(state());
-        }
-    }
-
     class PowerPin extends Microcontroller.OutputPin {
         public void write(boolean val) {
             power = val;
@@ -78,14 +68,13 @@
 
     private int state() {
         if ( !power ) return 0;
-        if ( !on ) return 1;
-        else return 2;
+        else return 1;
     }
 
     class ADCInput implements ADC.ADCInput {
         public int getLevel() {
             if ( data == null ) return ADC.GND_LEVEL;
-            if ( !power || !on ) return ADC.GND_LEVEL;
+            if ( !power ) return ADC.GND_LEVEL;
             return data.reading();
         }
     }


More information about the Avrora mailing list