#include #include #include #include "dm5406.h" #include "nortlib.h" unsigned short DM_DoConversion( void ) { unsigned short value; /* Start the conversion */ outp( BaseAddress + START_CONVERSION, 0 ); /* Wait for conversion to complete */ while ( ( inp( BaseAddress + STATUS_BYTE ) & 1 ) == 0 ) ; /* Read the Data, MSB first */ value = ( inp( BaseAddress + READ_DATA ) & 0x0F ) * 256; value += inp( BaseAddress + READ_DATA ) & 0xFF; return value; } /* The channel here includes the gain: To read channel 3 with A gain of 8: Read_AtoD( 3 | GAIN_8 ) */ unsigned short DM_Read_AtoD( unsigned char Channel ) { unsigned char B; /* Set the conversion channel: */ Channel &= AD_MASK; B = inp( BaseAddress + CHANNEL_SLCT ); if ( ( B & AD_MASK ) != Channel ) { B = ( B & ~AD_MASK ) | Channel; outp( BaseAddress + CHANNEL_SLCT, B ); DM_DoConversion(); /* Once for settling time */ } return DM_DoConversion(); } /******************* DM_Reset The ResetBoard procedure is used to reset the DM5406. The 8255 PPI is configured so that ports A and C are input and port B is output, a dummy A-D conversion is performed and then the clear board command is sent. *******************/ void DM_Reset(void) { outp(BaseAddress + PPI_CTRL, 0x99); /* Set PPI Port B for output */ outp(BaseAddress + PPI_B, 0); /* Channel 0, Gain 1, Ext Trig = Disabled, IRQ = Disabled */ outp(BaseAddress + SCAN_BURST_SLCT, 0); outp(BaseAddress + CLEAR_BOARD, 0); DM_DoConversion(); /* Dummy Conversion */ outp(BaseAddress + CLEAR_BOARD, 0); /* Any value will do */ } /***************** DM_DAC_Write The DM_DAC_Write procedure outputs the specified voltage to the specifed DAC. *****************/ void DM_DAC_Write( unsigned char DAC, unsigned short Value ) { if ( DAC > 1 ) { nl_error( 2, "Illegal DAC address %d", DAC ); return; } if ( Value >= 0x1000 ) { nl_error( 2, "DAC Setpoint out of bounds", DAC); return; } outp(BaseAddress + DAC1_LSB + DAC * 2, Value % 256); outp(BaseAddress + DAC1_MSB + DAC * 2, Value / 256); outp(BaseAddress + DAC_UPDATE, 0); } /*********** Read DigitalIO The ReadDigitalIO function returns the value of the specified digital input port. Each digital input line is represented by a bit of the return value. Digital in 0 is bit 0, digital in 1 is bit 1, and so on. ***********/ unsigned char DM_ReadDigitalIO(unsigned char InputPort) { return(inp(BaseAddress + PPI_A + InputPort)); } /*********** WriteDigitalIO The WriteDigitalIO function sets the value of the digital output port to equal the value passed as parameter v. Each digital output line is represented by a bit of v. Digital out 0 is bit 0, digital out 1 is bit 1, and so on. ***********/ void DM_WriteDigitalIO(unsigned char OutputPort, unsigned char v) { outp(BaseAddress + PPI_A + OutputPort, v); } /***************** ConfigureIOPorts The ConfigureIOPorts procedure is used to configure the ports A and C on the 8255 PPI for either input or output. A value of 1 means input, a value of 0 is for output. It is advisable to use the INPUT and OUTPUT constants defined in this file. Port B remains set for output. *****************/ void DM_ConfigureIOPorts(unsigned char PortA, unsigned char PortC) { unsigned char ControlByte; ControlByte = 128 + (PortA * 16) + (PortC * 9); outp(BaseAddress+PPI_CTRL, ControlByte); }