I was told that you find the course on C too abstract!
A pulse generator is a device you use to test your electronics
(e.g. electronics to read out an experiment
which generates electronic signals
On a professional pulse generator you can:
Before using the signal from the pulse generator
you observe the signal on an oscilloscope
How does an oscilloscope work?
What is
A standard digital storage oscilloscope uses
(not useful for professional applications
but ok for the slow signals we produce
with our electronics) featuring:
Let us create our own pulse generator!
It should provide
We have a 12 bit DAC, which creates signal
levels from 0V to Vcc
What is the max. number this DAC can take in
decimal and in hex?
What is the signal resolution in ‰
The DAC has 3 registers with the following bit layout:
register 0 takes the lowest 4 bits of the DAC value
register 1 takes the middle 4 bits
register 2 takes the highest 4 bits
RS selects the register
The strobe line (STR) must pulse (go high and low again)
to read/ write the data (R/W line) from/to the DAC
What is the bit combination and sequence to write the
middle 4 bits with the data 0xa
Even though this will be still a very small and simple
program, let’s break it down into smaller pieces:
Write a piece of code that checks that the user
has entered 1 arguments
The program prints a “Usage” message and exits if the
no of arguments given by the user is not exactly 1
If the no of args is correct we have to check
if the argument given is either
int strcmp(const char *s1, const char *s2)
This function returns zero if the 2 strings match
You must include <string.h> to use this function
Improve your program to include a check
if the argument given is “sine” or “rect”.
Print an error message it it is not
and a success message if it is.
As we said, the DAC takes 12 bit values which
can be stored in an array of short (16 bits)
The upper 4 bits of each element will be zero
The generation of the waveform goes into a
separate source file and its associated include file
I give you the example for the sine wave and
you write the code for the rectangular wave
First we create the framework
We will need:
Write a test function (genWaveTest.c) taking one argument
(the wave type) and printing which wave type has been selected.
Which definitions should go into the include file?
How do you have to modify the main program
to call the genWave function?
Write the code for the generation of the rectangular wave form.
The signal should be zero for the first 50 values of the wave,
4095 for the following 50 values
We need to learn a few bit handling functions before
being able to prepare the data for the DAC:
| : bitwise or
& : bitwise and
data += 5 <=> data = data + 5
data |= 5 <=> data = data | 5
~data: invert all bits in data
data >> 4 all bits in data are shifted right by 4
data << 4 all bits in data are shifted left by 4
Write a function which prepares a byte for the DAC
The functions takes 3 arguments:
to register to the middle nibble?
Now create a strobe function which takes DAC data
and generates a strobe signal on the
STR line without touching the other bits
Now that we know how to strobe it is easy to write
a 12 bit value to the DAC
We must do it in 3 steps:
4
Now we have all the bits and pieces and
finalizing the project becomes easy.
In the file accessing the hardware we add:
and we call this in main.
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
![]() |
checkArgs.png | r1 | manage | 48.6 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
cmdLineCount.png | r1 | manage | 20.8 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
createWaveForm.png | r1 | manage | 63.2 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
dacPrep.png | r1 | manage | 42.0 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
dacPrepResult.png | r1 | manage | 8.7 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
functionTest.png | r1 | manage | 40.2 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
genWaveTest.png | r1 | manage | 24.4 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
gnuplot.png | r1 | manage | 36.2 K | 2017-10-09 - 08:31 | UnknownUser | |
![]() |
gnuplotRect.png | r1 | manage | 29.1 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
includeFile.png | r1 | manage | 35.4 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
pulseGenResult.png | r1 | manage | 36.0 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
rectWave.png | r1 | manage | 29.0 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
rectWaveGnuPlot.png | r1 | manage | 29.2 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
scope.png | r1 | manage | 81.0 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sendOneValue.png | r1 | manage | 32.4 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sendToDAC.png | r1 | manage | 29.7 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sendToHWInclude.png | r1 | manage | 28.4 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sendToHWTest.png | r1 | manage | 48.3 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sendToHWTestResult.png | r1 | manage | 29.5 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sendWave.png | r1 | manage | 52.1 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sine.png | r1 | manage | 71.0 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
sineFunc.png | r1 | manage | 67.0 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
strobe.png | r1 | manage | 45.1 K | 2017-10-09 - 08:32 | UnknownUser | |
![]() |
waveGen.odp | r1 | manage | 767.6 K | 2017-10-16 - 12:39 | UnknownUser | |
![]() |
waveGen.tar.gz | r1 | manage | 813.9 K | 2017-10-09 - 08:31 | UnknownUser |