10-bit Σ ADC from a PIC16F84



Similar documents
Section 29. Instruction Set

PIC Programming in Assembly. (

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

AN727. Credit Card Reader Using a PIC12C509 DATA ENCODING INTRODUCTION FIGURE 1: POSITION OF ISO TRACKS 1, 2 AND 3. Andrew M Errington

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Four-Channel Digital Voltmeter with Display and Keyboard. 8 x 220W RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 RA0 RA1 RA2 RA3 PIC16C71

Simple Alarm System WIRELESS AND REMOTE CONTROLLED PERSONAL APPLIANCE CODE WORD ORGANIZATION TRANSMISSION FORMAT

How To Program A Microcontroller With Memory On A Microchip Microcontroller

Small Hardware Development and Prototyping Board for the SX28

PIC in Practice. A Project-Based Approach. D. W. Smith

Application Report. 1 Introduction. 2 Resolution of an A-D Converter. 2.1 Signal-to-Noise Ratio (SNR) Harman Grewal... ABSTRACT

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

LEVERAGING FPGA AND CPLD DIGITAL LOGIC TO IMPLEMENT ANALOG TO DIGITAL CONVERTERS

Accurate Measurement of the Mains Electricity Frequency

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

c0003 A Simple PIC Application CHAPTER 3

Memory organization. Memory blocks: Program memory (flash-type) 16 kword (32 kbyte) (instruction 16 bit wide) Data RAM 1536 byte (1.

b 1 is the most significant bit (MSB) The MSB is the bit that has the most (largest) influence on the analog output

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

Department of Electrical and Computer Engineering Ben-Gurion University of the Negev. LAB 1 - Introduction to USRP

PIC16F84A. 18-pin Enhanced Flash/EEPROM 8-Bit Microcontroller. Devices Included in this Data Sheet: Pin Diagrams. High Performance RISC CPU Features:

Harmonics and Noise in Photovoltaic (PV) Inverter and the Mitigation Strategies

Section 28. In-Circuit Serial Programming (ICSP )

AN857. Brushless DC Motor Control Made Easy INTRODUCTION S 001 B. Anatomy of a BLDC SIMPLIFIED BLDC MOTOR DIAGRAMS. Microchip Technology Inc.

Using The PIC I/O Ports

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT BIT DIFFERENTIAL ADC WITH I2C LTC2485 DESCRIPTION

Analog-to-Digital Converters

Laboratory 4: Feedback and Compensation

AN857. Brushless DC Motor Control Made Easy INTRODUCTION S 001 B. Anatomy of a BLDC SIMPLIFIED BLDC MOTOR DIAGRAMS

1. The demonstration code is sending garbage to my terminal program. What are the recommended settings?

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

ABCs of ADCs. Analog-to-Digital Converter Basics. Nicholas Gray Data Conversion Systems Staff Applications Engineer

Section 14. Compare/Capture/PWM (CCP)

25. AM radio receiver

A Low-Cost VCA Limiter

Hideo Okawara s Mixed Signal Lecture Series. DSP-Based Testing Fundamentals 46 Per-pin Signal Generator

Lab #9: AC Steady State Analysis

Section 8. Interrupts

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AC/DC Power Supply Reference Design. Advanced SMPS Applications using the dspic DSC SMPS Family

PCM Encoding and Decoding:

I 2 C Master Mode Overview and Use of the PICmicro MSSP I 2 C Interface with a 24xx01x EEPROM

LAB 12: ACTIVE FILTERS

Chapter 13. PIC Family Microcontroller

PIC16F8X. 18-pin Flash/EEPROM 8-Bit Microcontrollers. Devices Included in this Data Sheet: Pin Diagrams. High Performance RISC CPU Features:

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

POCKET SCOPE 2. The idea 2. Design criteria 3

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

DAC Digital To Analog Converter

ANALYZER BASICS WHAT IS AN FFT SPECTRUM ANALYZER? 2-1

Lecture N -1- PHYS Microcontrollers

FREQUENCY RESPONSE ANALYZERS

AND9035/D. BELASIGNA 250 and 300 for Low-Bandwidth Applications APPLICATION NOTE

PIC12F508/509/16F505 Data Sheet

MCP3901. Two Channel Analog Front End. Description. Features. Package Type. Applications

Embedded C Programming

PIC16F526 Data Sheet. 14-Pin, 8-Bit Flash Microcontroller Microchip Technology Inc. Preliminary DS41326A

PLL frequency synthesizer

AC : PRACTICAL DESIGN PROJECTS UTILIZING COMPLEX PROGRAMMABLE LOGIC DEVICES (CPLD)

A simple RF/Microwave frequency counter

FFT Frequency Detection on the dspic

An Introduction to MPLAB Integrated Development Environment

Digital to Analog Converter. Raghu Tumati

SSPBUF. Shift Clock SSPSR. START bit, STOP bit, Acknowledge Generate

AVX EMI SOLUTIONS Ron Demcko, Fellow of AVX Corporation Chris Mello, Principal Engineer, AVX Corporation Brian Ward, Business Manager, AVX Corporation

HOW TO GET 23 BITS OF EFFECTIVE RESOLUTION FROM YOUR 24-BIT CONVERTER

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

Non-Data Aided Carrier Offset Compensation for SDR Implementation

Pulse Width Modulation (PWM) LED Dimmer Circuit. Using a 555 Timer Chip

24-Bit, 96kHz BiCMOS Sign-Magnitude DIGITAL-TO-ANALOG CONVERTER

MATRIX TECHNICAL NOTES

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Vi, fi input. Vphi output VCO. Vosc, fosc. voltage-controlled oscillator

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

MCP3901. Two-Channel Analog Front End. Description. Features. Package Type. Applications

USB to serial chip CH340

PIC16F84A Data Sheet. 18-pin Enhanced FLASH/EEPROM 8-bit Microcontroller Microchip Technology Inc. DS35007B

Dithering in Analog-to-digital Conversion

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Electronic Circuits Spring 2007

ADS9850 Signal Generator Module

Loop Bandwidth and Clock Data Recovery (CDR) in Oscilloscope Measurements. Application Note

Interface Protocol v1.2

T = 1 f. Phase. Measure of relative position in time within a single period of a signal For a periodic signal f(t), phase is fractional part t p

The Effective Number of Bits (ENOB) of my R&S Digital Oscilloscope Technical Paper

Baseband delay line QUICK REFERENCE DATA

Tire pressure monitoring

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

AN601 I2C 2.8 Communication Protocol. SM130 SM130 - Mini APPLICATION NOTE

CHAPTER 11: Flip Flops

Filter Comparison. Match #1: Analog vs. Digital Filters

AN585. A Real-Time Operating System for PICmicro Microcontrollers INTRODUCTION. Why do I Need a Real-Time Kernel? What is Multitasking Anyway?

Use and Application of Output Limiting Amplifiers (HFA1115, HFA1130, HFA1135)

M68EVB908QL4 Development Board for Motorola MC68HC908QL4

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Timing Errors and Jitter

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Transcription:

1-bit Σ ADC from a PIC16F84 Jesús Arias 22nd November 23 1 The circuit +5V 1 + 1uF 1nF 1nF 33 4.7 V DTR U1 Analog Input ( 5 Volt) R3 68K R1 1K R2 1K C1 33nF PIC16F84 RB7 RA2 RA3 ad2.asm OSC1 OSC2 X1 R4 22K R5 1K Q1 BC557 RXD CTS GND 4MHz The schematic of the ADC consist mainly of a PIC16F84 microcontroller and a RC network. The microcontroller generates an RS232-compatible output (96 baud, 8 bit, no parity) thanks to the level-converter circuit that is shown on the right of the schematic. The PIC16F84 must be clocked at 4 MHz. The ratio between R1 and R2 defines the input range of the converter: V in R2 R1 V dd The resistor R3 is used to adjust the input offset. The center-of-scale code is obtained for the following input voltage: V dd R1 V in V th 2 R2 1 R1 R2 R1 R3 were V th is the threshold voltage of the input pin (RA3). In our case V dd is 5 volts and V th is about 1.4 volts (from PIC16F84 datasheet). Alternatively, if we want our input range centered around V dd 2, the R3 value must be: 1

R3 R1 R2 V th V dd 2 V th The resistor values in this design give an input range of 5 volts centered around 2.5 volts. The Σ conversion works generating a train of pulses on the pin RA2 whose average value cancels the input signal at the capacitor node. This forces a voltage at pin RA3 very close to the pin threshold. The program running in the PIC microcontroller generates the output pulses by just inverting the logic level of pin RA3 every 14 µs and copying it into the RA2 output. These pulses are recorded and they are used to reconstruct the equivalent input voltage by doing a digital filtering. A good, regulated, power supply is required. Decoupling capacitors must be close to microcontroller power pins. In addition, we must avoid loading other microcontroller s pins. e.g. It would be a bad idea to drive a LED directly from a microcontroller pin. If other pins are used as outputs they must be isolated using a buffer powered from a different voltage source in order to maintain the microcontroller power supply clean. 2 The digital filter The filtering of the Σ modulator stream is done by program. The filter used is a second-order comb filter, whose structure is: decimation RA2 1 Z 1 Z 1 256 1 Z 1 1 Z 1 aout comb comb1 comb2 comb3 This filter is composed of two integrators, running at 96 Hz, followed by sample decimation and two differentiators running at 37.56 Hz. The filter input is only one bit, but each comb variable is 16 bits long and so it is the output. It must be noted that, even if the output samples are 16-bit long, the less-significant bits are almost random. The expected AD resolution is only 1 bits. The data processing is done in an interrupt routine using 16-bit integer arithmetic (A pain in the neck for a CPU without ADD-with-carry instructions). 3 Simulation results The following results were obtained using the f84 simulator conveniently modified to simulate the analog section on the prototype and its serial output. 2

3.1 Transfer function & error 65536 1 57344 Output code 49152 496 32768 24576 16384 8192 1 2 3 4 5 Analog input (V) Output error 5-5 -1 1 2 3 4 5 Analog input (V) A linear voltage ramp is applied to the input. This ramp starts at volts and it ends at 5 volts. The time interval is 4 sec long or 152 samples.the simulated transfer function is an almost perfect straight line, but there is still a small offset error (The code for volts is not zero). Another interesting property is that a positive overflow gives a zero code instead of 65535 (in fact it is a truncated 65536). The error graph on the right is the difference between the actual ADC output and the best straight-line fit. Here, a small nonlinearity is observed. The error amplitude is about 3 LSBs, or 2 times smaller than the output range. This error is bigger for input voltages around 2.5 V due to a remaining tonal behavior (The Σ output is a perfect square wave for that input). 3.2 Spectra & SNR -2-2 Amplitude (db) -4-6 Amplitude (db) -4-6 -8-8 -1-1 1 1 1 1 Frequency (Hz) -12 2 4 6 8 1 12 14 16 18 2 Frequency (Hz) In this simulation the input signal is a sinusoid centered around 2.5 volts. The first graph shows the spectra of the pulse train at RA2 (red line) and the ADC output (blue line). The sampling frequency is 9615 Hz for the pulse output and 37.65 Hz (9615/256) for the ADC output. Here we can see that the digital filter does a good job removing the high-frequency noise and lowering the sample rate without allowing too much noise to fold back in top of the signal band. The FFT length was 65536 samples for RA2 output and 256 samples for ADC output. The signal-to-noise ratio (SNR) was estimated at 65dB from this graph. This means that the effective ADC resolution is about 1.5 bits ( ENOB SNR 1 76 6 2 ) The second graph shows only the ADC output. In this case we want to see how high is the distortion of the input signal. We can see that the third harmonic of the input signal is attenuated more than 7 db with respect to the input 3

tone. This means that the signal distortion is less than the ADC noise, and, therefore, we can state that this is a very linear converter. The FFT length was 228 samples. 4 The program The microcontroller program is written in native assembly language. It requires 166 words of flash memory for the program itself and 31 bytes of RAM for variables. Interrupts are called every 14 clock cycles. A typical interruption takes 39 cycles to execute, but every 256 interrupts we have a longer interruption that takes 67 clock cycles. The AD conversion accounts for a 37% of the total CPU time. 5 Program listing ;--------------------------------------------------- ; This program is distributed under GNU GPL license ;--------------------------------------------------- processor p16f84 config x3ff2 radix dec w equ f equ 1 c equ dc equ 1 z equ 2 indf equ x tmr equ x1 pcl equ x2 status equ x3 fsr equ x4 porta equ x5 portb equ x6 eedata equ x8 eeadr equ x9 pclatch equ xa intcon equ xb optionr equ x81 trisa equ x85 trisb equ x86 eecon1 equ x88 eecon2 equ x89 ;---------------------------------------------- ; Variable defs. 4

;---------------------------------------------- cblock xc tmp_w tmp_st nirq nsamples sampleix comb combh comb1 comb1h comb2 comb2h comb3 comb3h aout aouth adata adata_h nchar resto cntbit obyte uart uarth uartdel tmp buf endc ;------ RESET ---------------------------- ; Configuration: ; --------------- ; RA3 A/D input ; RA2 A/D output ; RB7 UART output ; org movlw xfb ;RA2 out tris porta goto ini ;------ INTERRUPT (9615/sec)----------------- org x4 5

tmp_w ;save CPU status swapf status,w tmp_st bcf intcon,2 ;clear interrupt ;Interrupt latency equalization (to add 1-cycle delay if needed) ; - can give 3 db improvement (1/2 bit) ; Some experimentation is still needed because ; PIC16F84 interrupt details are not well known ;We can try: ; - No equalization ; - btfsc tmr, ; - btfss tmr, btfsc tmr, goto deleq deleq movlw 259-14 ;adjust timer for a new addwf tmr,f ;interrupt ;------ A/D ----- rrf porta,w ;A/D feedback loop xorlw 4 ;~RA3 -> RA2 porta ;---- UART ---- ;16-bit shift reg. bsf status,c rrf uarth,f rrf uart,f btfsc status,c bsf portb,7 btfss status,c bcf portb,7 uartdel,f ;dec. uartdel if not btfss status,z decf uartdel ;---- Comb Filter: integrators ---- btfsc porta,2 goto isr1 incfsz comb,f goto isr1 incf combh,f isr1 comb,w addwf comb1,f btfsc status,c incf comb1h,f 6

addwf combh,w comb1h,f ;----- DECIMATION: The differentiator code is called ;----- every 256 interrupts incfsz nirq,f goto isrf ;----- Comb Filter: differentiators ----- ; aout =comb1-comb2-comb3 ; comb3=comb1-comb2 ; comb2=comb1 subwf btfss decf subwf subwf btfss decf subwf incf comb1,w aout comb1h,w aouth comb2,w aout,f status,c aouth,f comb2h,w aouth,f aout,w comb2 aouth,w comb2h comb3,w aout status,c aouth,f comb3h,w aouth,f comb2,w comb3 comb2h,w comb3h comb1,w comb2 comb1h,w comb2h nsamples,f 7

;---- End of Interrupt ---- isrf swapf tmp_st,w ;restore cpu status status swapf tmp_w,f swapf tmp_w,w retfie ;------------------------------------------- ;------ MAIN ------------------------------- ;------------------------------------------- ini movlw x7e ;RB7, RB out tris portb movlw x88 ;No Pull-UPs, no prescaler option clrf nirq ;Clearing variables clrf nsamples clrf sampleix clrf comb clrf combh clrf comb1 clrf comb1h clrf comb2 clrf comb2h clrf comb3 clrf comb3h movlw xff uart uarth bsf portb,7 ; Default state of UART s line movlw xa ; Interrupt on timer overflow intcon buc call getad ; get AD sample call prtn ; And print it in decimal goto buc ;-------- UART EMULATOR (96 bps) --------- ; Sends the byte: "obyte" ;------------------------------------------- putbyte nirq,w tmp 8

pbbuc1 tmp,w ;wait until next interrupt subwf nirq,w btfsc status,z goto pbbuc1 pbbuc2 uartdel,f btfss status,z goto pbbuc2 movlw xff ; Filling the UART shift reg. uarth obyte,w uart bcf status,c rlf uart rlf uarth movlw 1 ; Wait until 1 interrupts uartdel return ;------------------ BIN to ASCII ----------------- ; divide by 1: adata(16 bits)/1 -> adata,resto ;------------------------------------------------- div1 movlw 16 cntbit clrf resto movlw 1 bdiv1 bcf status, rlf adata,f rlf adata_h,f rlf resto,f subwf resto,f btfsc status,c incf adata btfss status,c addwf resto,f decfsz cntbit,f goto bdiv1 retlw ;------------------------------------------------ ;-- prtn: prints adata (16 bits) in ascii ;------------------------------------------------ 9

prtn movlw buf fsr clrf nchar bprtn1 call div1 incf nchar resto,w addlw 48 indf incf fsr adata,w iorwf adata_h,w btfss status,z goto bprtn1 bprtn2 decf fsr,f indf,w obyte call putbyte decfsz nchar,f goto bprtn2 movlw 1 obyte call putbyte retlw ;----------------------------------------------- ; A/D read: new sample -> adata ;----------------------------------------------- getad nsamples,w subwf sampleix,w btfsc status,z goto getad nsamples,w sampleix aout,w adata aouth,w adata_h bsf portb, ; Pulse on PB for timming debug bcf portb, return 6 Experimental results The proposed ADC was built and tested. First, in order to test the basic operation of the converter, an exponential ramp was applied to the input from a big capacitor that was charged from ground to +5V through a resistor. The recorded transient is shown in Fig 1. 1

65536 RC-transient test 49152 ADC code 32768 16384 1 2 3 4 5 6 7 8 9 sample # Figure 1: Transient signal recorded using the proposed ADC. Then, by cropping the exponential part of the transient and by doing a nonlinear curve fitting we obtained the average error of the converter (Fig 2). This plot shows a different behavior than predicted from simulations, with an average error about 1 1-bit LSB and with higher peak values. The peaks in this plot are due to idle tones in the converter, a well known problem of first-order delta-sigma modulators. Finally, a 4.7 Hz sinusoid was applied to the input and the recorded data stream was processed in the frequency domain using a Fourier transform. The obtained spectrum is shown in Fig 3. The measured SNR was 64 db (1.3 effective bits) and the total harmonic distortion was -61 db. 11

2 1.5 1 INL (1-bit LSB).5 -.5-1 -1.5-2 8192 16384 24576 32768 496 49152 57344 65536 ADC code Figure 2: Nonlinearity plot of the ADC. SNR = 64 db, THD = -61 db -2-4 Ampl. (db) -6-8 -1-12 2 4 6 8 1 12 14 16 18 2 Freq. (Hz) Figure 3: Spectrum of a digitized sinusoid. (496-sample FFT) 12