Presentation is loading. Please wait.

Presentation is loading. Please wait.

2008EECS194-51 Dealing with Analog Signals A Microcontroller View Jonathan Hui University of California, Berkeley.

Similar presentations


Presentation on theme: "2008EECS194-51 Dealing with Analog Signals A Microcontroller View Jonathan Hui University of California, Berkeley."— Presentation transcript:

1 2008EECS194-51 Dealing with Analog Signals A Microcontroller View Jonathan Hui University of California, Berkeley

2 2008EECS194-52 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

3 2008EECS194-53 An Analog World Transducers –Allow us to convert physical phenomena to a voltage potential in a well-defined way.

4 2008EECS194-54 Going From Analog to Digital What we want How we have to get there SoftwareSensorADC Physical Phenomena VoltageADC Counts Engineering Units Physical Phenomena Engineering Units

5 2008EECS194-55 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

6 2008EECS194-56 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

7 2008EECS194-57 Sampling Basics Resolution –Number of discrete values that represent a range of analog values –MSP430: 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

8 2008EECS194-58 Sampling Basics Converting: ADC counts  Voltage Converting: Voltage  Engineering Units

9 2008EECS194-59 Sampling Basics Converting values in 16-bit MCUs vtemp = adccount/4095 * 1.5; tempc = (vtemp-0.986)/0.00355;  tempc = 0 Fixed point operations –Need to worry about underflow and overflow Floating point operations –They can be costly on the node

10 2008EECS194-510 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…

11 2008EECS194-511 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

12 2008EECS194-512 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)

13 2008EECS194-513 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

14 2008EECS194-514 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 the range (min and max) Specify characteristics of the input signal (settling time) 2.Enable interrupt and set a bit to start a conversion 3.When interrupt occurs, read sample from data register 4.Wait for a sample period 5.Repeat step 1

15 2008EECS194-515 Block Diagram (MSP430)

16 2008EECS194-516 ADC Features Texas Instruments MSP430 Atmel ATmega 1281 Resolution12 bits10 bits Sample Rate200 ksps76.9 ksps Internally Generated Reference Voltage 1.5V, 2.5V, Vcc1.1V, 2.56V Single-Ended Inputs1216 Differential Inputs014 (4 with gain amp) Left Justified OptionNoYes Conversion ModesSingle, Sequence, Repeated Single, Repeated Sequence Single, Free Running Data Buffer16 samples1 sample

17 2008EECS194-517 ADC Core Input –Analog signal Output –12-bit digital value of input relative to voltage references Linear conversion

18 2008EECS194-518 SAR ADC SAR = Successive-Approximation-Register –Binary search to find closest digital value

19 2008EECS194-519 SAR ADC SAR = Successive-Approximation-Register –Binary search to find closest digital value 1 Sample  Multiple cycles

20 2008EECS194-520 SAR ADC 1 Sample  Multiple cycles

21 2008EECS194-521 Sample and Conversion Timing Timing driven by: –TimerA –TimerB –Manually using ADC12SC bit Signal selection using SHSx Polarity selection using ISSH

22 2008EECS194-522 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-

23 2008EECS194-523 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

24 2008EECS194-524 Software Configuration How it looks in code: ADC12CTL0 = SHT0_2 | REF1_5V | REFON | ADC12ON; ADC12CTL1 = SHP;

25 2008EECS194-525 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 Is this a multiplexor as you saw in CS150?

26 2008EECS194-526 Conversion Memory 16 sample buffer Each buffer configures sample parameters –Voltage reference –Input channel –End-of-sequence CSTARTADDx indicates where to write next sample

27 2008EECS194-527 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

28 2008EECS194-528 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;

29 2008EECS194-529 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(); }

30 2008EECS194-530 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(); }

31 2008EECS194-531 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(); }

32 2008EECS194-532 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(); }

33 2008EECS194-533 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(); }

34 2008EECS194-534 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(); }

35 2008EECS194-535 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


Download ppt "2008EECS194-51 Dealing with Analog Signals A Microcontroller View Jonathan Hui University of California, Berkeley."

Similar presentations


Ads by Google