Lecture 5: PIC32 development board, Timers ADC and interrupts,

Slides:



Advertisements
Similar presentations
Analog to digital converter
Advertisements

The 8051 Microcontroller and Embedded Systems
Analog-to-Digital Converter (ADC) And
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN.
Data Acquisition Concepts Data Translation, Inc. Basics of Data Acquisition.
Lecture 11 Digital-to-Analog Converters and Analog Comparators.
Analog Comparator Positive input chooses bet. PB2 and Bandgap Reference. Negative input chooses bet. PB3 and the 8 inputs of the A/D. ACME= Analog Comparator.
1 Lab2: A/D Converter. 2 This circuit connects a variable voltage to an A/D port on the AVR mcu. Your software running on the AVR mcu will read the digital.
5-1 Analogue Input/Output Many sensors/transducers produce voltages representing physical data.  To process transducer data in a computer requires conversion.
Slides created by: Professor Ian G. Harris Inputs and Outputs PIC Vcc RA3 RA4 RA5  Make an LED toggle state when button is pressed  Need to read RA3,
1 Analog-to-Digital Converter (ADC). 2 ADC Features (1/3) ADC conversion rate 1 MHz and 12-bit resolution – 1µs conversion time at 56 MHz – 1.17µs conversion.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
1 ECE 263 Embedded System Design Lessons 2, 3 68HC12 Hardware Overview, Subsystems, and memory System.
Railway Foundation Electronic, Electrical and Processor Engineering.
ASPPRATECH.
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
EEE527 Embedded Systems Lecture 8: Practical Interrupts Ian McCrumRoom 5B18, Tel: voice mail on 6 th ring Web site:
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
System Clocks.
Chapter 4 TIMER OPERATION
MICROPROCESSOR INPUT/OUTPUT
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Digital to Analogue Converter
Lecture 13 A/D Converter & D/A Converter. Outline Basic Operation Single Scan Mode Continuous Scan Mode Group Scan Mode Interrupt Sources Registers D/A.
One of the most important feature of the microcontroller is a number of input/output pins used for connection with peripherals. In the case of PIC 167CX,
ELN5622 Embedded Systems Class 7 Spring, 2003 Aaron Itskovich
ELE2MIC Lecture 21 The AVR Sleep Modes ATMEGA128’s Analog to Digital Converter –Features –Block Diagram –Clock Source –Input Sources –Interrupts –BandGap.
SIGMA-DELTA ADC SD16_A Sigma-Delta ADC Shruthi Sujendra.
Prepared by Eng. Musa Alyaman1 Chapter Seven Chapter Seven PIC16F87x.
1 LHO 13 The 8051CF020 and the University Daughter Card.
EEE527 Embedded Systems Lecture 10B:Chapter 11 Analogue to Digital Convertors (ADCs) (version 2: 25/11/13, see after slide 20 Ian McCrumRoom 5B18, Tel:
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
8051 Micro controller. Architecture of 8051 Features of 8051.
ECE/CS-352: Embedded Microcontroller Systems The Silicon Laboratories C8051F020 Enhanced 8051 Part 4 Timer3, Temperature Sensor, AD0WINT.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
Alexei SemenovGeneric Digitizer Generic Digitizer 10MHZ 16 bit 6U VME Board.
CS224 I/O. Timers Timer1 is 16-bit timer 2^16-1 or 65,535 SYSCLK = 40MHz, Prescalers – 1:1, 1:8, 1:64, and 1:256 – Use T1CONbits.TCKPS=3 for 1:256 scaling.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Analog Capture- Port E. Digital to Analog and Analog to Digital Conversion D/A or DAC and A/D or ADC.
By James Cockrell and Justin Loveless
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose:  This course provides an overview of the serial communication.
Chapter 5 - Interrupts.
Chapter 11 Data Acquisition and Manipulation The aims of this chapter are to introduce: the main features of a data acquisition system; the characteristics.
Lab 3: ADC.
Device Overview 1.  The advantages of all PIC18Fxxxx microcontrollers:  High computational performance  High-endurance  Enhanced Flash program memory.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
Chapter 12 Some PIC Microcontroller Advances The aims of this chapter are to introduce: To introduce in overview two microcontrollers which show some enhanced.
Chapter Microcontroller
ADC 1 Analog to Digital Converter. ADC 2 ADC Features n General Features -Supports 8 or 10-bit resolution Modes, -Track period fully programmable up to.
Lecture Notes / PPT UNIT III
EE 319K Introduction to Embedded Systems
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
MECH 373 Instrumentation and Measurements
Why are Timer Functions Important?
Basic Computer Organization and Design
SAR ADC Input Types TIPL 4003 TI Precision Labs – ADCs
EI205 Lecture 13 Dianguang Ma Fall 2008.
UNIT – Microcontroller.
RX Compare Match Timer (CMT)
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
Chapter 7 Features and Interfacing of Programmable Devices for 8085 based systems.
Chapter 10 It’s an Analog World
Introducing the PIC Mid-Range Family and the 16F84A
Lecture 13 A/D Converter & D/A Converter
MSP432™ MCUs Training Part 6: Analog Peripherals
Pondicherry Engineering College
Presentation transcript:

Lecture 5: PIC32 development board, Timers ADC and interrupts, Embedded Systems Lecture 5: PIC32 development board, Timers ADC and interrupts, Ian McCrum Room 5B18, Tel: 90 366364 voice mail on 6th ring Email: IJ.McCrum@Ulster.ac.uk Web site: http://www.eej.ulst.ac.uk

Timers PIC32MX1xx/2xx family have 5 (6 counting the internal core timer) you can just read the 32 bit number that increments automatically There is a Plib function ReadCoreTimer(void); that returns an unsigned int. It runs at half the system frequency. Note figure 8-1 from the datasheet

Timers type A and type B;

TIMER1: Type A a 16 bit counter that has a PR1 register allowing generating a trigger, either when overflow occurs or when the count equals the value held in PR1. It can use the system clock (actually the Peripheral clock PBCLK) either direct or divided by 1,8,16 or 64. Or it can use an external clock, either an input or an external crystal Relevant register is T1CON. The trigger condition raises the T1IF Flag

Timers type B; (Timers 2,3 and Timers 4,5)

TMRx is even – timer 2 or 4 TMRy is odd – timer 3 or 5 X is the master timer, y is slave

Code for type A – 16 bit Timer1 - see next slide for T1CON again…

Using Interrupts with Timer 1 (plib calls)

Try this code and then do the exercises at the end…

Using the Analogue to Digital Convertor (ADC) The 10-bit Analog-to-Digital Converter (ADC) includes the following features: • Successive Approximation Register (SAR) conversion • Up to 1 Msps conversion speed • Up to 13 analog input pins • External voltage reference input pins • One unipolar, differential Sample and Hold Amplifier (SHA) • Automatic Channel Scan mode • Selectable conversion trigger source • 16-word conversion result buffer • Selectable buffer fill modes • Eight conversion result format options • Operation during Sleep and Idle modes 11.1.2 CONFIGURING ANALOG AND DIGITAL PORT PINS The ANSELx register controls the operation of the analog port pins. The port pins that are to function as analog inputs must have their corresponding ANSEL and TRIS bits set.

ANSELA on Our PIC

Overview of Operation Analog sampling consists of two steps: acquisition and conversion Sample start time can be controlled in software by setting the SAMP bit (AD1CON1<1>) or controlled automatically by the ASAM bit (AD1CON1<2>) Conversion time is the time required for the ADC to convert the voltage held by the SHA. The ADC requires one ADC clock cycle (TAD) to convert each bit of the result, plus two additional clock cycles. Therefore, a total of 12 TAD cycles are required to perform the complete conversion. When the conversion time is complete, the result is written into one of the 16 ADC result registers (ADC1BUF0 through ADC1BUFF). The sum of the acquisition time and the analog-to-digital conversion time provides the total sample time The conversion trigger source SSRC<2:0> (AD1CON1<7:5>) ends the sampling time and begins an ADC conversion. Taken from a variety of hardware sources, or can be controlled manually in software by clearing the SAMP bit. The Auto-Sample mode and auto-conversion trigger can be used together to provide endless automatic conversions without software intervention. The ADC can optionally switch between MUX A and MUX B configurations between conversions. The ADC can also optionally scan through a series of analog inputs using a single MUX.

Note, inputs can be single or differential, we can use external Vref + and - Very powerful buffer system The DP32 board has AN9 wired to a Variable Resistor AN9 is RB15/RPB15, pin 26 on the 28 pin device

Note, inputs can be single or differential, we can use external Vref + and - The DP32 board has AN9 wired to a Variable Resistor AN9 is RB15/RPB15, pin 26 on the 28 pin device

So you can repetitively sample a selected range of channels, the values are stored in the buffer registers An interrupt may be generated at the end of each sample sequence or multiple sample sequences as determined by the value of the SMPI<3:0> bits (AD1CON2<5:2>). The number of sample sequences between interrupts can vary between 1 and 16. The user should note that the analog-to-digital conversion buffer holds the results of a single conversion sequence.

ANSELB=0x0080 The DP32 board has AN9 wired to a Variable Resistor AN9 is RB15/RPB15, pin 26 on the 28 pin device Redo this code for AN9

The DP32 board has AN9 wired to a Variable Resistor ANSELB = 0x0080 The DP32 board has AN9 wired to a Variable Resistor AN9 is RB15/RPB15, pin 26 on the 28 pin device Redo this code for AN9

Bit 15 ON 1 = ADC is operating Bit 13 SIDL only relevant in idle mode Bit 10-8 FORM<2:0> 000 = 16 bit Data out – bottom 10 bits are the reading Bit 7-5 SSRC<2:0> 000 = clearing SAMP bit ends sampling and starts conversion Bit 4 CLRASAM 0 = normal, buffer get overwritten by next conversion sequence Bit 2 ASAM 1 = sampling begins as soon as last conversion complete 0 = Sampling begins when SAMP bit is set Bit 1 SAMP 1 = ADC sample and hold Amp is sampling 0 = ADC sample and hold Amp is holding When ASAM = 0, writing ‘1’ to this bit starts sampling When SSRC = 000, put ‘0’ in SAMP -ends sampling & starts conversion Bit 0 DONE 1 = ADC conversion is done

Bit 15-13 VCFG<2:0> 000 = Vrefh = AVDD and Vrefl = Avss (3 Bit 15-13 VCFG<2:0> 000 = Vrefh = AVDD and Vrefl = Avss (3.3V and 0V) Bit 12 OFFCAL 0 = disable input offset calibration Bit 10 CSNA 0 = do not scan inputs {1 = scan inputs} Bit 7 BUFS only valid if BUFM is ‘1’; 1 = ADC is filling buffer 8-F, you read 0-7 0 = ADC is filling buffer 0-7, you read 8-F Bit 5-2 SMPI<3:0> 0000 = Interrupt at completion of conversion for each sample Bit 1 BUFM 0 = Buffer configures as one 16 word buffer ADC1BUFF to ADC1BUF0 1 = Buffer configures as two 8 word buffers Bit 0 ALTS 0 = Use Sample A input multiplexor settings {1=>alternate sample A/B)

bit 15 ADRC: ADC Conversion Clock Source bit 1 = Clock derived from FRC 0 = Clock derived from Peripheral Bus Clock (PBCLK) bit 12-8 SAMC<4:0>: Auto-Sample Time bits <note 1> 11111 =31 T AD 00001 =1 TAD 00000 =0 TAD (Not allowed) bit 7-0 ADCS<7:0>: ADC Conversion Clock Select bits <note 2> 11111111 =TPB • 2 • (ADCS<7:0> + 1) = 512 • TPB = TAD • 00000001 =TPB • 2 • (ADCS<7:0> + 1) = 4 • TPB = TAD 00000000 =TPB • 2 • (ADCS<7:0> + 1) = 2 • TPB = TAD

bit 31 CH0NB 1 = Channel 0 negative input is AN1 0 = Channel 0 negative input is VREFL bit 27-24 CH0SB<3:0>: Positive Input Select bits for Sample B 1111 = Channel 0 positive input is Open 1100 = Channel 0 positive input is AN12 • • • 0001 = Channel 0 positive input is AN1 0000 = Channel 0 positive input is AN0 bit 23 CH0NA: Negative Input Select bit for Sample A Multiplexer Setting 1 = Channel 0 negative input is AN1 bit 19-16 CH0SA<3:0>: Positive Input Select bits for Sample A Mux Setting 1111 = Channel 0 positive input is Open 1110 = Channel 0 positive input is IVREF 1101 = Channel 0 positive input is CTMU temperature (CTMUT) 1100 = Channel 0 positive input is AN12

http://umassamherstm5.org/tech-tutorials/pic32-tutorials/pic32mx220-tutorials/adc The 10-bit ADC can be split into two sections: Acquisition and Conversion.

Manual Mode Configuration In manual mode, the programmer must make an individual request every time the ADC starts a sample. In the version presented here, the acquisition is started manually by setting  AD1CON1bits.SAMP HIGH. Conversion will then start automatically after an amount of time specified in the AD1CON3 SFR. When acquisition is finished, the SAMP bit will go LOW. When conversion is done, the AD1CON1bits.DONE bit will go HIGH. The result will be stored in one of the ADC1BUFx registers. Since we’re only requesting the analog value of one pin at a time in this manual mode, the result is always stored in the first buffer register or ADC1BUF0. The AD1CHS is the channel select SFR. Of importance to us is that AD1CHS<16:19> control which pin is being input to the ADC. With this information, we can make a simple function that takes as input an analog pin number and returns the 10-bit analog voltage as an int from 0-1023 as follows.

To configure for this mode, we set the conversion to trigger automatically after acquisition is done by setting the SSRC bits found at AD1CON1<5:7>. Choosing manual mode is also found in this register. In AD1CON3, we will set the source of the ADC clock, how long a period (TAD) is, and how many periods of this clock per acquisition. Conversion is always 12 TAD cycles long. We’ll set the analog clock period to be four times the peripheral bus clock period which will be equal to SYSCLK. TAD = 4*TPB. At FPB = 50MHz, TAD = 4*TPB = 80ns. To be on the safe side, we’ll configure the acquisition period as 15*TAD = 1.2us. Thus, the entire analog-to-digital conversion takes 27*TAD = 2.16us. The configuration is shown below.

Automatic Scan Configuration In the automatic scan mode we’ll be using, the ADC peripheral will be sampling and converting a specified number of analog pins as long as the ADC has power. Whenever the processor then requests the 10-bit voltage representation of some of these pins, the ADC peripheral will give the most recent completed conversion. With this method, ADC call latency is severely reduced! Once the ADC is configured and running, every additional pin request is as simple as a single assignment line. However, this method uses slightly more power as the ADC is constantly sampling and converting voltages. Also, while the ADC call time is very short, there is a minimum time between calls to make sure new analog voltages have been sampled. We’re only talking a few microseconds and even this can be reduced by careful planning of the ADC clock (TAD) and how many cycles are necessary for sampling in your particular application! Please read the link below if you wish to understand this further http://umassamherstm5.org/tech-tutorials/pic32-tutorials/pic32mx220-tutorials/adc

Working ADC Code on the DP32; using AN9(RB15) and LEDs 3-0(RB0-3) Modified from http://umassamherstm5.org/tech-tutorials/pic32-tutorials/pic32mx220-tutorials/adc

Modified from http://umassamherstm5

Modified from http://umassamherstm5

These exercises prepare you for the mini-project. Add a timedelay so that a reading is taken every 1/100th second. Add a buffer so that data is continually filling a 1024 ring buffer Output on the LEDs how full the buffer is Convert the ADC routine so that it fills the buffer under interrupts and the only code is main loops continually checking how full the buffer is, These exercises prepare you for the mini-project.