Hello dear friends! I have a strange problem with DAC LTC2622. I have: microcontroller, LTC2622, LM4040-3.0 as 3V-reference for DAC. All working good except some situations:
1. When I load to DAC, for example, "1.8V", DAC displays "1.8V".
2. After this, If I load to DAC "0V", DAC displays "0V" - good work. (Video: https://youtu.be/Bc5JtQaE-YI)
BUT:
1. When I load to DAC voltage more than "1.9V" (for example, 2.8V), DAC displays this value (2.8V).
2. After this, If I load to DAC "0V", DAC displays some random value more than 1.9V, but not zero! Why it not reset to zero? (Video: https://youtu.be/dnlpj72F0kE)
And:
1. When I load to DAC voltage more than "1.9V" (for example, 2.8V), DAC displays this value (2.8V).
2. After this, If I load to DAC voltage more than 0.25V, DAC displays this value (more than 0.25V)! (https://youtu.be/hpUF4fzlK2A)
I think that problem is not in my code, because I've tried to send data to DAC manually (SO-delay-SCK1-delay-SCK0-delay-SO-delay-SCK1-delay-SCK0 ... e.t.c.) using diagram and timing from datasheet (24-bit and 32-bit data word).The result is similar. Oscilloscope also displays that SPI transieve a "zero" bits to data word if I load "0" to DAC. My code is below. Please help!
sbit DAC_CS at GPIOA_ODR.B2;
sbit DAC_SCK at GPIOA_ODR.B3;
sbit DAC_SO at GPIOA_ODR.B4;
void DACOut(unsigned int DACCommand, unsigned int DACAdress, unsigned long DACVoltage) {
unsigned long TempData;
unsigned int DACData, i;
TempData = (unsigned long)DACVoltage*4096/3000 ; // Convert Voltage (in mV) to DAC code.
DACData = (unsigned int)TempData ; // Convert Long to Int.
Delay_us(1);
DAC_CS = 0 ; // CS 0
asm nop;
asm nop;
for (i=0; i<4; i++) {
if (DACCommand.B3 == 1) {
DAC_SO = 1 ;
} else {
DAC_SO = 0 ;
}
DAC_SCK = 1 ; // SCK UP
asm nop ;
asm nop ;
DAC_SCK = 0 ; // SCK down
DACCommand = DACCommand<<1 ;
}
for (i=0; i<4; i++) {
if (DACAdress.B3 == 1) {
DAC_SO = 1 ; // 1
} else {
DAC_SO = 0 ; // 0
}
DAC_SCK = 1 ; // SCK UP
asm nop ;
asm nop ;
DAC_SCK = 0 ; // SCK down
DACAdress = DACAdress<<1;
}
for (i=0; i<16; i++) {
if (DACData.B11 == 1) {
DAC_SO = 1 ; // 1
} else {
DAC_SO = 0 ; // 0
}
DAC_SCK = 1 ; // SCK UP
asm nop ;
asm nop ;
DAC_SCK = 0 ; // SCK down
DACData = DACData<<1 ;
}
DAC_CS = 1 ; // CS 1
}
void main() {
GPIO_Init();
DAC_CS = 1 ; // CS 0
Delay_us(1);
while (1) {
DacOut(0b0011, 0b0000, 2800);
Delay_ms(1000);
DacOut(0b0011, 0b0000, 0);
Delay_ms(1000);
}
}