Important changes to forums

We’re making some changes to the Mbed forums. From 10th December 2019 all new discussions will take place on our new forum site. You can continue to reply to existing threads for the next two weeks. After that we will archive this forum so you can return to useful posts in the future.

MAX541 problem with odd/even addition.

16 Nov 2019


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;
        RB4 = 1; 

void attack_F()
        dacData = dacData + 2;
        }while(dacData < 65535);
        if(dacData == 65535)
            dacData = 625;

void main(void)

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

You need to log in to post a reply