Presentation is loading. Please wait.

Presentation is loading. Please wait.

3/2/2015IoET - L05 sense1 Wireless Embedded InterNet working Foundations of Ubiquitous Sensor Networks Triggers and Sensing David E. Culler University.

Similar presentations


Presentation on theme: "3/2/2015IoET - L05 sense1 Wireless Embedded InterNet working Foundations of Ubiquitous Sensor Networks Triggers and Sensing David E. Culler University."— Presentation transcript:

1 3/2/2015IoET - L05 sense1 Wireless Embedded InterNet working Foundations of Ubiquitous Sensor Networks Triggers and Sensing David E. Culler University of California, Berkeley

2 3/2/2015IoET - L05 sense2 An Analog World Everything in the physical world is an analog signal –Sound, light, temperature, gravitational force Need to convert into electrical signals –Transducers: converts one type of energy to another »Electro-mechanical, Photonic, Electrical, … –Examples »Microphone/speaker »Thermocouples »Accelerometers And digitize Then manipulate

3 3/2/2015IoET - L05 sense3 An Analog World Transducers –Allow us to convert physical phenomena to a voltage potential in a well-defined way. R ohm ?  V

4 3/2/2015IoET - L05 sense4 Simplest Analog Device Often think of it as an actuator, rather than a sensor –But that’s because of the circuit we put it in It is binary (two states) but why is it not digital? switch Rain Sensor Magnetic Reed Contact Switch Tilt Sensor Water Level Float Sensor PhotoInterrupter Flow Sensor Temperature Switch Pressure Switch

5 3/2/2015IoET - L05 sense5 To Sample a switch, make it digital Many sensor are switches Two “states” but not digital –Open => no current –Closed => no voltage drop Cap charges to Vacc when open Cap discharges to GND when closed VDVD V tL V tH V acc GND switch D

6 3/2/2015IoET - L05 sense6 Making Sense of Physical Information Digital representation of physical phenomenon –Transducer => Signal Conditioning => ADC => –Conversion to physical units –Calibration and correction –Here: 0 / 1, True / False Associating meaning to the reading –Open / Closed –Empty / Full –In Position / Not Depends on the specific device taking the reading The Context of the device

7 3/2/2015IoET - L05 sense7 Analog to Digital What we want How we have to get there SoftwareSensorADC Physical Phenomena VoltageADC Counts Engineering Units Physical Phenomena Engineering Units

8 3/2/2015IoET - L05 sense8 Ratiometric sensor V a = V acc * R sens / (R comp + R sens ) use V ref = V acc D = M * R sens / (R comp + R sens ) V acc GND Resistive Sensor VAVA R comp R sensor

9 Getting down to the MCU 3/2/2015IoET - L05 sense9

10 3/2/2015IoET - L05 sense10 Getting Input into the MCU

11 Storm: points to pins 3/2/2015IoET - L05 sense11

12 Firestorm => Storm => ATSAM4LC Most pins have many functions –C.f. section 3.2 3/2/2015IoET - L05 sense12

13 Power, Power, Power 3/2/2015IoET - L05 sense13

14 3/2/2015IoET - L05 sense14 ARM Cortex MCU – a system on a chip

15 3/2/2015IoET - L05 sense15 Memory and Memory-Mapped IO

16 GPIO The General Purpose Input/Output Controller (GPIO) controls the I/O pins of the microcontroller. Each GPIO pin may be used as a general-purpose I/O or be assigned to a function of an embed- ded peripheral. The GPIO is configured using the Peripheral Bus (PB). 3/2/2015IoET - L05 sense16

17 What’s beyond the pin Control logic associated with a pin 3/2/2015IoET - L05 sense17

18 GPIO Registers 3/2/2015IoET - L05 sense18

19 3/2/2015IoET - L05 sense19 Analog-to-Digital Basics So, how do you convert analog signals to a discrete values? A software view: 1.Set some control registers : »Specify where the input is coming from (which pin) »Specify how to collect it (reference, mode, range) 2.Enable interrupt and set a bit to start a conversion 3.Wait for conversion (poll for complete or interrupt) 4.read sample from data register 5.Wait for a sample period 6.Repeat step 1

20 Our ADC 3/2/2015IoET - L05 sense20

21 3/2/2015IoET - L05 sense21 ADC Features Texas Instruments MSP430 Atmel ATmega 1281 ATSAM4L Resolution12 bits10 bits12 (or 8) bits Sample Rate200 ksps76.9 ksps300 ksps Internally Generated Reference Voltage 1.5V, 2.5V, Vcc1.1V, 2.56V1.0 V, 0.625 Vcc, Vcc/2, 2 ext ref 1-64x Gain, zoom Single-Ended Inputs 121615 Differential Inputs 014 (4 with gain amp) 7 Left Justified Option NoYesyes Conversion Modes Single, Sequence, Repeated Single, Repeated Sequence Single, Free Running Single, Continuous, Timer, Triggers Data Buffer16 samples1 sample Add M-Cortex feature

22 3/2/2015IoET - L05 sense22 Sampling Basics How do we represent an analog signal? –As a time series of discrete values  On the MCU: read the ADC data register periodically VCounts

23 3/2/2015IoET - L05 sense23 Sampling Basics What do the sample values represent? –Some fraction within the range of values  What range to use? Range Too Small Range Too Big Ideal Range

24 3/2/2015IoET - L05 sense24 Sampling Basics Resolution –Number of discrete values that represent a range of analog values –ATSAM4L: 12-bit ADC »4096 values »Range / 4096 = Step Larger range  less information Quantization Error –How far off discrete value is from actual –½ LSB  Range / 8192 Larger range  larger error

25 3/2/2015IoET - L05 sense25 Sampling Basics Converting: ADC counts  Voltage Converting: Voltage  Engineering Units

26 3/2/2015IoET - L05 sense26 Sampling Basics Converting values in 16-bit MCUs (easy on 32 bit) vtemp = adccount/4095 * 1.5; tempc = (vtemp-0.986)/0.00355;  tempc = 0 Fixed point operations –Need to worry about underflow and overflow –Avoid divide and (to a lesser degree) multiply Floating point operations –They can be costly on the node, but not ridiculous Pay attention to overall all contribution to error command uint16_t TempInt.get() { uint16_t tval = (uint32_t)760*(uint32_t)val/4096 – 468; return tval;}

27 Time for Lab 3/2/2015IoET - L05 sense27

28 3/2/2015IoET - L05 sense28 Sampling Basics What sample rate do we need? –Too little: we can’t reconstruct the signal we care about –Too much: waste computation, energy, resources »Example: 2-bytes per sample, 4 kHz  8 kB / second But the mote only has 10 kB of RAM…

29 3/2/2015IoET - L05 sense29 Shannon-Nyquist Sampling Theorem If a continuous-time signal contains no frequencies higher than, it can be completely determined by discrete samples taken at a rate: Example: –Humans can process audio signals 20 Hz – 20 KHz –Audio CDs: sampled at 44.1 KHz Need to ensure there is no appreciable energy above 2x sample.

30 3/2/2015IoET - L05 sense30 Sampling Basics Aliasing –Different frequencies are indistinguishable when they are sampled. Condition the input signal using a low-pass filter –Removes high-frequency components –(a.k.a. anti-aliasing filter)

31 3/2/2015IoET - L05 sense31 Sampling Basics Dithering –Quantization errors can result in large-scale patterns that don’t accurately describe the analog signal –Introduce random (white) noise to randomize the quantization error. Direct Samples Dithered Samples

32 3/2/2015IoET - L05 sense32 Block Diagram (MSP430)

33 Basic operation 3/2/2015IoET - L05 sense33 38.6.2

34 3/2/2015IoET - L05 sense34 ADCs: Resources or Computation OS provides a convenient and safe abstraction of physical resources Operating systems deal with devices, not ADCs. TinyOS has strived to provide uniform, easy-to- use common abstraction of the ADC. Should it? ADC and how sampling is performed in “on the datapath” of the application.

35 3/2/2015IoET - L05 sense35 TI MSP ADC Core Input –Analog signal Output –12-bit digital value of input relative to voltage references Linear conversion

36 3/2/2015IoET - L05 sense36 SAR ADC SAR = Successive-Approximation-Register –Binary search to find closest digital value

37 How ADCs work 3/2/2015IoET - L05 sense37

38 3/2/2015IoET - L05 sense38 SAR ADC SAR = Successive-Approximation-Register –Binary search to find closest digital value 1 Sample  Multiple cycles

39 3/2/2015IoET - L05 sense39 SAR ADC 1 Sample  Multiple cycles

40 3/2/2015IoET - L05 sense40 Sample and Conversion Timing Timing driven by: –TimerA –TimerB –Manually using ADC12SC bit Signal selection using SHSx Polarity selection using ISSH

41 3/2/2015IoET - L05 sense41 Voltage Reference Voltage Reference Generator –1.5V or 2.5V –REFON bit in ADCCTL0 –Consumes energy when on –17ms settling time External references allow arbitrary reference voltage Want to sample Vcc, what Vref to use? InternalExternal Vref+ 1.5V, 2.5V, VccVeRef+ Vref- AVssVeRef-

42 3/2/2015IoET - L05 sense42 Sample Timing Considerations Port 6 inputs default to high impedance When sample starts, input is enabled –But capacitance causes a low-pass filter effect  Must wait for the input signal to converge

43 3/2/2015IoET - L05 sense43 Software Configuration How it looks in code: ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP;

44 3/2/2015IoET - L05 sense44 Inputs and Multiplexer 12 possible inputs –8 external pins (Port 6) –1 Vref+ (external) –1 Vref- (external) –1 Thermistor –1 Voltage supply External pins may function as Digital I/O or ADC. –P6SEL register What sort of a MUX is this?

45 3/2/2015IoET - L05 sense45 Conversion Memory 16 sample buffer Each buffer configures sample parameters –Voltage reference –Input channel –End-of-sequence CSTARTADDx indicates where to write next sample

46 3/2/2015IoET - L05 sense46 Conversion Modes Single-Channel Single-Conversion –Single channel sampled and converted once –Must set ENC (Enable Conversion) bit each time Sequence-of-Channels –Sequence of channels sampled and converted once –Stops when reaching ADC12MCTLx with EOS bit Repeat-Single-Channel –Single channel sampled and converted continuously –New sample occurs with each trigger (ADC12SC, TimerA, TimerB) Repeat-Sequence-of-Channels –Sequence of channels sampled and converted repeatedly –Sequence re-starts when reaching ADC12MCTLx with EOS bit

47 3/2/2015IoET - L05 sense47 Software Configuration How it looks in code: Configuration ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP; ADC12MCTL0 = EOS | SREF_1 | INCH_11; Reading ADC data m_reading = ADC12MEM0;

48 3/2/2015IoET - L05 sense48 A Software Perspective command void Read.read() { ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP; ADC12MCTL0 = EOS | SREF_1 | INCH_11; call Timer.startOneShot( 17 ); } event void Timer.fired() { ADC12CTL0 |= ENC; ADC12IE = 1; ADC12CTL0 |= ADC12SC; } task void signalReadDone() { signal Read.readDone( SUCCESS, m_reading ); } async event void HplSignalAdc12.fired() { ADC12CTL0 &= ~ENC; ADC12CTL0 = 0; ADC12IE = 0; ADC12IFG = 0; m_reading = ADC12MEM0; post signalReadDone(); }

49 3/2/2015IoET - L05 sense49 A Software Perspective command void Read.read() { ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP; ADC12MCTL0 = EOS | SREF_1 | INCH_11; call Timer.startOneShot( 17 ); } event void Timer.fired() { ADC12CTL0 |= ENC; ADC12IE = 1; ADC12CTL0 |= ADC12SC; } task void signalReadDone() { signal Read.readDone( SUCCESS, m_reading ); } async event void HplSignalAdc12.fired() { ADC12CTL0 &= ~ENC; ADC12CTL0 = 0; ADC12IE = 0; ADC12IFG = 0; m_reading = ADC12MEM0; post signalReadDone(); }

50 3/2/2015IoET - L05 sense50 A Software Perspective command void Read.read() { ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP; ADC12MCTL0 = EOS | SREF_1 | INCH_11; call Timer.startOneShot( 17 ); } event void Timer.fired() { ADC12CTL0 |= ENC; ADC12IE = 1; ADC12CTL0 |= ADC12SC; } task void signalReadDone() { signal Read.readDone( SUCCESS, m_reading ); } async event void HplSignalAdc12.fired() { ADC12CTL0 &= ~ENC; ADC12CTL0 = 0; ADC12IE = 0; ADC12IFG = 0; m_reading = ADC12MEM0; post signalReadDone(); }

51 3/2/2015IoET - L05 sense51 A Software Perspective command void Read.read() { ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP; ADC12MCTL0 = EOS | SREF_1 | INCH_11; call Timer.startOneShot( 17 ); } event void Timer.fired() { ADC12CTL0 |= ENC; ADC12IE = 1; ADC12CTL0 |= ADC12SC; } task void signalReadDone() { signal Read.readDone( SUCCESS, m_reading ); } async event void HplSignalAdc12.fired() { ADC12CTL0 &= ~ENC; ADC12CTL0 = 0; ADC12IE = 0; ADC12IFG = 0; m_reading = ADC12MEM0; post signalReadDone(); }

52 3/2/2015IoET - L05 sense52 A Software Perspective command void Read.read() { ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP; ADC12MCTL0 = EOS | SREF_1 | INCH_11; call Timer.startOneShot( 17 ); } event void Timer.fired() { ADC12CTL0 |= ENC; ADC12IE = 1; ADC12CTL0 |= ADC12SC; } task void signalReadDone() { signal Read.readDone( SUCCESS, m_reading ); } async event void HplSignalAdc12.fired() { ADC12CTL0 &= ~ENC; ADC12CTL0 = 0; ADC12IE = 0; ADC12IFG = 0; m_reading = ADC12MEM0; post signalReadDone(); }

53 Old backup 3/2/2015IoET - L05 sense53

54 3/2/2015IoET - L05 sense54 MCU Kernel Driver Interrupts and Tasks ADC Application command void Read.read() { ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP; ADC12MCTL0 = EOS | SREF_1 | INCH_11; call Timer.startOneShot( 17 ); } event void Timer.fired() { ADC12CTL0 |= ENC; ADC12IE = 1; ADC12CTL0 |= ADC12SC; } task void signalReadDone() { signal Read.readDone( SUCCESS, m_reading ); } async event void HplSignalAdc12.fired() { ADC12CTL0 &= ~ENC; ADC12CTL0 = 0; ADC12IE = 0; ADC12IFG = 0; m_reading = ADC12MEM0; post signalReadDone(); }

55 3/2/2015IoET - L05 sense55 Interrupts and Tasks Tasks are run-to-completion –Used to signal application events –Break up computation in the application Interrupts –Generated by the hardware –Preempt execution of tasks Interrupts and tasks can schedule new tasks Hardware Interrupt Task Handler

56 3/2/2015IoET - L05 sense56 TinyOS Generic Components Multiple instances of a component Type polymorphism Compile-time configuration All of the above

57 3/2/2015IoET - L05 sense57 TinyOS Parameterized Interface Logically related array of interfaces Improved code by handling all interfaces collectively Compile time sizing across module boundaries Basis fo discovery

58 3/2/2015IoET - L05 sense58 Getting a hold of the event *** fix Hardware Phy Link Network Transport HplSignal Radio Flash MCU PortsADCTimers Software Kernel Driver Code Memory Mapped IO registers Hardware Interrupt Handler dispatch event void Boot.booted() { atomic { P2IE &= ~PIN7; /* Disable interrupt */ P2IFG &= ~PIN7; /* Clear interrupt flag */ P2DIR &= ~PIN7; /* Configure as input */ P2IES |= PIN7; /* Select Hi->Lo */ P2IE |= PIN7; /* Enable interrupts */ } async event void HplSignalPort2.fired() { if ( P2IFG & PIN7 ) { P2IFG &= ~PIN7; post fired(); }


Download ppt "3/2/2015IoET - L05 sense1 Wireless Embedded InterNet working Foundations of Ubiquitous Sensor Networks Triggers and Sensing David E. Culler University."

Similar presentations


Ads by Google