FFT Frequency Detection on the dspic

Similar documents
PID Control. Proportional Integral Derivative (PID) Control. Matrix Multimedia 2011 MX009 - PID Control. by Ben Rowland, April 2011

Solar Energy Conversion using MIAC. by Tharowat Mohamed Ali, May 2011

Android, Bluetooth and MIAC

FlowKit in-circuit debug system

ECIO40P ECIO28P ECRM40. Page 1. USB programmable microcontrollers. 0.6 DIP footprint. Supplied with a free version of Flowcode. E-blocks compatible

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

LED board datasheet EB

Switch board datasheet EB

CAN bus board. EB018

E-Blocks Easy RFID Bundle

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

Controlling a Dot Matrix LED Display with a Microcontroller

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

Performing the Fast Fourier Transform with Microchip s dspic30f Series Digital Signal Controllers

E-Blocks Easy Internet Bundle

RS232 Board datasheet

Electronics. Discrete assembly of an operational amplifier as a transistor circuit. LD Physics Leaflets P

2.0 Command and Data Handling Subsystem

ARRL Morse Code Oscillator, How It Works By: Mark Spencer, WA8SME

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

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

Chapter 6: From Digital-to-Analog and Back Again

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

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

FAST Fourier Transform (FFT) and Digital Filtering Using LabVIEW

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

Welcome to the tutorial for the MPLAB Starter Kit for dspic DSCs

Programming Logic controllers

Conversion Between Analog and Digital Signals

Measuring Resistance Using Digital I/O

DSPDemo. By Moe Wheatley MoeTronix.

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

MP3 Player CSEE 4840 SPRING 2010 PROJECT DESIGN.

Poor Man s A/D Converter By Dave Wissel at Wave Technology

Transistor Amplifiers

Palaparthi.Jagadeesh Chand. Associate Professor in ECE Department, Nimra Institute of Science & Technology, Vijayawada, A.P.

POCKET SCOPE 2. The idea 2. Design criteria 3

Low Cost Pure Sine Wave Solar Inverter Circuit

Signal Processing in So.ware and Electric Field Sensing

A DESIGN OF DSPIC BASED SIGNAL MONITORING AND PROCESSING SYSTEM

Section 3. Sensor to ADC Design Example

Switch Mode Power Supply Topologies

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Automotive electronics CAN and LIN buses. Copyright 2006 Matrix Multimedia Limited

Computer Networks and Internets, 5e Chapter 6 Information Sources and Signals. Introduction

CELL PHONE AUDIO CONTROLLED POINT OF SALE TECHNOLOGY REVIEW REPORT. Alana Sweat Group 9 October 18, 2008

Surveillance System Using Wireless Sensor Networks

Digital to Analog Converter. Raghu Tumati

Development of Low Cost Private Office Access Control System(OACS)

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

IMPEDANCE MEASURING SYSTEM BASED ON A DSPIC

25. AM radio receiver

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

Ultrasound Distance Measurement

DAC Digital To Analog Converter

Current Loop Application Note 1495

FREQUENCY RESPONSE OF AN AUDIO AMPLIFIER

EECC694 - Shaaban. Transmission Channel

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

Inductors in AC Circuits

Measuring Temperature withthermistors a Tutorial David Potter

Op-Amp Simulation EE/CS 5720/6720. Read Chapter 5 in Johns & Martin before you begin this assignment.

Multiplexing and Sampling Theory

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

2011, The McGraw-Hill Companies, Inc. Chapter 5

Lock - in Amplifier and Applications

THE BASICS OF PLL FREQUENCY SYNTHESIS

Laboratory 4: Feedback and Compensation

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

INSTRUMENTATION AND CONTROL TUTORIAL 3 SIGNAL PROCESSORS AND RECEIVERS

Analog signals are those which are naturally occurring. Any analog signal can be converted to a digital signal.

Final Report. Hybrid Synth by Synthesize Me. Members: Jamie Madaris Jack Nanney

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

RF Network Analyzer Basics

UPS PIco. to be used with. Raspberry Pi B+, A+, B, and A. HAT Compliant. Raspberry Pi is a trademark of the Raspberry Pi Foundation

Test Driven Development of Embedded Systems Using Existing Software Test Infrastructure

An Introduction to MPLAB Integrated Development Environment

Pulse Width Modulation

Constructing a precision SWR meter and antenna analyzer. Mike Brink HNF, Design Technologist.

Features, Benefits, and Operation

Analog vs. Digital Transmission

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

Innovative Practices in Optimal Utilization of Solar Energy (Solar Tracking System)

Analog-to-Digital Converters

Analog Representations of Sound

Frequency Response of Filters

I2C PRESSURE MONITORING THROUGH USB PROTOCOL.

OPERATIONAL AMPLIFIERS. o/p

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

13. Diode Rectifiers, Filters, and Power Supplies

The Development of a Pressure-based Typing Biometrics User Authentication System

Pressure Transducer to ADC Application

Voltage boost and buck circuits using Atmel AVR Tiny13V for driving a white LED.

Cell Phone Vibration Experiment

3. Identification of water pumps through RFID technology. 4. Wireless control of remote water pump using RF technology.

Simple SDR Receiver. Looking for some hardware to learn about SDR? This project may be just what you need to explore this hot topic!

Bipolar Transistor Amplifiers

Transcription:

FFT Frequency Detection on the dspic by Jac Kersing Nov 2012 Abstract In this article Jac explains how he solved a practical challenge using powerful dspic devices and Fast Fourier Transform algorithms. He accomplishes this using Flowcode for dspic and PIC24s. Read more to discover how! An example is included to accompany this article. Requirements Software: Flowcode for dspic & PIC24 Problem A little while ago I found myself faced with the challenge to transport signals of two sensors over a two wire cable. The sensors require power to operate and produce an analog signal requiring some interpretation to translate it to an binary (on/off) value. There being no power available at the 'remote' location adds to the challenge. Several solutions were considered to solve the challenge. One was to use the wires to supply (low voltage) power and use some kind of radio transmitter/receiver solution to transfer the data. Two 30 cm layers of reinforced concrete caused the signals to be too unreliable for this to work. An other solution was to use a PIC attached to the sensors with some kind of protocol to transmit the status of the sensors. It would be nice if this solution could operate without any battery power as the sensors require up to 30 ma, a considerable drain on a battery given the 24 hour operation of the sensors. In the ideal world the cable would provide power to the remote location and transport the sensor status back. Hardware As I am working on a project requiring dspics and FFT I could not resist the temptation and designed the solution based on frequency generation and FFT. The high level design can be found in illustration 1. Page 1

Illustration : High level design The PIC circuit has the sensors attached and converts the input values read to a true/false state. If the state of a sensor is true a sine of a certain frequency is output. The frequency is 1000 Hz for sensor 1 and 1500 Hz for sensor 2. At any given time the output might be idle, have a frequency of 1000 Hz, 1500 Hz or both 1000 Hz and 1500 Hz. The output signal is 'fed' to the two wire connection to the dspic. At the dspic the input signal needs to be isolated from the power feed. A high pass filter consisting of a capacitor and resistor take care of this. The output of this very simple filter is a weaker (due to cable losses and the filter) version of the wave form generated by the PIC. This wave form needs to be amplified and converted to the input range of the dspic. A simple circuit with an OPAMP, some resistors and some capacitors solves that problem (see illustration 2) Illustration : Amplifier circuit Page 2

The 3.3 volt level output of the amplifier circuit is used as input for an analog input (AN0) of the dspic. The prototype is build using the circuit in illustration 2, an EB64 16 bit PIC / dspic multiprogrammer with a dspic33fj128gp802 fitted and an EB004 LED board to display the relayed signal. Theory Before we start working on the software a (tiny) bit of theory is needed. Fast Fourier Transform decomposes a series of samples into 'bins' of different frequencies. Each bin represents the extend the frequencies contained in that bin are present in the input signal. To be able to distinguish between two frequencies we need them to be in different bins. Microchip provides a library of FFT routines for their dspic range of micro controllers. These routines take an input array sized power-of-two (64, 128, 256...) and provide the output in an array sized half that of the input array. The size of the frequency band contained within each bin in the output is equal to the sample frequency divided by the number of samples. An example: When using a sample frequency of 20 khz and a sample size of 256 samples, the size of each frequency band is 78.125 Hz. With a sample size of 128 samples the band would be 156.25 Hz. Something to take into account when determining the samples frequency is the requirement of the sample rate to be at least twice the highest possible input frequency. (Google for Nyquist for background) Software The hardware connects the signal to be sampled to an input of the Analog-to-Digital Converter (ADC). Flowcode provides us with an ADC component to convert input signals to digital values. However, due to the requirements of the FFT used we are unable to use this component. Due to the requirements of the Microchip FFT library and of the PIC the buffers used for FFT and DMA need to be created with special compiler attributes. Flowcode does not allow us to specify these attributes, as a result these buffers are created in the 'Supplementary Code' definitions and function declarations. In addition to the memory requirements, the FFT library defines the format of the input to be in 1.15 data format. This format has 1 sign bit and 15 fractional bits and can (only) be used to represent decimal numbers in the range -1.0 to (nearly) +1.0. Page 3

Sampling the input A sample frequency of 20 khz is used (R3/C3 in the circuit diagram form a very simple 10 khz low pass filter). The sampling is driven by Timer 3, the results are transferred to a 32 sample input buffer using DMA. Once the input buffer is full an interrupt will start code to transfer the samples to their final destination. (The PIC actually alternates between two input buffers to allow the interrupt code to copy samples while new samples are acquired without the risk of overwriting the samples being copied) The macro to setup the ADC, Timer 3 and DMA contains a number of C code blocks. These take care of the 'low level' setup of the ADC channel, the DMA channel and enable the ADC. The Interrupt blocks setup Timer 3 with the correct frequency. The next step is to immediately disable the interrupt as we do not want to use it directly and setup DMA5 with a custom interrupt for DMA5. For the DMA5 code to work some additional C code is required, a helper routine performing the actual data copy out of the DMA buffer to the FFT buffer. The code can be found in the 'Supplementary Code' function implementations. Illustration : InitADC Macro FFT Fast Fourier Transform is performed on complex numbers. This means the input values need to be transformed to complex values. (This is very simple as the imaginary component of the input signal is zero) The c-code in the StartADC macro zeros the imaginary components and (re)set the pointers used to transfer samples. The DMA5 code copies the real values to the sample array. The FFT code requires a number of constants (twiddle factors), these are set up in the C code blocks in InitFFT. Once the samples have been read the signal strength of the input signal needs to be processed. The ProcesFFT macro takes care of this. It also translated the complex values to integers and copies them to an array accessible by 'normal' flow chart elements. Page 4

Main program The main program is rather simple. It starts with setting the oscillator, calls the macros to initialize FFT and ADC and enters an endless loop. In the loop samples are acquired (StartADC) and processed (ProcessFFT). Depending on the contents of the buckets for 1000Hz and 1500Hz outputs B15-B12 and B11-B8 are set (signal present) or cleared (no signal). Minor Challenges While developing the code a number of minor challenges presented themselves: Flowcode for dspic is missing the include file for the FFT library. This can be solved in two ways, the first is to copy it from the Microchip distribution, the second option (which has been implemented) is to add the relevant definitions to the 'Supplementary Code' definitions and function declarations. The use of C code and a library preclude simulation of the code. To debug the code I revered to the proven method of displaying information on a display (I used the EB058, allowing a number of lines of text to be displayed.) The batch file used to link programs that is provided with FlowCode does not use the DSP library. To be able to use DSP functions the file 'pic16_c30_link.bat' (which can be found in: c:\program files\matrix Multimedia\Flowcode PIC24&dsPIC v4\tools\mx_bats) needs to be changed. The line starting with 'pic30-gcc should be altered to read : pic30-gcc -Wl,%1.o,-L"%~dp0..\C_tools\lib",-ldsp,--heap=256,-- report-mem,--script="%~dp0..\c_tools\support\%3\gld\p%2.gld",- o%1.cof (this is all one line where the bold text has been added to the original text) Further reading Below are some links to other resources and articles on related subjects, and technical documentation relating to the hardware used for this project... Flowcode: Learning Centre: User Forums: Product Support: http://www.matrixmultimedia.com/flowcode.php http://www.matrixmultimedia.com/lc_index.php http://www.matrixmultimedia.com/mmforums http://www.matrixmultimedia.com/sup_menu.php Copyright Matrix Multimedia Limited 2012 Flowcode, E-blocks, ECIO, MIAC and Locktronics are trademarks of Matrix Multimedia Limited. PIC and PICmicro are registered trademarks of Arizona Microchip Inc. AVR, ATMega and ATTiny are registered trademarks of the ATMEL corporation. ARM is a registered trademark of ARM Ltd. Page 5