Firmware
Click here for a copy of our firmware and all related files.
A/D Conversion
Each of the five axes on the arm has a potentiometer attached to it. The potentiometer's variable resistance allows us to calculate the angle of that joint since the voltage varies linearly with the angle. We take the voltage reading and send it to the pic. For this reading to be useful, the pic must convert the analog signal into a digital one. To do this, we must configure five pins to ba analog inputs and initialize the analog to digital converter.
movlw b'00001010' movwf ADCON1, ACCESS ; set 0-3 and 5 on PORTA to be analog movlw b'00101111' ; 0-3 and 5 to be input movwf TRISA, ACCESS ; set up all PORTA pins to be analog inputs movlw b'00000001' movwf ADCON0, ACCESS ;turn on a2d converter movlw b'10101110' movwf ADCON2, ACCESS ;configure a2d settings (readings are right justified)
The value given to ADCON1 is responsible for telling the PIC which pins are analog inputs and what the reference voltages are. In this case, pins zero through three and five are inputs and the voltage range is zero to five volts. ADCON2 is responsible for acquisition time, the conversion clock, and the output format. We chose an appropriate acquisition time and conversion clock, and formatted our output to be in two bytes since it is ten bit A/D conversion. When the value of a potentiometer is asked for, the pic captures the high and low byte of the pin, and saves the value to files that are later used in our vendor specific requests.
select case 0x00 movf ADRESH,W,ACCESS banksel POT2SLOT1HI movwf POT2SLOT1HI,BANKED movf ADRESL,W,ACCESS movwf POT2SLOT1LO,BANKED break case 0x01 movf ADRESH,W,ACCESS banksel POT2SLOT2HI movwf POT2SLOT2HI,BANKED movf ADRESL,W,ACCESS movwf POT2SLOT2LO,BANKED break default ends
The access function selects a default header address instead of asking for one. This enables simpler code in that we do not have to specify what banks we want to deal with unless we are dealing with files that we write to the PIC, in that case, we have to follow the file saving statement with a banked statement.
Data Transfer
In order to transfer data to the host computer, we have the host ask for the data in the form of vendor specific requests.
banksel BD0IAH movf BD0IAH, W, BANKED movwf FSR0H, ACCESS movf BD0IAL, W, BANKED ; get buffer pointer movwf FSR0L, ACCESS banksel POT1SLOT1LO movf POT1SLOT1LO,W,BANKED addwf POT1SLOT2LO,W,BANKED movwf POSTINC0 movf POT1SLOT1HI,W,BANKED addwfc POT1SLOT2HI,W,BANKED movwf POSTINC0 banksel BD0IBC movlw 0x06 movwf BD0IBC, BANKED ; set byte count to 1 movlw 0xC8 movwf BD0IST, BANKED ; send packet as DATA1, set UOWN bit
The first four lines configure the data transfer register and came with the lab 1 firmware. The next seven lines take the values in the files that we stored in the A/D conversion and add them to the ISF register that is sent to the host with the last four lines.
Created Spring 2005 by Zachary Borden (2008), Mark Cavolowksy (2008), and Matthew Donahoe (2008)