CSE 398 Experiment #2 Introduction to Microcontrollers Using Peripheral I/O Ports Authors: William Tan, Rahul Gathoo, Anthony Garo Introduction Methods Since we know that our microcontroller the M68DKIT912C32 has an built-in analog to digital convertor we can adjust the settings so it will receive the correct format of the signal. The ATD_10B8C has either an 8 but or 10 bit resolution, we will be using the 8 bit resolution. There are six analog to digital control registers, we will need to modify the default settings of each one. We leave ATDCTL0 and ATDCTL1 unchanged. Since the ATDCTL2 has the option to of ADPU we will set the 7th bit high to power on the ATD_10B8C block. Since we will be using 2 channels we will set ATDCTL3 on the 4th bit and clear the 5th which is 4 channels by default. Finally with ATDCTL4 set it to 8 bit resolution. Entry: LDD #$0000 BSET ATDCTL2,#$80 BSET ATDCTL3,#$10 BCLR ATDCTL3,#$20 BSET ATDCTL4,#$80 Then we want to start the binning process, we will use memory ?SampleBuffer ? to store all 256 conversion samples that we receive from the ATD convertor. First we write to register ATDCTL5 to start the conversion process. Then we load the results memory into register Y and compare the SCF flag to 1, then we will know the conversion is complete. After the loop has run 256 times it will had summed all 256 conversions into memory SampleBuffer. LDX #0 ; Loads the most significant byte of the index X StartConversion: BSET ATDCTL5,#$90 ; Write to ATDCTL5 to start conversion Wait: LDY ATDSTAT0 ; Load ATDSTAT0 into register Y CPY #$8000 ; Compare SCF flag to 1 BEQ AddtoBuffer ; Branch to add result to samplebuffer JMP Wait ; If conversion is not complete AddtoBuffer: ADDD ATDDR0H INX CPX #255 BNE StartConversion STD SampleBuffer ;Load accumlated value into the SampleBuffer Now we want to our number we have to the correct scale, so we divide the value that was binned from the 256 conversion samples by the maximum possible value. This will give us a fraction to multiply by 4999 to get our ?real? value from 0 to 5v. After this, we will store the answer into ReadoutBuffer. Afterward we have to convert this value in ReadoutBuffer to a BCD value that we can send to the FPGA board to display on the LEDs. In order to convert we simply divide the value in ReadoutBuffer by 1000 to get the MSB, then take the remainder and divide by 100 to get the second MSB and continue doing so until the value LSB is in the last remainder. LDY #4999 EMUL LDX #65280 EDIV STY ReadoutBuffer LDD ReadoutBuffer ; Start BCD to Binary conversion LDX #1000 IDIV STX FirstValue ; Store the quotient in memory, Remainder in D LDX #100 IDIV ; Divide remainder by 100 STX SecondValue ; Store quotient in memory LDX #10 IDIV STX ThirdValue STD FourthValue We store each converted BCD number into a separate memory. Results We were successful in setting up the ATD_10B8C to receive the correct format of data. Binning process was also successful; we chose to bin 256 numbers because our resolution was 8bits, so we would obtain a 16 bit result in our results register. Our Conversion to the correct range was also successful and the Binary to BCD conversion gave us the correct values. Total we have 4 values converted to BCD for mill volt resolution. Discussion 2
Want to see the other 3 page(s) in CSE 398 Experiment 2.docx?JOIN TODAY FOR FREE!