MAX541 problem with odd/even addition.

16 Nov 2019

Hi.

I'm trying to send data to MAX541. Everything works ok using even number in "dacData = dacData + 2".

I cannot add odd numbers. When I use value 1,3,5,etc summing to "dacData = dacData + 2";, I get a square wave output from DAC. Square wave goes that other half cycles from 0 to 1.25 V. Other half goes from 1.25V to 2.5V.

If I send LSB first I get unexpected results. Sometimes output is sawtooth from 0 to 2.5V. However I would need to have sawtooth wave from 1.2V to 2.5V but I it always resets the starting point to 0.

I'm using PIC16f18345 and MAX541. V reference is 2.5V.

Any help or suggestions please?

include the mbed library with this snippet


uint16_t dacData = 625;             
uint8_t DAC[2] = {0,0};              

uint16_t Attack;            

void DAC_Send()
{
        DAC[0] = dacData >> 8;           // MSB 
        DAC[1] = (uint8_t) dacData;      // LSB
        RB4 = 0;
        SPI1_Exchange8bit(DAC[0]);
        SPI1_Exchange8bit(DAC[1]);
        RB4 = 1; 
}

void attack_F()
{
        do
        {   
        dacData = dacData + 2;
        DAC_Send();          
        Timer0Delay();
        }while(dacData < 65535);
        if(dacData == 65535)
        {
            dacData = 625;
            DAC_Send();
        }
}


void main(void)
{
    SYSTEM_Initialize();
    SPI1_Initialize();
    ADC_Initialize();
    INTERRUPT_GlobalInterruptEnable();
    //INTERRUPT_PeripheralInterruptEnable();
    
    while(1)
    {       
        
        attack_F();
        
    }
}

26 Nov 2019

Hi John

Regarding this condition while(dacData < 65535), since type of dacData is uint16_t, the only situation to exit the loop is when dacData == 65535, if the increment doesn't not equal to one, the condition might not ever be reached.

Regards, Desmond