Hello to everyone,
I’m writing here since after many days I cannot properly communicate with an MCP 4725 DAC using the toradex i2c library.
I’m developing an application in C# where I have an MCP4725 connected to a laser galvanometer.
I have to send values to the DAC to control the lens position for the laser beam deflection.
I don’t understand exactly how I can write in a right way the code to send a fast write command or a Standard command to the DAC register and/or eeprom.
I’ve written some code that works correctly but I have a strange issue I can’t understand.
Infact with this code I move correctly the laser beam where I want but the issue is that each time I send a new value I see a 30cm laser wake trail, also if I send the same value (the laser should not move so it isn’t a galvanometer issue). It’s like the DAC out voltage decrease a little before the new voltage will be set.
The code I wrote is the following:
public void WriteRegister(int iValue)
{
if (bReverse)
iValue = MAX_VALUE - iValue;
//Fast Mode
uint bufferLenght = 3;
Byte[] DataToWrite = new Byte[bufferLenght];
DataToWrite[0] = 192;
DataToWrite[1] = (byte)((iValue & 3840) >> 8);
DataToWrite[2] = (byte)(iValue & 255);
try
{
unsafe
{
fixed (byte* for_Casting_Intptr_to_Byte = DataToWrite)
{
returnValue = i2c.I2c_Write(i2cHandle, (IntPtr)for_Casting_Intptr_to_Byte, bufferLenght);
if (returnValue == 0)
throw new Exception(); ///< If Write operation returns 0
}
}
}
catch (Exception ex)
{
Program.cGlobals.cLogging.LogMessage("Scrittura Configurazione Fallita - Codice Errore: " + ex.Message);
}
}
I’ve tryied also to send a standard command with this code:
//Write DAC Register (not fast)
uint bufferLenght = 4;
Byte[] DataToWrite = new Byte[bufferLenght];
DataToWrite[0] = 192;
DataToWrite[1] = MCP4726_CMD_WRITEDAC; // cmd to update the DAC
DataToWrite[2] = (byte)(iValue >> 4); // the 8 most significant bits... (D11.D10.D9.D8.D7.D6.D5.D4)
DataToWrite[3] = (byte)((iValue & 15) << 4); // the 4 least significant bits... (D3.D2.D1.D0)
But it’s not working.
I hope someone could help me, I will really appreciate…
Thanks in advance.