Line: 1 to 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Slide 1: An additional Lecture on C ProgrammingCreating a Signal Generator
Slide 2: C is too abstract?I was told that you find the course on C too abstract!
Slide 3: A pulse generatorA pulse generator is a device you use to test your electronics (e.g. electronics to read out an experiment which generates electronic signalsOn a professional pulse generator you can:
Slide 4: The oscilloscopeBefore using the signal from the pulse generator you observe the signal on an oscilloscope How does an oscilloscope work? What is
Slide 5: A standard oscilloscopeA standard digital storage oscilloscope uses
Slide 6: Oscilloscope ExampleSlide 7: Our pulse generatorLet us create our own pulse generator!It should provide
Slide 8: The DACWe 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 ‰This is Physics!Slide 9: DAC accessThe 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 0xaSlide 10: Breaking down the problemEven though this will be still a very small and simple program, let’s break it down into smaller pieces:
Slide 11: Check the number of cmd line argsWrite 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 1Slide 12: Solution: arg count | |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < | |||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||
Argument CheckIf the no of args is correct we have to check if the argument given is either
Check the argumentImprove 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.Solution: argument check | |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < | |||||||||||||||||||||||||||||||||||||||||||||||||||
> > | |||||||||||||||||||||||||||||||||||||||||||||||||||
Creating the wave formAs 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 waveFunction testFirst we create the framework We will need:
Write the Test functionWrite 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?Dummy function and test (main)The include fileThe test functionImplementing the functionWas it correct?The rectangular wave formWrite 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 valuesSolution: Rectangular waveThe rectangular wave formBit handling functions | |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < | We need to learn a few bit handling functions before | ||||||||||||||||||||||||||||||||||||||||||||||||||
> > | We need to learn a few bit handling operators before | ||||||||||||||||||||||||||||||||||||||||||||||||||
being able to prepare the data for the DAC: | |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < | | : bitwise or | ||||||||||||||||||||||||||||||||||||||||||||||||||
> > | | : bitwise or | ||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < | & : bitwise and | ||||||||||||||||||||||||||||||||||||||||||||||||||
> > | & : 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < | |||||||||||||||||||||||||||||||||||||||||||||||||||
> > | example:
data = 16 00010000 data >> 4 00000001 | ||||||||||||||||||||||||||||||||||||||||||||||||||
DAC preparationWrite a function which prepares a byte for the DAC The functions takes 3 arguments:
Solution: DAC preparationNow the test programStrobeNow create a strobe function which takes DAC data and generates a strobe signal on the STR line without touching the other bitsSolution: StrobeSend one short value to the DAC | |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < | Now that we know how to strobe it is easy to write | ||||||||||||||||||||||||||||||||||||||||||||||||||
> > | 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: | |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < |
| ||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||||||||||||||||||||||||
< < |
| ||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||||||||||||||||||||||||||||
Solution: send one data word4...and the test program for it… with the resultAssembling the whole thingNow 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.And this is the final result%SLIDESHOWEND% -- Uli Raich - 2017-10-09Comments
| |||||||||||||||||||||||||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
|