
Originally Posted by
mixedgas
Thats nice, but you still need a second source for testing some times in the field. what is wrong with 6$ instead of 450-560.
ATmega328 + Microchip MCP4922 + Max232 -> can haz $15 test pattern generator.
That's how I generate ramps and sine waves for testing my laser modulator project anyway. (Mine uses a pair of MCP4921s, which are the same but only a single DAC on the chip.)
Here's the code for an Arduino to produce counter-ramps:
Code:
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK 13//sck
#define SLAVESELECTX 10//ss
#define SLAVESELECTY 9//ss
#define LDAC 8
void setup() // run once, when the sketch starts
{
byte clr;
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECTX,OUTPUT);
pinMode(SLAVESELECTY,OUTPUT);
pinMode(LDAC,OUTPUT);
digitalWrite(SLAVESELECTX,HIGH);
digitalWrite(SLAVESELECTY,HIGH); //disable devices
digitalWrite(LDAC,HIGH);
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
}
void write_values(uint16_t samplex, uint16_t sampley)
{
uint8_t dacSPI0 = 0;
uint8_t dacSPI1 = 0;
dacSPI0 = (samplex >> 8) & 0x00FF;
dacSPI0 |= 0x30;
dacSPI1 = samplex & 0x00FF;
digitalWrite(SLAVESELECTX,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(SLAVESELECTX,HIGH);
dacSPI0 = (sampley >> 8) & 0x00FF;
dacSPI0 |= 0x30;
dacSPI1 = sampley & 0x00FF;
digitalWrite(SLAVESELECTY,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(SLAVESELECTY,HIGH);
// Latch the DACs
digitalWrite(LDAC, LOW);
digitalWrite(LDAC, HIGH);
//delay(1);
}
void loop() // run over and over again
{
static int j;
j+=5;
if (j > 4096) j = 0;
write_values(j, 4095-j);
}