State the Maximum Sampling Rate That a Pic24 Chip With Fcy=16mhz Can Handle,

Chapter 14: Analog to Digital Conversion, Data Acquisition and Control
Modified to exist compatible with EE319K Lab 8

Jonathan Valvano and Ramesh Yerraballi

Throughout this course we take seen that an embedded organisation uses its input/output devices to interact with the external world. In this chapter we will focus on input devices that we utilise to gather information about the world. More than specifically, nosotros present a technique for the system to measure analog inputs using an analog to digital converter (ADC). We will use periodic interrupts to sample the ADC at a fixed charge per unit. We define the rate at which nosotros sample as the sampling rate, and use the symbol fs. We volition then combine sensors, the ADC, software, PWM output and motor interfaces to implement intelligent control on our robot motorcar.

Learning Objectives:

  • Written report the nuts of transducers: conversion of physical to electric.
  • Develop a means for a digital computer to sense its analog world.
  • Review digitization: Quantization, range, precision and resolution.
  • Extend the Nyquist Theorem to cases where we utilize the ADC to sense information.
  • Apply the Central Limit Theorem to improve signal to dissonance ratio.
  • Use an optical sensor to measure out altitude to an object (EE319K skips this).

                     Video xiv.0. Introduction to Digitization

14.1. Data Conquering and Control Systems

                     Video fourteen.1. Digitization Concepts.

The measurand is a real world indicate of involvement like sound, distance, temperature, force, mass, pressure, menstruation, calorie-free and acceleration. Figure 14.1 shows the information flow graph for a data conquering system or control arrangement. x(t) is the fourth dimension-varying signal we are attempting to measure. The control system uses an actuator to drive a measurand in the real world to a desired value while the data conquering arrangement has no actuator because it simply measures the measurand in a nonintrusive manner. Consider an entire organization that collects information, non but the ADC. The following four limitations exist when sampling data.

  • Aamplitude resolution
  • Amplitude range
  • Fourth dimension quantization
  • Time interval

Amplitude resolution is the smallest change in input signal that tin be distinguished. For case, nosotros might specify the resolution every bit dX. Amplitude range is defined equally the smallest to largest input value that tin be measured. For example, we might specify the range as Xmin to Xmax. Amplitude precision is defined as the number of singled-out values from which the measurement is selected. The units of precision are given in culling or bits. If a system has 12-fleck precision, there are 2^12 or 4096 distinct alternatives. For case if we use a slide pot to measure altitude, the range of that pot might be 0 to one.5cm. If there is no electrical noise and we use a 12-bit ADC, then the theoretical resolution is ane.5cm/4095, or about 0.0004 cm. In most systems, the resolution of the measurement is determined past noise and not the number of bits in the ADC. Time quantization is the fourth dimension difference between one sample and the next. Time interval is the smallest to largest time during which we collect samples. If we use a 10-Hz SysTick interrupt to sample the ADC and calculate distance, the sampling charge per unit, fs, is 10 Hz, and the time quantization is 1/fs=0.1 sec. If we use a retentiveness buffer with 500 elements, then the fourth dimension interval is 0 to fifty sec.

: Assume Xmin, Xmax, and dX are all given in the aforementioned units. Give a formula that relates the precision in $.25 as a function of Xmin, Xmax and dX.

: Assume the precision is north in bits, and Xmin, Xmax, and dX are all given in the same units. Requite a formula that relates the resolution, dX every bit a part of Xmin, Xmax and n.

: Assume you take a 12-bit ADC and shop data into an array of blazon uint16_t. Let fs exist the sampling rate in Hz, and T be the full time interval required to collect samples in sec. Give a formula that relates needed retentiveness in bytes as a function of fs and T.

: Presume you accept an 8-flake ADC. Let the sampling rate be 100 Hz. Presume yous allocate 20,000 out of the available 32,768 bytes of RAM to shop the data. What is the respective fourth dimension interval? I.eastward., how many seconds of information can you lot tape?

: Assume you have a 4-bit DAC used to play sound. Let the sampling rate be 11 kHz. You can pack two DAC samples into ane byte. Presume yous classify 128 kibibytes out of the available 256 kibibytes of ROM to store the data. What is the corresponding time interval? I.east., how many seconds of audio can you play?

Figure xiv.1. Signal paths a data acquisition system.

The input or measurand is x. The output is y.  A transducer converts ten into y. A broad variety of inexpensive sensors can be seen at https://world wide web.sparkfun.com/categories/23 Examples include

· Sound                           Microphone

· Pressure, mass, force      Strain guess, force sensitive resistor

· Temperature                  Thermistor, thermocouple, integrated circuits

· Distance                        Ultrasound, lasers, infrared light

· Menstruation                             Doppler ultrasound, menstruation probe

· Acceleration                   Accelerometer

· Light                             Photographic camera

· Biopotentials                  Silverish-Silver Chloride electrode

A linear transducer is an input/output part fits a directly line. In other words, the input/output response fits a linear equation:

y = g*ten*b

where yard and b are constants. Software volition have an easy fourth dimension with a linear transducer. For example, the linear potentiometer, PTA20432015CPB10, has a transfer function as shown in Effigy 14.2, where the input x is distance in cm, and the output y is resistance in kΩ. Yous tin use a simple circuit to convert resistance to voltage, the ADC to convert voltage to an integer, and uncomplicated software to convert an integer to altitude.

Figure 14.2. The linear potentiometer distance sensor exhibits linear beliefs.

: Consider the linear potentiometer in Effigy 14.2. Allow 10 be the distance in cm and let y be the resistance in kohm. Give an appropriate transfer office showing y as a function of x.

A nonmonotonic transducer is an input/output role that does not accept a mathematical inverse. For case, if two or more input values yield the same output value, then the transducer is nonmonotonic. Software will have a difficult time correcting a nonmonotonic transducer. For example, the Precipitous GP2Y0A21YK IR distance sensor has a transfer function equally shown in Figure 14.3. If you read a transducer voltage of two V, yous cannot tell if the object is 3 cm away or 12 cm away. Nonetheless, if we assume the distance is always greater than 10cm, and then this transducer can be used. Details well-nigh transducers and actuators tin can be found in Embedded Systems: Existent-Fourth dimension Interfacing to ARM Cortex-M Microcontrollers, 2020, ISBN: 978-1463590154.

Effigy 14.iii. The Sharp IR altitude sensor exhibits nonmonotonic behavior.

xiv.2. The Analog to Digital Converter

An analog to digital converter (ADC) converts an analog bespeak into digital form, shown in Figure 14.4. An embedded arrangement uses the ADC to collect information most the external globe (data conquering system.) The input signal is unremarkably an analog voltage, and the output is a binary number. The ADC precision is the number of distinguishable ADC inputs (e.one thousand., 4096 alternatives, 12 bits). The ADC range is the maximum and minimum ADC input (e.g., 0 to +3.3V). The ADC resolution is the smallest distinguishable change in input (e.one thousand., 3.3V/4095, which is about 0.81 mV). The resolution is the change in input that causes the digital output to change by 1.

            Range(volts) = Precision(alternatives) Resolution(volts)

Figure 14.iv. A 12-fleck ADC converts 0 to 3.3V on its input into a digital number from 0 to 4095.

The about pervasive method for ADC conversion is the successive approximation technique, as illustrated in Figure fourteen.5. A 12-fleck successive approximation ADC is clocked 12 times. At each clock another bit is determined, starting with the near significant bit. For each clock, the successive approximation hardware issues a new "judge" on Vdac past setting the flake under examination to a "1". If Vdac is now college than the unknown input, Vin , and then the bit under test is cleared. If 5dac is less than Vin , then the fleck under test is remains 1. In this clarification, bit is an unsigned integer that specifies the scrap nether examination. For a 12-bit ADC, bit goes 2048, 1024, 512, 256,...,1. Dout is the ADC digital output, and Z is the binary input that is truthful if Vdac is greater than Fivein .

Effigy 14.5. A 12-bit successive approximation ADC.

                     Video xiv.2. Successive Approximation



Interactive Tool 14.1

This tool allows yous to go through the motions of a ADC sample capture using successive approximation. It is a game to demonstrate successive approximation. There is a secret number betwixt 0 to 63 (half-dozen-bit ADC) that the computer has selected. Your task is to acquire the secret number by making exactly 6 guesses. You can guess by entering numbers into the "Enter estimate" field and clicking "Approximate". The Tool will tell y'all if the number you guess is higher or lower than the secret number. When yous accept the respond, enter it into the "Concluding reply" field and click the "Submit answer" push button.


The secret number is ???

The secret number is strictly less than these guesses             :
The secret number is greater than or equal to these guesses :


: With successive approximation, what is the strategy when making the start judge? For example, if you had a 10 bit ADC, what would be your starting time estimate?

Observation: The speed of a successive approximation ADC relates linearly with its precision in bits.

Normally we don't specify accuracy for just the ADC, simply rather we give the accuracy of the entire system (including transducer, analog circuit, ADC and software). An ADC is monotonic if it has no missing codes equally the analog input slowly rises. This means if the analog indicate is a slowly rising voltage, and so the digital output will hit all values ane at a fourth dimension, e'er going upwards, never going down. The effigy of  merit of an ADC involves 3 factors:

  • precision (number of bits),
  • speed (how fast can we sample), and
  • power (how much energy does it accept to operate).

How fast we tin sample involves both the ADC conversion fourth dimension (how long information technology takes to convert), and the bandwidth (what frequency components tin can be recognized by the ADC). The ADC cost is a part of the number and quality of internal components. 2 12-bit ADCs are built into the TM4C123 microcontroller, chosen ADC0 and ADC1. You volition use ADC0 to collect data and we will use ADC1 and the PD3 pin to implement a voltmeter and oscilloscope using TExaSdisplay.

14.3. Details of the ADC on the TM4C123

Tabular array 14.1 shows the ADC0 register bits required to perform sampling on a single channel. Any bits non specified will read 0. There are two ADCs; you will utilize ADC0 and TExaSdisplay uses ADC1. For more complex configurations refer to the specific data sheet. The value in the ADC0_PC_R specifies the maximum sampling rate, see Table 14.2. This is non the bodily sampling charge per unit; it is the maximum possible. Setting ADC0_PC_R to seven, allows the TM4C123 to sample upwards to ane million samples per second. The example code in this section volition set ADC0_PC_R to ane, because nosotros will be sampling much slower than 125 kHz. Information technology will exist more accurate and crave less ability to run at 125 kHz maximum fashion, as compared to 1 MHz maximum way. In this affiliate we will use software trigger mode, and then the bodily sampling rate is determined past the SysTick periodic interrupt rate; the SysTick ISR will take one ADC sample. On the TM4C123, we will need to prepare $.25 in the AMSEL register to actuate the analog interface. Furthermore, we volition clear bits DEN annals to conciliate the digital interface.

Address

31-17

16

xv-3

2

one                0

Name

0x400F.E638

ADC1           ADC0

SYSCTL_RCGCADC_R

31-14

13-12

11-10

9-8

7-half dozen

v-iv

3-ii

one-0

0x4003.8020

SS3

SS2

SS1

SS0

ADC0_SSPRI_R

31-16

fifteen-12

11-eight

7-4

3-0

0x4003.8014

EM3

EM2

EM1

EM0

ADC0_EMUX_R

31-4

iii

ii

1

0

0x4003.8000

ASEN3

ASEN2

ASEN1

ASEN0

ADC0_ACTSS_R

0x4003.8030

AVE (3 bits)

ADC0_SAC_R

0x4003.80A0

MUX0

ADC0_SSMUX3_R

0x4003.8FC4

Speed

ADC0_PC_R

0x4003.80A4

TS0

IE0

END0

D0

ADC0_SSCTL3_R

0x4003.8028

SS3

SS2

SS1

SS0

ADC0_PSSI_R

0x4003.8004

INR3

INR2

INR1

INR0

ADC0_RIS_R

0x4003.800C

IN3

IN2

IN1

IN0

ADC0_ISC_R

31-12

xi-0

0x4003.80A8

DATA

ADC0_SSFIFO3

Table xiv.1. The TM4C ADC registers. Each annals is 32 bits wide. You will use ADC0 and we will apply ADC1 for the grader and to implement the oscilloscope feature.

Value

Description

0x7

1M samples/2d

0x5

500K samples/second

0x3

250K samples/2nd

0x1

125K samples/second

Table fourteen.2. The maximum sampling rate specified in the ADC0_PC_R register.

Tabular array 14.3 shows which I/O pins on the TM4C123 can exist used for ADC analog input channels.

IO

Own

0

1

two

three

iv

5

6

vii

eight

9

14

PB4

Ain10

Port

SSI2Clk

M0PWM2

T1CCP0

CAN0Rx

PB5

Ain11

Port

SSI2Fss

M0PWM3

T1CCP1

CAN0Tx

PD0

Ain7

Port

SSI3Clk

SSI1Clk

IiiC3SCL

M0PWM6

M1PWM0

WT2CCP0

PD1

Ain6

Port

SSI3Fss

SSI1Fss

IiiC3SDA

M0PWM7

M1PWM1

WT2CCP1

PD2

Ain5

Port

SSI3Rx

SSI1Rx

M0Fault0

WT3CCP0

USB0epen

PD3

Ain4

Port

SSI3Tx

SSI1Tx

IDX0

WT3CCP1

USB0pflt

PE0

Ain3

Port

U7Rx

PE1

Ain2

Port

U7Tx

PE2

Ain1

Port

PE3

Ain0

Port

PE4

Ain9

Port

U5Rx

IiiC2SCL

M0PWM4

M1PWM2

CAN0Rx

PE5

Ain8

Port

U5Tx

I2C2SDA

M0PWM5

M1PWM3

CAN0Tx

Table xiv.iii. Twelve unlike pins on the TM4C123 can be used to sample analog inputs.  The example code will apply ADC0 and PE4/Ch9 to sample analog input. TExaSdisplay uses ADC1 and PD3 to implement the oscilloscope feature.

The ADC has four sequencers, simply yous will use just sequencer 3 in EE319K Labs 8,9,10 (edX MOOC Labs 14 and 15). We set the ADC0_SSPRI_R register to 0x0123 to make sequencer 3 the highest priority. Because we are using simply one sequencer, we but demand to make sure each sequencer has a unique priority. We ready bits xv–12 (EM3) in the ADC0_EMUX_R register to specify how the ADC will be triggered. Table 14.4 shows the various ways to trigger an ADC conversion. More avant-garde ADC triggering techniques are presented in the volume Embedded Systems: Real-Time Interfacing to ARM® Cortex™-K Microcontrollers. However in this chapter, we utilise software offset (EM3=0x0). The software writes an 8 (SS3) to the ADC0_PSSI_R to initiate a conversion on sequencer 3. We can enable and disable the sequencers using the ADC0_ACTSS_R register. There are twelve ADC channels on the TM4C123. Which aqueduct we sample is configured by writing to the ADC0_SSMUX3_R register. The mapping between channel number and the port pin is shown in Table 14.three. For example channel ix is connected to the pin PE4. The ADC0_SSCTL3_R annals specifies the mode of the ADC sample. We set TS0 to measure temperature and clear information technology to measure the analog voltage on the ADC input pin. Nosotros fix IE0 so that the INR3 bit is set when the ADC conversion is complete, and clear it when no flags are needed. When using sequencer 3, there is simply i sample, so END0 will always be set, signifying this sample is the terminate of the sequence. In this course, the sequence will be just one ADC conversion. We set up the D0 flake to activate differential sampling, such every bit measuring the analog departure between ii ADC pins. In our example, we clear D0 to sample a unmarried-ended analog input. Because we set the IE0 bit, the INR3 flag in the ADC0_RIS_R register volition be set when the ADC conversion is consummate, Nosotros clear the INR3 fleck by writing an 8 to the viii to the ADC0_ISC_R register.

Value

Outcome

0x0

Software first

0x1

Analog Comparator 0

0x2

Analog Comparator 1

0x3

Analog Comparator 2

0x4

External (GPIO PB4)

0x5

Timer

0x6

PWM0

0x7

PWM1

0x8

PWM2

0x9

PWM3

0xF

Ever (continuously sample)

Table 14.4. The ADC EM3, EM2, EM1, and EM0 bits in the ADC_EMUX_R register.

Nosotros perform the following steps to configure the ADC for software start on one aqueduct. Program 14.1 shows a specific details for sampling PE4, which is channel 9. The role ADC0_InSeq3 will sample PE4 using software start and use busy-wait synchronization to wait for completion.

Step i. We enable the ADC clock chip 0 in SYSCTL_RCGCADC_R for ADC0.

Step 2. We enable the port clock for the pin that we will be using for the ADC input.

Step iii. We await for the two clocks to stabilize (some people establish extra delay prevented hard faults)

Step iv. Make that pin an input by writing zero to the DIR register.

Step five. Enable the alternative function on that pin by writing 1 to the AFSEL register.

Step vi. Disable the digital function on that pin by writing zero to the DEN register.

Step seven. Enable the analog function on that pin by writing i to the AMSEL register.

Stride viii. We set up the ADC0_PC_R register specify the maximum sampling rate of the ADC. In this instance, we volition sample slower than 125 kHz, so the maximum sampling rate is set at 125 kHz. This will require less power and produce a longer sampling time, creating a more accurate conversion.

Stride ix. We will prepare the priority of each of the four sequencers. In this case, we are using simply one sequencer, so the priorities are irrelevant, except for the fact that no two sequencers should have the aforementioned priority.

Footstep 10. Before configuring the sequencer, we need to disable it. To disable sequencer 3, nosotros write a 0 to bit 3 (ASEN3) in the ADC0_ACTSS_R register. Disabling the sequencer during programming prevents erroneous execution if a trigger result were to occur during the configuration process.

Step 11. We configure the trigger outcome for the sample sequencer in the ADC0_EMUX_R register. For this instance, nosotros write a 0000 to bits fifteen–12 (EM3) specifying software start mode for sequencer 3.

Step 12. Configure the respective input source in the ADC0_SSMUX3 register. In this example, we write the channel number to bits iii–0 in the ADC0_SSMUX3_R register. In this example, we sample channel 9, which is PE4.

Step 13. Configure the sample command bits in the respective nibble in the ADC0_SSCTL3 register. When programming the last crumb, ensure that the END fleck is set. Failure to gear up the END fleck causes unpredictable behavior. Sequencer three has only one sample, so we write a 0110 to the ADC0_SSCTL3_R register. Scrap 3 is the TS0 scrap, which we clear considering nosotros are not measuring temperature. Bit two is the IE0 bit, which we set considering we desire to the RIS bit to exist prepare when the sample is complete. Bit 1 is the END0 bit, which is set considering this is the last (and merely) sample in the sequence. Bit 0 is the D0 bit, which we articulate because we practice not wish to utilize differential mode.

Step 14. Disable interrupts in ADC by clearing bits in the ADC0_IM_R annals. Since we are using sequencer 3, we disable SS3 interrupts by immigration chip 3.

Step 15. We enable the sample sequencer logic by writing a 1 to the respective ASEN3. To enable sequencer 3, nosotros write a i to bit 3 (ASEN3) in the ADC0_ACTSS_R annals.

void ADC0_InitSWTriggerSeq3_Ch9(void){
SYSCTL_RCGCADC_R |= 0x0001;   // 1) activate ADC0
SYSCTL_RCGCGPIO_R |= 0x10;    // two) activate clock for Port East
while((SYSCTL_PRGPIO_R&0x10) != 0x10){};  // 3 for stabilization
GPIO_PORTE_DIR_R &= ~0x10;    // four) make PE4 input
GPIO_PORTE_AFSEL_R |= 0x10;   // 5) enable alternate function on PE4
GPIO_PORTE_DEN_R &= ~0x10;    // 6) disable digital I/O on PE4
GPIO_PORTE_AMSEL_R |= 0x10;   // 7) enable analog functionality on PE4
// while((SYSCTL_PRADC_R&0x0001) != 0x0001){}; // practiced lawmaking, simply not implemented in simulator
ADC0_PC_R &= ~0xF;
ADC0_PC_R |= 0x1;             // viii) configure for 125K samples/sec
ADC0_SSPRI_R = 0x0123;        // 9) Sequencer 3 is highest priority
ADC0_ACTSS_R &= ~0x0008;      // 10) disable sample sequencer 3
ADC0_EMUX_R &= ~0xF000;       // 11) seq3 is software trigger
ADC0_SSMUX3_R &= ~0x000F;
ADC0_SSMUX3_R += 9;           // 12) fix channel
ADC0_SSCTL3_R = 0x0006;       // thirteen) no TS0 D0, yes IE0 END0
ADC0_IM_R &= ~0x0008;         // xiv) disable SS3 interrupts
ADC0_ACTSS_R |= 0x0008;       // 15) enable sample sequencer iii
}

Program 14.i. Initialization of the ADC using software offset and busy-wait (ADCSWTrigger).

                     Video fourteen.3. ADC Initialization Ritual

Programme 14.2 gives a function that performs an ADC conversion. There are iv steps required to perform a software-start conversion. The range is 0 to 3.3V. If the analog input is 0, the digital output will be 0, and if the analog input is 3.3V, the digital output will exist 4095.

            Digital Sample = (Analog Input (volts) 4095) / 3.3V(volts)

Stride 1. The ADC is started using the software trigger. The channel to sample was specified earlier in the initialization.

Step 2. The role waits for the ADC to complete by polling the RIS register bit 3.

Step 3. The 12-bit digital sample is read out of sequencer 3.

Step four. The RIS chip is cleared by writing to the ISC annals.

Figure xiv.iii. The four steps of analog to digital conversion: 1) initiate conversion, 2) wait for the ADC to end, 3) read the digital result, and 4) clear the completion flag.

//------------ADC0_InSeq3------------

// Busy-wait analog to digital conversion

// Input: none

// Output: 12-flake upshot of ADC conversion

uint32_t ADC0_InSeq3(void){  uint32_t result;

  ADC0_PSSI_R = 0x0008;            // 1) initiate SS3

  while((ADC0_RIS_R&0x08)==0){};   // ii) await for conversion done

  result = ADC0_SSFIFO3_R&0xFFF;   // 3) read result

  ADC0_ISC_R = 0x0008;             // 4) acknowledge completion

  render event;

}

Program 14.2. ADC sampling using software start and busy-look (ADCSWTrigger).

                     Video 14.four. Capturing a Sample

It is important to sample the ADC at a regular rate. 1 simple style to deploy periodic sampling is to perform the ADC conversion in a periodic ISR. In the following code, the sampling rate is determined by the rate of the periodic interrupt. The global variable, Flag is chosen a semaphore, which is set when new information is stored into the variable Data. We can connect PF1 to a logic analyzer or oscilloscope to verify the sampling rate.

uint32_t Data; // 0 to 4095
uint32_t Flag; // 1 means new data
void SysTick_Handler(void){
GPIO_PORTF_DATA_R ^= 0x02; // toggle PF1
Data = ADC0_InSeq3();      // Sample ADC
Flag = ane;                  // Synchronize with other threads
}

In that location is software in the volume Embedded Systems: Real-Time Interfacing to ARM® Cortex™-One thousand Microcontrollers showing you how to configure the ADC to sample a single aqueduct at a periodic rate using a timer trigger. The almost time-authentic sampling method is timer-triggered sampling (EM3=0x5).

: If the input voltage is 1.65V, what value will the TM4C 12-fleck ADC return?

: If the input voltage is 1.0V, what value will the TM4C 12-chip ADC return?

14.4. Nyquist Theorem

To collect information from the external earth into the reckoner nosotros must catechumen information technology from analog into digital form. This conversion process is called sampling and because the output of the conversion is one digital number at one bespeak in time, at that place must exist a finite time in between conversions, Δt. If we use SysTick periodic interrupts, then this Δt is the time between SysTick interrupts. We define the sampling charge per unit as

fsouthward = 1/Δt

If this information oscillates at frequency f, then according to the Nyquist Theorem, we must sample that signal at

fsouthward > 2f

Furthermore, the Nyquist Theorem states that if the betoken is sampled with a frequency of fdue south , then the digital samples just contain frequency components from 0 to ½ fs . Conversely, if the analog signal does contain frequency components larger than ½ fs , and then in that location volition be an aliasing error during the sampling procedure (performed with a frequency of fs ). Aliasing is when the digital point appears to have a different frequency than the original analog betoken.

Interactive Tool 14.two:

Discover the Nyquist Theorem. In this animation, you lot control the analog signal by dragging the handle on the left. Click and drag the handle up and down to create the analog moving ridge (the blueish continuous wave). The betoken is sampled at a fixed rate (fs = 1Hz) (the red wave). The digital samples are connected by direct red lines then yous tin can encounter the data as captured by the digital samples in the computer.

Practise 1: If you move the handle up and down very slowly y'all will observe the digital representation captures the essence of the analog wave y'all have created past moving the handle. If yous wiggle the handle at a rate slower than ½ fs , the Nyquist Theorem is satisfied and the digital samples faithfully capture the essence of the analog signal.

Exercise 2: Notwithstanding if you wiggle the handle quickly, yous will detect the digital representation does not capture the analog wave. More specifically, if you wiggle the handle at a charge per unit faster than ½ fsouthward the Nyquist Theorem is violated causing the digital samples to be fundamentally unlike from the analog wave. Endeavour wiggling the handle at a fast but constant rate, and you will notice the digital wave also wiggles but at an wrong frequency. This incorrect frequency is called aliasing.


Figure 14.iv shows what happens when the Nyquist Theorem is violated. In both cases a signal was sampled at 2000 Hz (every 0.five ms). In the get-go figure the 200 Hz indicate is properly sampled, which ways the digital samples accurately draw the analog bespeak. However, in the 2nd effigy, the 2200 Hz signal is not sampled properly, which means the digital samples exercise not accurately describe the analog point. This fault is called aliasing. Aliasing occurs when the input signal oscillates faster than the sampling rate and it characterized by the digital samples "looking like" information technology is oscillating at a different charge per unit than the original analog signal. For these two sets of sampled information, notice the digital data are exactly the aforementioned.

Figure 14.4. Aliasing occurs when the input analog signal oscillates faster than the rate of the ADC sampling.

                     Video 14.5. Aliasing Demonstration: The Wagon Wheel Effect

: Assume you wish to represent sounds in digital form on the computer, either equally inputs sampled from an ADC, or as outputs created with a DAC. The approximate range of canine hearing is 40 to 60 kHz. What sampling rate preverves all information for canine sound?

: The sounds in Lab ten are sampled at 11 kHz. What range of frequencies tin can exist in the samples?

: Assume the input is a pure sine wave at one kHz, 1.65+ane*sin(2*pi*1k*t), and the ADC is sampled at 2 kHz. Will the information be properly represented in the digital data?

Valvano Postulate : If fmax is the largest frequency component of the analog indicate, and so you must sample more than ten times fmax in society for the reconstructed digital samples to look similar the original signal when plotted on a voltage versus fourth dimension graph.

14.5. Central Limit Theorem

The resolution of a measurement organisation is the smallest change in input that tin can be reliably detected. The accuracy of a measurement system is the average difference betwixt measured value and truth. For virtually systems, resolution and accurateness are dominated by noise, rather than the precision of the ADC. To improve signal to racket ratio, we tin sample the ADC multiple times and average the samples.

Assume the true signal is μ. More formally, μ is the expected value of the bespeak. When we sample the signal, noise is added, and so the sampled data does not equal the truth. Permit x1, x2, x3,... be sampled information on the same truthful signal. To use the Fundamental Limit Theorem (CLT) nosotros will make the post-obit assumptions:

1) the added dissonance is independent (the added dissonance of one sample is not related to the added racket of another sample);
2) the added racket has the aforementioned probability distribution (whatever concrete procedure that generated the noise in i sample, creates dissonance in the other samples);

The CLT states that if you take a bespeak with mean μ and standard deviation σ and have sufficiently large random samples (n>30), and calculate the average

X = (sum(x1+x2+...+xn))/n

then the distribution of X will be approximately ordinarily distributed (Gaussian). More than importantly, the expected value of X will arroyo μ. If the noise has naught mean (as likely to be additive as subtractive), so X will approach the true signal as north increases. One approximate of noise is the standard deviation of multiple samples.

Southward = sqrt((sum((x1-X)^two+(x2-X)^2+...+(xn-X)^ii))/n)

There is a manner on the ADC to automatically accept multiple samples and return the average. The ADC0_SAC_R register can exist any value from 0 to half dozen. The possible choices are

ADC0_SAC_R = 0;  // take one sample
ADC0_SAC_R = i;  // take 2 samples, return average
ADC0_SAC_R = ii;  // take four samples, render average
ADC0_SAC_R = 3;  // have 8 samples, return average
ADC0_SAC_R = 4;  // accept sixteen samples, return average
ADC0_SAC_R = 5;  // take 32 samples, return average
ADC0_SAC_R = half-dozen;  // take 64 samples, return average

You lot will notice the signal to noise ratio will improve dramatically if you use hardware averaging. However, the disadvantage of hardware averaging is the fourth dimension to convert. If taking one sample takes 8us, then activating 32-bespeak hardware averaging volition increase the fourth dimension to sample to 32*eight=128us. Similarly, it will take more than electrical ability to deploy hardware averaging.

                     Video . Central Limit Theorem

Because of noise, if we set the ADC input to a constant voltage, and sample information technology many times, nosotros volition become a distribution of digital outputs. We plot the number of times we got an output as a office of the output sample. The shape of this response is chosen a probability mass function (pmf) characterizing the noise processes. A pmf plots the number of occurrences versus the ADC sample value. To illustrate the CTL, one.65V was connected to PE2 and the software in Department 14.three was used to measure the ADC 1000 times. The experiment was performed at 3 values of ADC0_SAC_R: 0 (1 point), two (four-point average), and 4 (xvi-point boilerplate). Notice the shape becomes Gaussian and the standard deviation reduces. In item, the data with 1 point (no averaging) has two or three humps (not normally distributed), but with xvi-bespeak average there is ane symmetric hump (normally distributed)

Figure xiv.v. Probability mass functions showing hardware averaging improves signal to racket ratio.

: Give an advantage of using hardware averaging.

: Give ii disadvantages of using hardware averaging.

: The TM4C123 has hardware averaging. What would you lot do if you want to deploy averaging, but you are using a different microcontroller that does not support hardware averaging?

14.6. C++ on the TM4C123, EE319H only

In near aspects, running C++ on the microcontroller is identical to running C++ on other machines. However, be enlightened of the memory limitations of the TM4C123. To run C++ we volition create a small heap and continue to have a small stack, knowing that all globals, statics, locals, and heap must fit into the 32 kibibytes of RAM on the TM4C123. The post-obit code exists in the startup file for Lab8_C++ project, creating 1024 bytes of stack and 512 bytes of heap.

Stack_Size EQU 0x00000400
Area STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; Heap Configuration
Heap_Size EQU 0x00000200
Surface area HEAP, NOINIT, READWRITE, Align=three
__heap_base
Heap_Mem Infinite Heap_Size
__heap_limit

                     Video . Running C++ on the TM4C123.

                     Video . Running a vector.cpp C++ instance from EE312H on the TM4C123.

EE319K Lab 8 videos

Educational Objectives of Lab viii

• Sampling
— ADC conversion
— Interrupt-driven periodic sampling
— Calibration and accuracy
— Nyquist Theorem
— Key Limit Theorem
• Thread synchronization
— Postal service box
• Fixed-signal numbers
— Value = Integer*Constant
• Modular development
• Object oriented blueprint in C++ (EE319H)

Lab8_Introduction

In this video we review the software starter projection and overview the design steps for implementing Lab 8. The full scale range of the measurement is adamant by the concrete size of the potentiometer (some move 0 to one.5cm, and others movement 0 to two.0cm).

Lab8_SlidePot

We show how to adhere slide pot to protoboard. This slide potentiometer has a range of 0 to 2 cm.

Lab8_Calibration

In this video we demonstrate the steps to calibrate the device. We activate hardware averaging to better signal to noise ratio

Lab8_Accuracy

In this video we demonstrate the steps to determine accuracy of the device. We will also show you how to estimate resolution. We actuate hardware averaging to amend point to noise ratio.

Collect ii to five measurements with your distance measurement system. In the left column place the true distances as determined by your eyes looking at the cursor and the ruler. In the right cavalcade place the measured distances as determined by your organisation. When yous have entered at least ii sets of data, click the "Calculate" button.

True values          |  Measured values  |    Errors

The number of data sets is
The maximum error is
The average mistake is


Lab8_Demo

Demonstration of Lab viii final solution

14.seven. Robot Motorcar Controller, EE319K/EE319H students tin can skip department fourteen.7

The goal is to bulldoze a robot machine autonomously downward a road. Autonomous driving is a difficult problem, and we have greatly simplified it and will use this unproblematic trouble to illustrate the components of a control arrangement. Every control arrangement has existent-world parameters that it wishes to control. These parameters are called land variables. In our system we wish to drive down the middle of the road, so our state variables will be the distance to the left side of the road and the distance to the right side of the road as illustrated in Figure 14.7. When we are in the heart of the route these ii distances volition exist equal. And then, allow's define Error every bit:

Error = Dleft Dright

If Error is goose egg we are in the center of the road, so the controller will attempt to drive the Fault parameter to cypher.

Figure 14.7. Physical layout of the autonomous robot as is drives downwards the route.

                     Video 14.6a. IR Sensor for Robot Motorcar

We will need sensors and a data acquisition system to mensurate Dleft and Dright . In order to simplify the trouble we volition place pieces of wood to create walls along both sides of the road, and make the road the same width at all places along the runway. The Sharp GP2Y0A21YK0F infrared object detector tin can measure distance (http://www.sharpsma.com) from the robot to the forest. This sensor creates a continuous analog voltage between 0 and +3V that depends inversely on distance to object, come across Figure fourteen.half-dozen.  We volition avert the 0 to 10 cm range where the sensor has the nonmonotonic behavior. We volition apply two ADC channels (PE4 and PE5) to convert the two analog voltages to digital numbers. Permit Left and Right be the ADC digital samples measured from the ii sensors.  We tin can presume distance is linearly related to 1/voltage, we can implement software functions to calculate altitude in mm as a function of the ADC sample (0 to 4095). The 241814 abiding was found empirically, which means nosotros nerveless information comparing actual distance to measured ADC values.

Dleft = 241814/ Left

Dright = 241814/ Correct

Figure 14.8 shows the accuracy of this data conquering system, where the estimated distance, using the to a higher place equation, is plotted versus the true distance.

Figure 14.eight. Measurement accurateness of the Sharp GP2Y0A21YK0F altitude sensor used to measure distance to wall.

Next we need to extend the robot built in Instance 12.2. First nosotros build two motor drivers and connect one to each bike, as shown in Figure 14.9. In that location will be two PWM outputs: PA6 controls the right motor attached to the correct wheel, and PA5 controls the left motor attached to the left wheel. The motors are classified as actuators because they exert force on the world. Similar to Example 12.ii nosotros will write software to create two PWM outputs so we can independently conform power to each motor. If the friction is constant, the resistance of the motor, R, will exist fixed and the ability is

Power = (8.iv2/R)*H/(H+L)

When creating PWM, the period (H+L) is fixed and the duty cycle is varied by changing H. And so we encounter the robot controller changes H, it has a linear result on delivered ability to the motor.

Effigy 14.nine. Circuit diagram of the robot car. One motor is wire reversed from the other, because to move frontwards i motor must spin clockwise while the other spins counterclockwise.

The currents can range from 500mA to one A, so TIP120 Darlington transistors are used, because they can sink upwards to 3 A see data canvass. Detect the dark black lines in Effigy 14.9; these lines signify the paths of these big currents. Discover also the currents do not laissez passer into or out of the LaunchPad. Figure xiv.ten shows the robot car. The ii IR sensors are positioned in the forepart at well-nigh 45 degrees.

Figure fourteen.10. Photograph of the robot car.

                     Video 14.7. Autonomous Robot Demonstration

Figure 14.11 illustrates the feedback loop of the control system. The state variables are Dleft and Dcorrect . The two sensors create voltages that depend on these two state variables. The ADC samples these ii voltages, and software calculates the estimates Dleft and Dright . Error is the difference between Dleft and Dright . The correct motor is powered with a constant duty cycle of 40%, while the duty cycle of the left motor is adjusted in an attempt to drive down the middle of the road.  We will constrain the duty cycle of the left motor to between 30% and 50%, so it doesn't over recoup and spin in circles. If the robot is closer to the left wall ( Dleft < Dright ) the error will be negative and more than power will be applied to the left motor, turning it right. Conversely, if the robot is closer to the right wall ( Dleft > Dright ) the mistake will be positive and less power volition be practical to the left motor, turning information technology left. Once the robot is in the middle of the road, mistake will exist zero, and power will not be changed. This control algorithm can exist written as a set of elementary equations. The number "200" is the controller gain and is institute by trial and mistake once the robot is placed on the route. If it is boring to react, then we increase gain. If it reacts as well rapidly, we decrease the proceeds.

         Error = Dleft - Dright

         LeftH = LeftH – 200*Mistake;

         if(LeftH < 30*800) LeftH=thirty*800;  // 30% min

         if(LeftH > 50*800) LeftH=50*800;  // l% max

         LeftL = 80000 - LeftH;            // constant catamenia

Observation: In the field of control systems, a popular arroyo is chosen PID command, which stands for proportional integral derivative. The above simple algorithm really implements the integral term of a PID controller. Furthermore, the two if statements in the control software implement a feature called anti-reset windup.

These controller equations are executed in the SysTick ISR so the controller runs at a periodic rate.

Figure fourteen.11. Block diagram of the airtight loop used in the robot car.

                     Video 14.6b. The Robot Command System

Details about microcontroller-based control systems can exist institute in Affiliate 10 of Embedded Systems: Real-Time Operating Systems for ARM® Cortex-Chiliad Microcontrollers, 2014, ISBN: 978-1466468863.

Bill of Materials

1) Ii DC geared motors, HN-GH12-1640Y,GH35GMB-R, Jameco Part no. 164786
- 0.23in or 6 mm shaft (get hubs to match)
ii) Metal or woods for base of operations,
3) Hardware for mounting
- 2 motor mounts 1-ane/4 in. PVC Conduit Clamps Model # E977GC-CTN Store SKU # 178931 www.homedepot.com
- some way to attach the LaunchPad (I used an Erector set, but you lot could use rubber bands)
4) Ii wheels and two hubs to lucifer the diameter of the motor shaft
- Shepherd ane-1/4 in. Pulley Safe Bike Model # 9487 www.homedepot.com
- ii 6mm hubs Dave's Hubs - 6mm Hub Prepare of Two Office# 0-DWH6MM www.robotmarketplace.com
- 2 3-Inch Diameter Treaded Calorie-free Flite Wheels 2pk Role# 0-DAV5730 world wide web.robotmarketplace.com
five) Ii GP2Y0A21YK IR range sensors
- Sparkfun, world wide web.sparkfun.com SEN-00242 or http://www.parallax.com/product/28995
vi) Battery
- 8.4V NiMH or eleven.1V LiIon. I bought the 8.4V NiMH batteries you see in the video as surplus a long time ago. I teach a real-time OS class where students write an Os then deploy it on a robot. I have a big pile of these viii.4V batteries, so I used a couple for the two robots in this course. NiMH are easier to charge, but I suggest Li-Ion because they store more energy/weight. For my medical instruments, I employ a lot of Tenergy 31003 (7.4V) and Tenergy 31012 (eleven.1V) (cyberspace search for the best price). Y'all will need a Li-Ion charger. I have used both of these Tenergy TLP-4000 and Tenergy TB6B chargers.
7) Electronic components
- two TIP120 Darlington NPN transistors
-ii 1N914 diodes
-2 10uF tantalum caps
- 7805 regular
-2 10k resistors

Websites to purchase robot parts

Robot parts

Pololu Robots and Electronics
Jameco'southward Robot Shop
Robot Marketplace
Sparkfun
Parallax
Belfry Hobbies

Surplus parts

BG Micro
All Electronics

Full-service parts

Newark (US) or element14 (worldwide)
Digi-Key
Mouser
Jameco

Part search engine

Octopart

Reprinted with approval from Embedded Systems: Introduction to ARM Cortex-M Microcontrollers, 2014, ISBN: 978-1477508992, http://users.ece.utexas.edu/~valvano/arm/outline1.htm
from Embedded Systems: Real-Time Interfacing to ARM Cortex-Grand Microcontrollers, 2014, ISBN: 978-1463590154, http://users.ece.utexas.edu/~valvano/arm/outline.htm

and from Embedded Systems: Real-Fourth dimension Operating Systems for the ARM Cortex-Yard Microcontrollers , 2014, ISBN: 978-1466468863, http://users.ece.utexas.edu/~valvano/arm/outline3.htm

Creative Commons License
Embedded Systems - Shape the World by Jonathan Valvano and Ramesh Yerraballi is licensed under a Artistic Eatables Attribution-NonCommercial-NoDerivatives 4.0 International License.
Based on a work at http://users.ece.utexas.edu/~valvano/arm/outline1.htm.

correabereest.blogspot.com

Source: https://users.ece.utexas.edu/~valvano/Volume1/E-Book/C14_ADCdataAcquisition.htm

0 Response to "State the Maximum Sampling Rate That a Pic24 Chip With Fcy=16mhz Can Handle,"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel