Docsity

Lab Exercise: Exploring the Functionality of an A/D Converter, Exercises of Computer Programming

Toggle sidebar
bg1
Revision 2
Lab exercises
1) This session we want to become more comfortable with the laboratory equipment:
• Begin with the program you wrote last week to use the A/D converter as an output device. Use the scope to measure the
time it takes for the completion of one loop of your program. Measure how long a simple assignment statement takes.
Look at the time it takes to execute some other structures of statements, maybe a loop, and maybe a subroutine call.
• Display square waves, sine waves, and ramping waves on the scope. Become comfortable reading (on the scope) and
setting the amplitude, offset, and frequency fairly accurately. Use the function generator to create a 1 KHz ramping
wave that varies from a low of 1 volt to a high of 4 volts. Confirm the parameters on your scope. Leave it set there. We
will use it in that setting later.
2) We now want to exercise the A/D converter in it primary analog conversion mode. Attached is a sample program. It is
similar to the one supplied with the NetBurner. I made a few changes to “clean it up”. We will use it to understand how the
A/D converter is set-up and used in its basic primary mode.
• Find the functionality provided by :
#include <..\mod5282\system\sim5282.h>
and describe how it defines the object variables used to program the A/D converter.
• Become familiar with the program. Confirm that the set-up of the A/D converter makes sense. In you report, you should
explain the settings used.
• Run the program and confirm that it produces the output you expected. Don’t put any inputs on the 8 A/D channels yet.
Observe the outputs and explain what you observe.
• Put 0 volts (gnd) or 5 volts on one A/D inputs and observe the value in the output. Put the voltage (0 or 5 volts) on other
A/D inputs and observe that the A/D values are appropriately displayed in the output.
• RECHECK THE RAMP WAVE ON YOUR FUNCTION GENERATOR AND HAVE YOUR LAB PARTNER
CONFIRM THAT IT IS CORRECTLY SET (1 volt to 4 volt swing). IT IS IMPORTANT THAT YOU NEVER
PLACE A NEGATIVE VOLTAGE OR A VOLTAGE GREATER THAN 5 VOLTS ON AN A/D INPUT! Keep the
waveform displayed on your scope.
• Connect the ramp waveform to an A/D input and observe the output. Why is it difficult to see the waveform change?
• Modify the program to be able to print out successive samples of one A/D input. This will require that you change the
setup of the queue to store successive samples of one channel.
• Looking at the set-up, what do you believe the sampling rate is? Measure the sampling rate.
• Change the frequency of the input until you can observe “aliasing”. Explain what is happening here.
• What can you say about the linearity and accuracy of the converter?
Docsity.com
pf2

Partial preview of the text

Download Lab Exercise: Exploring the Functionality of an A/D Converter and more Exercises Computer Programming in PDF only on Docsity!

Revision 2

Lab exercises

1) This session we want to become more comfortable with the laboratory equipment:

  • Begin with the program you wrote last week to use the A/D converter as an output device. Use the scope to measure the

time it takes for the completion of one loop of your program. Measure how long a simple assignment statement takes.

Look at the time it takes to execute some other structures of statements, maybe a loop, and maybe a subroutine call.

  • Display square waves, sine waves, and ramping waves on the scope. Become comfortable reading (on the scope) and

setting the amplitude, offset, and frequency fairly accurately. Use the function generator to create a 1 KHz ramping

wave that varies from a low of 1 volt to a high of 4 volts. Confirm the parameters on your scope. Leave it set there. We

will use it in that setting later.

2) We now want to exercise the A/D converter in it primary analog conversion mode. Attached is a sample program. It is

similar to the one supplied with the NetBurner. I made a few changes to “clean it up”. We will use it to understand how the

A/D converter is set-up and used in its basic primary mode.

  • Find the functionality provided by : #include <..\mod5282\system\sim5282.h>

and describe how it defines the object variables used to program the A/D converter.

  • Become familiar with the program. Confirm that the set-up of the A/D converter makes sense. In you report, you should

explain the settings used.

  • Run the program and confirm that it produces the output you expected. Don’t put any inputs on the 8 A/D channels yet.

Observe the outputs and explain what you observe.

  • Put 0 volts (gnd) or 5 volts on one A/D inputs and observe the value in the output. Put the voltage (0 or 5 volts) on other

A/D inputs and observe that the A/D values are appropriately displayed in the output.

  • RECHECK THE RAMP WAVE ON YOUR FUNCTION GENERATOR AND HAVE YOUR LAB PARTNER

CONFIRM THAT IT IS CORRECTLY SET (1 volt to 4 volt swing). IT IS IMPORTANT THAT YOU NEVER

PLACE A NEGATIVE VOLTAGE OR A VOLTAGE GREATER THAN 5 VOLTS ON AN A/D INPUT! Keep the

waveform displayed on your scope.

  • Connect the ramp waveform to an A/D input and observe the output. Why is it difficult to see the waveform change?
  • Modify the program to be able to print out successive samples of one A/D input. This will require that you change the

setup of the queue to store successive samples of one channel.

  • Looking at the set-up, what do you believe the sampling rate is? Measure the sampling rate.
  • Change the frequency of the input until you can observe “aliasing”. Explain what is happening here.
  • What can you say about the linearity and accuracy of the converter?

Docsity.com

#include "predef.h" #include <stdio.h> #include <ctype.h> #include <startnet.h> #include <autoupdate.h> #include <dhcpclient.h> #include <..\mod5282\system\sim5282.h> extern "C" { void UserMain(void * pd); } /* Set up A/D to continuously sample all 8 channels and store the results / void InitializeQADC() { sim.qadc.qadcmcr=0x8000; sim.qadc.portqa=0; sim.qadc.portqb=0; sim.qadc.ddrqa=0; sim.qadc.ddrqb=0; sim.qadc.qacr0=0x7F; / 64Mhz clock / sim.qadc.qacr1=0x1100; _/ probably not needed (repeated below) /_ sim.qadc.qacr2=11; sim.qadc.qasr0=0; sim.qadc.qadcmcr=0x0000; sim.qadc.ccw[0]=0xC0; sim.qadc.ccw[1]=0xC1; sim.qadc.ccw[2]=0xC2; sim.qadc.ccw[3]=0xC3; sim.qadc.ccw[4]=0xF4; sim.qadc.ccw[5]=0xF5; sim.qadc.ccw[6]=0xF7; sim.qadc.ccw[7]=0xF8; sim.qadc.ccw[8]=0xFC; sim.qadc.ccw[9]=0xFD; sim.qadc.ccw[10]=0xFF; _sim.qadc.qacr1=0x1100; / Continious software scans in queue 1 /_ } / Return the converted samples / WORD GetQADC(int ch) { return sim.qadc.rjurr[ch]; } void UserMain(void * pd) { InitializeStack(); if (EthernetIP==0)GetDHCPAddress(); OSChangePrio(MAIN_PRIO); EnableAutoUpdate(); / Start up the A/D system / InitializeQADC(); iprintf("Application started\n"); while (1) { OSTimeDly(20); iprintf("A/D values. Floating point voltage assumes a 5.0V reference\r\n"); for (int i=0; i<10; i++) { WORD v=GetQADC(i); float f=v; f=f5.0/1024.0; printf("AD[%d] = 0x%03X or %4d or %4.2fV \r\n",i,v,v,f); } } } Docsity.com