system
April 1, 2009, 1:20am
1
Thought I should share this.
I am using two DAC to supply the X and Y voltage on an old
"Houston Instrument Omnigraphic 2000 XY Recorder Plotter".
The plotter's X and Y input range is 0 - 5v.
This code simply lets the plotter pen move to it's extremes and back.
The MCP4921 communicates with the Arduino via Serial Peripheral Interface (SPI).
Code here:
http://maybevideodoes.de/howto/DAC/SPI_MCP4921.pde
system
March 16, 2010, 3:25pm
2
Do you know how can I send saved serial data from arduino to MCP4921??
how to set it??
just like this
void setup(){
//Timer2 setup This is the audio rate timer, fires an interrupt at 15625 Hz sampling rate
TIMSK2 = 1<<OCIE2A; // interrupt enable audio timer
OCR2A = 127;
TCCR2A = 2; // CTC mode, counts up to 127 then resets
TCCR2B = 0<<CS22 | 1<<CS21 | 0<<CS20; // different for atmega8 (no 'B' i think)
SPCR = 0x50; // set up SPI port
SPSR = 0x01;
DDRB |= 0x2E; // PB output for DAC CS, and SPI port
PORTB |= (1<<1); // CS high
sei(); /
system
March 16, 2010, 3:37pm
3
here is the SPI code i used:
#define DATAOUT 11//MOSI
//#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK 13//sck
#define SLAVESELECT0 10//ss
void SPI_setup(){
pinMode(9, OUTPUT); //+5V for SHDN on mcp4922 mini board
digitalWrite(9,HIGH);
byte clr;
pinMode(DATAOUT, OUTPUT);
// pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT0,OUTPUT);
digitalWrite(SLAVESELECT0,HIGH); //disable device
// pinMode(SLAVESELECT1,OUTPUT);
// digitalWrite(SLAVESELECT1,HIGH); //disable device
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
}
void write_valueX(int sample)
{
// splits int sample in to two bytes
byte dacSPI0 = 0;
byte dacSPI1 = 0;
dacSPI0 = (sample >> 8) & 0x00FF; //byte0 = takes bit 15 - 12
dacSPI0 |= (1 << 7); // A/B: DACa or DACb - Forces 7th bit of x to be 1. all other bits left alone.
dacSPI0 |= 0x10;
dacSPI1 = sample & 0x00FF; //byte1 = takes bit 11 - 0
digitalWrite(SLAVESELECT0,LOW);
SPDR = dacSPI0; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
SPDR = dacSPI1;
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
digitalWrite(SLAVESELECT0,HIGH);
delay(5);
}
void write_valueY(int sample)
{
// splits int sample in to two bytes
byte dacSPI0 = 0;
byte dacSPI1 = 0;
dacSPI0 = (sample >> 8) & 0x00FF; //byte0 = takes bit 15 - 12
dacSPI0 |= 0x10;
dacSPI1 = sample & 0x00FF; //byte1 = takes bit 11 - 0
digitalWrite(SLAVESELECT0,LOW);
SPDR = dacSPI0; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
SPDR = dacSPI1;
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
digitalWrite(SLAVESELECT0,HIGH);
delay(5);
}
system
March 16, 2010, 5:04pm
4
i dont know how to declare cs and sck.