lab 5 signal analyzer/generator. introduction create a client mfc application that samples a signal...

22
Lab 5 Signal Analyzer/Generator

Post on 19-Dec-2015

218 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Lab 5

Signal Analyzer/Generator

Page 2: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Introduction

Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or DirectX.

Digitally analyze and generate analog waveforms

Reconstruct the waveform using the sampled signal

Page 3: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Spartan 3 board

http://www.digilentinc.com/Products/Detail.cfm?Prod=S3BOARD&Nav1=Products&Nav2=Programmable

Tutorial 1

Tutorial 2

Tutorial 3

Page 4: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Acquiring an Analog Signal

Input is a signal with peak to peak of 5 V Voltage input in the range -2.5 to 2.5 V Use Analog to Digital Converter

ADC0820 Input’s analog voltage 0 to 5 V Requires adding 2.5 Volts to input signal

before converted.

Page 5: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Voltage compatibility issue

Spartan 3 uses a 5 V adapter Internal voltage levels are 3.3 V, 2.5 V and 1.2 V. ADC0820 needs a 5V, Output levels are close to 5V Inputs cannot handle 5 V without a current limiting

resister. Use R > 170 Ohms to limit current to 10 mA. Alternately, since the FPGA I/O are TTL compatible,

you may want to use TTL buffers to limit the voltage levels to about 3.4 V.

Page 6: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Sampling Signals on Serial Port

Max Baud Rate 115,200 115,200 bits per second

Max Sampling Frequency 115,200 / 10 bits (8 data, 1 start, 1 stop)

Max Input Frequency to avoid aliasing (Max Sampling Frequency) / 2 = 5760 Hz

Page 7: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Discrete Fourier Transform (DFT)

Can be processor intensive thus use Fast Fourier Transform (FFT) to calculate DFT

Algorithm requires a sampling frequency as a power of 2

Refer to FFT function on UL-99 (C++)

Page 8: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Windows GDI

If you took 408 you probably already know this

Page 9: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Device context classes

CPaintDC - for drawing on windows client handlers (on paint only)

CClientDC - for drawing on windows client handlers (anytime other then on paint)

CWindowDC – for drawing anywhere in a window

CMetafileDC - Drawing to a GDI metafile

Page 10: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

How to draw

Create paint object Move to point Draw line

Page 11: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

How to draw

CClientDC DC(this) DC.MoveTo(0,0); DC.LineTo(100,100);

When the window calls on_paint the window will clear the area.

Page 12: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

How to keep a drawing on a screen

Void draw(CDC* pDC,CRect rect) {

pDC->Rectangle(rect) }

Page 13: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

How to keep a drawing on screen

Onpaint() {

CRect rect;

GetClientRect (&rect);

CPaintDC dc(this);

draw(&dc,rect); }

Page 14: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Other draw functions

Rectangle Arc PolyLine MoveTo Pie Ellipse RoundRect

Page 15: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Coordinatestaken from programming with MFC second edition

Page 16: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Coordinates

How to set

CClientDC dc(this)

dc.SetMapMode (MM_LOMETRIC);

Page 17: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Why you should use a pixel coordinate systems and pitfalls

There are only so many pixels on a screen, this is set by a screen resolution.

In a pixel coordinate system, how many pixels on a client window can be found by finding the size by using:

GetClientRect(CRect rect); 1 pixel is the most accurate there is (no such

thing as ½ pixel in GDI)

Page 18: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Changing Color

CPen pen;

pen.CreatePen (PS_SOLID, 1, RGB (255, 0, 0));

CClientDC dc(this)

CPen *oldPen = dc.SelectObject(&pen);

Page 19: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Changing Color

Taken from programming with MFC, Second Edition

Page 20: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Different Lines

Taken from programming with MFC, Second Edition

Page 21: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Draw Text

CPaint dc(this)

dc.SetTextAlign(TA_RIGHT);

dc.TextOut(0,0,”hello”);

Page 22: Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or

Anything else?

THERE IS MORE YOU CAN DO

This is just on the basics

Anything other details can be found on the MSDN.