Line: 1 to 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Added: | |||||||||||||||||||||||||||||||||||||||||||||||||||
> > |
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 countSlide 13: Argument CheckIf the no of args is correct we have to check if the argument given is either
Slide 14: 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.Slide 15: Solution: argument checkSlide 16: 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 waveSlide 17: Function testFirst we create the framework We will need:
Slide 18: 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?Slide 19: Dummy function and test (main)Slide 20: The include fileSlide 21: The test functionSlide 22: Implementing the functionSlide 23: Was it correct?Slide 24: 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 valuesSlide 25: Solution: Rectangular waveSlide 26: The rectangular wave formSlide 27: Bit handling functionsWe 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 4Slide 28: DAC preparationWrite a function which prepares a byte for the DAC The functions takes 3 arguments:
Slide 29: Solution: DAC preparationSlide 30: Now the test programSlide 31: StrobeNow create a strobe function which takes DAC data and generates a strobe signal on the STR line without touching the other bitsSlide 32: Solution: StrobeSlide 33: Send one short value to the DACNow 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:
Slide 34: Solution: send one data word4Slide 35: ...and the test program for itSlide 36: … with the resultSlide 37: Assembling 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.Slide 38: And this is the final result-- Uli Raich - 2017-10-09Comments
|