C and Assembly Language Subroutine for Writing to DAC Channel A, Assignments of Microprocessors

Instructions for writing a c or assembly language subroutine named 'writetodac' to write a 12-bit integer value to dac channel a along with the appropriate command to update the dac. The required registers and their addresses, as well as a sample c program to test the subroutine.

Typology: Assignments

Pre 2010

Uploaded on 05/14/2009

angularmomentum
angularmomentum 🇺🇸

5

(2)

74 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 2534 Homework 6
You are to write a C or assembly language subroutine that implements the
following header:
Function: WriteToDAC
Created by: YOU
Description: Called from C with a 12-bit integer value it writes this integer to DAC
channel A along with the appropriate command to update the DAC.
You will require the following registers:
SPICR 0x84160060 SPI Control Register
SPISSR 0x84160070 SPI Slave Select Register
SPIDTR 0x84160068 SPI Data Transfer Register (FIFO)
SPISR 0x84160064 SPI Status Register
To check the operation of this subroutine you should use it in the following C program.
The output of DAC channel A can be easily measured using a multimeter and should
agree with the value displayed on the LCD screen to within a few hundredths of a volt.
You have already written the other subroutines that are called by this C program.
Additional information can be found in the Spartan-3E Starter Kit Board User
Guide and the data sheet for the LTC2624.
/****************************************************************************************
Program: HW 6
Created by: WTB
Description: Rotary knob is used to set a voltage between 0 and 3.2V in steps of 0.1V.
This voltage value is displayed on the LCD and is output to the DAC on channel A.
Last Revision: 10/16/08
****************************************************************************************/
//Defines
#define CMD 0 //send command to LCD
#define DATA 4 //send data to LCD
//Prototypes
extern "C" void LCD_write (int cmd_data, char data);
extern "C" int Rotary(void);
extern "C" void sleep(int microseconds);
void LCD_char(int index, char letter);
void WriteToDAC(int output);
int main(void) {
int voltage=0,input,ind;
LCD_write(CMD,1); //clear LCD
sleep(1640);
for (ind=0;ind<9;ind++) LCD_char(ind+2,"0.0 Volts"[ind]);//write initial value of voltage
while (1) {
if ((input=Rotary())) { //if the switch has moved
voltage += input;
if (voltage>32) voltage=32; //enforce voltage bounds
if (voltage<0) voltage=0;
ind=voltage/10; //write out new voltage to LCD
LCD_char(2,'0'+ind);
LCD_char(4,'0'+voltage-ind*10);
ind=(voltage*4096)/33; //convert voltage to DAC counts
WriteToDAC(ind); //send to DAC
}
}
}
void LCD_char(int index, char letter) {
LCD_write(CMD,(char)(0x80|index));
LCD_write(DATA,letter);
}

Partial preview of the text

Download C and Assembly Language Subroutine for Writing to DAC Channel A and more Assignments Microprocessors in PDF only on Docsity!

ECE 2534 Homework 6

You are to write a C or assembly language subroutine that implements the

following header:

Function: WriteToDAC Created by: YOU Description: Called from C with a 12-bit integer value it writes this integer to DAC channel A along with the appropriate command to update the DAC.

You will require the following registers:

SPICR 0x84160060 SPI Control Register SPISSR 0x84160070 SPI Slave Select Register SPIDTR 0x84160068 SPI Data Transfer Register (FIFO) SPISR 0x84160064 SPI Status Register

To check the operation of this subroutine you should use it in the following C program.

The output of DAC channel A can be easily measured using a multimeter and should

agree with the value displayed on the LCD screen to within a few hundredths of a volt.

You have already written the other subroutines that are called by this C program.

Additional information can be found in the Spartan-3E Starter Kit Board User

Guide and the data sheet for the LTC2624.

Program: HW 6 Created by: WTB Description: Rotary knob is used to set a voltage between 0 and 3.2V in steps of 0.1V. This voltage value is displayed on the LCD and is output to the DAC on channel A. Last Revision: 10/16/ ****************************************************************************************/ //Defines #define CMD 0 //send command to LCD #define DATA 4 //send data to LCD //Prototypes extern "C" void LCD_write (int cmd_data, char data); extern "C" int Rotary(void); extern "C" void sleep(int microseconds); void LCD_char(int index, char letter); void WriteToDAC(int output); int main(void) { int voltage=0,input,ind; LCD_write(CMD,1); //clear LCD sleep(1640); for (ind=0;ind<9;ind++) LCD_char(ind+2,"0.0 Volts"[ind]);//write initial value of voltage while (1) { if ((input=Rotary())) { //if the switch has moved voltage += input; if (voltage>32) voltage=32; //enforce voltage bounds if (voltage<0) voltage=0; ind=voltage/10; //write out new voltage to LCD LCD_char(2,'0'+ind); LCD_char(4,'0'+voltage-ind10); ind=(voltage4096)/33; //convert voltage to DAC counts WriteToDAC(ind); //send to DAC } } } void LCD_char(int index, char letter) { LCD_write(CMD,(char)(0x80|index)); LCD_write(DATA,letter); }