Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading/Writing to EEPROM & CalDac's

I am using the WinCE/Pocket PC port for the DAQ 6036E.
I am having problems writing the calibration values back to the CALDac's. I can Read the EEPROM ok.

Here's my source:
eePROMRead() -(seems to work fine)
/*
*************************************************************************************

FUNCTION: readEEPROM()

RETURNS: value from EEPROM.

NOTES:

*************************************************************************************
*/
int readEEPROM(int address, i32* value)
{

u8 thisbit;
u16 writevalue;
int index;


//Bar1 = bus->createAddressSpace(kPCI_BAR1);
//board = new tESeries(Bar1);

// Instruction: Single Read EEPROM: 0x03
// Address: 508 (0x1FC), factory year calibration
// Because adress is greater then 0xFF use 0x08 as a modifier of the instruction byte
// Upper byte is command plus address modifier, lower byte is lowest 8-bits of address
// EEPROM bit stream to write: 0000 1011 1111 1100

// writevalue = 0x0bfc; // Address: 508 - year factory calibration
// writevalue = 0x0bfb; // Address: 507 - month factory calibration
// writevalue = 0x0bfa; // Address: 506 - day factory calibration

// writevalue = 0x0bff; // Address: 511 - LSB board code
// writevalue = 0x0bfe; // Address: 510 - board revision
// writevalue = 0x0bfd; // Address: 509 - board subrevision
// writevalue = 0x0bda; // Address: 474 - MSB board code for some cards


// Serial Register
// 0x1 - clock
// 0x2 - data
// 0x4 - chip select - enable EEPROM communciation

// double write all communication to the serial interface/EEPROM

if (address > 0xff)
writevalue = 0x0b00 + (address & 0xff);
else
writevalue = 0x0300 + (address & 0xff);

// 0x4 - chip select - enable EEPROM communciation
board->SerialCommandRegister.writeRegister(0x00);
board->SerialCommandRegister.writeRegister(0x00);
board->SerialCommandRegister.writeRegister(0x04);
board->SerialCommandRegister.writeRegister(0x04);


// SerData = address LOC (469,467, 465, 463) to access on EEPROM.
// writevalue = modified address location to access.
for (index = 15; index >= 0; index--)
{// 0
thisbit = ((writevalue >> index) & 0x01) * 0x02;
board->SerialCommandRegister.writeRegister(0x04 + thisbit); // set data bit
board->SerialCommandRegister.writeRegister(0x04 + thisbit);
board->SerialCommandRegister.writeRegister(0x04 + thisbit + 0x1); // set data bit and clock
board->SerialCommandRegister.writeRegister(0x04 + thisbit + 0x1);
board->SerialCommandRegister.writeRegister(0x04);
board->SerialCommandRegister.writeRegister(0x04);
}

myvalue = 0;
// read back PROMOUT (D7-D0) 8-bit result.
for (index = 7; index >= 0; index--)
{
// read bit
board->SerialCommandRegister.writeRegister(0x04); // set clock low
board->SerialCommandRegister.writeRegister(0x04);
board->SerialCommandRegister.writeRegister(0x04 + 0x1); // set clock high
board->SerialCommandRegister.writeRegister(0x04 + 0x1);
thisbit = board->SerialStatus.readEEPROMOut(); // read data bit
thisbit &= 0x1;
myvalue |= thisbit << index;

//printf("thisbit[%d] = %d\n",index,thisbit);

}

delete board;
bus->destroyAddressSpace(Bar1);
return myvalue;
}
===================================================
SerialDacWrite() - this is where I am having problems.

/*********************************************************************

Serial DAC Write for 6036E

*********************************************************************/
int sDacWrite(i16 dac_number, i32 value)
{

i16 length=8;
i16 index;
u8 thisbit;
u16 bitMask;


printf("dac_number = 0x%x\n", dac_number);
printf("value = 0x%x\n", value);

/* Write out CalDac value. */
/* a0 a1 a2 a3 d7 d6 d5 d4 d3 d2 d1 d0 */
//value &= 0xFF;
//value |= dac_number << 8;
//length = 12;
//printf("value1 = 0x%x\n",value);



/* Initially Clock is low. */
/* Clear Clock and calDAC load signals. */
/* make sure EPROM CS is clear */
board->SerialCommandRegister.writeRegister(0x0);
board->SerialCommandRegister.writeRegister(0x0);

/* Write A0-A3 , send each bit with clk */
for(index=0;index <=3;index++)
{

thisbit = ((dac_number >> index) & 0x01);
printf("A[%d] = 0x%x\n",index, thisbit);

// clock SerClk & SerData(data to send)
board->SerialCommandRegister.writeRegister(0x01 + thisbit);
board->SerialCommandRegister.writeRegister(0x01 + thisbit);

// clock SerClk low
board->SerialCommandRegister.writeRegister(0x00 + thisbit);
board->SerialCommandRegister.writeRegister(0x00 + thisbit);

}


/* Write D7-D0, send each bit with clk */
/* Not sure here?????? */
for(index=length-1;index>=0;index--)
{
thisbit = ((value >> index) & 0x01);
printf("D[%d] = 0x%x\n",index,thisbit);

// clock SerClk & SerData(data to send)
board->SerialCommandRegister.writeRegister(0x01 + thisbit);
board->SerialCommandRegister.writeRegister(0x01 + thisbit);

// clock SerClk low
board->SerialCommandRegister.writeRegister(0x00 + thisbit);
board->SerialCommandRegister.writeRegister(0x00 + thisbit);

//thisbit >>=1;
}

/* Send appropriate load signal to update caldac. */
/* Timing diagram says to CLK/PULSE eack SerialDacLdxx */
/* Not sure here????? */

/* Pulse SerDacLd0 - 8 hex */
board->SerialCommandRegister.writeRegister(0x08);
board->SerialCommandRegister.writeRegister(0x08);
board->SerialCommandRegister.writeRegister(0x00);
board->SerialCommandRegister.writeRegister(0x00);

/* Pulse SerDacLd1 - 16 hex */
//board->SerialCommandRegister.writeRegister(0x10);
//board->SerialCommandRegister.writeRegister(0x10);
//board->SerialCommandRegister.writeRegister(0x0);
//board->SerialCommandRegister.writeRegister(0x0);

return 0;
}

====================================================
Here's the calling functions

//Read Calibration values from EEPROM

readEEPROM(469, &myvalue);
//printf("Hex value = 0x%x\n",myvalue);
sDacWrite(4, myvalue);//4


readEEPROM(467, &myvalue);
//printf("Hex value = 0x%x\n",myvalue);
sDacWrite(11, myvalue);

readEEPROM(465, &myvalue);
//printf("Hex value = 0x%x\n",myvalue);
sDacWrite(1, myvalue);

readEEPROM(463, &myvalue);
//printf("Hex value = 0x%x\n",myvalue);
sDacWrite(2, myvalue);
0 Kudos
Message 1 of 8
(4,165 Views)
Thanks to the great tech support. I now have my sSerialDacwrite() function working correctly under the WinCE port for reading EEPROM and writing back to the CalDAC's.

Kind Regards,

Robert Bowen
0 Kudos
Message 2 of 8
(4,166 Views)
I'm trying to exactly what Robert is doing on a WinCE 4.1 device with DAQCard 6036E. When reading the EEPROM the example code by Robert Bowen returns 0's

Any idea what can be wrong?

Andreas Johansson
0 Kudos
Message 3 of 8
(4,165 Views)
Hi, I'm doing the same thing now. I could not find an example. Could you post the code which works? Or you can send it to my email address qw4k@virginia.edu.
Thanks a lot.

flofish
0 Kudos
Message 4 of 8
(4,115 Views)
i am using eCos (Embedded Configurable Operation System) running on a simple intel base computer
 and want to read the calibration constt from EEPROM for NI PCI-6071E card.
but this code always return "myvalue=255". which is not the required value. can any body help me..
the code is a simple modification of the above code according to eCos syntax.
 
 
cyg_uint8 thisbit;
cyg_uint16 writevalue;
int myindex;
cyg_uint8 myvalue = 0; 
writevalue=0x0BFC;//reading the NI-DAQ Board Code
//p_PCI_DIO96->io_address  is the Base Add 1.
// 0x4 - chip select - enable EEPROM communciation
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x00);
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x00);
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x04);
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x04);
 
for (myindex = 15; myindex >= 0; myindex--)
{
thisbit = ((writevalue >> myindex) & 0x01) * 0x02;
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,(0x04 + thisbit)); // set data bit
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,(0x04 + thisbit));
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,(0x04 + thisbit + 0x1)); // set data bit and clock
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,(0x04 + thisbit + 0x1));
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x04);
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x04);
}

// read back PROMOUT (D7-D0) 8-bit result.
for (myindex = 7; myindex >= 0; myindex--)
{
// read bit
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x04); // set clock low
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x04);
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,(0x04 + 0x1)); // set clock high
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,(0x04 + 0x1));
HAL_READ_UINT8(p_PCI_DIO96->io_address+0x01,thisbit); // read data bit
thisbit &= 0x1;
myvalue |= thisbit << myindex;
}
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x00); // set rom low
HAL_WRITE_UINT8(p_PCI_DIO96->io_address + 0x0D,0x00);
printf("my Value = %d\n", myvalue);
printf("Execution completed");
/////////////////////////////////////
0 Kudos
Message 5 of 8
(3,723 Views)
Arshad,
 
Your question will be better answered in the Driver Development Kit Forum.  Could you please post this question there.
 
Thank you,
Raajit L
National Instruments
Message 6 of 8
(3,672 Views)
Hi All-
 
Let's continue the discussion here.
 
Thanks-
Tom W
National Instruments
0 Kudos
Message 7 of 8
(3,649 Views)

I'm trying to use Robert's code to query the EEPROM, and write to the CALDACs on the NI-6036E board. I have a few questions about the following line of code:

 

            thisbit = ((writevalue >> index) & 0x01) * 0x02;

 

I can understand the reason for the right-shift by the index. Can someone explain the reason for the mask with 0x01 and the multiplication by 0x02?

 

Also, the EEPROM read diagram in the PCI E Series Register-Level Programmer Manual here - http://shark.sssup.it/contrib/pci6025e/national/ni_prog.pdf

 

and NI's knowledgebase document here - http://digital.ni.com/public.nsf/allkb/7923356B383F5ECA852563A7004A3B8B

 

mention that:  

 

"During the first 4 clock pulses of the SerClk line, the SerData line needs to be 0. Then, you need to clock in the A8 address bit. Then clock in a 0, then a 1, and then a 1, and then A7-A0. These extra 0's and 1's around the address values are what the instruction refers to."

 

But Robert's code doesn't incorporate the special treatment for the A8 address bit. Does that timing need to be strictly adhered to? 

 

Thanks.

0 Kudos
Message 8 of 8
(2,782 Views)