MX Foundation 4
adc.c
/*****************************************************************************
//
// File:
// adc.c
//
// Copyright (c) MAX Technologies Inc. 1988-2019, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the configuration of an IPM-ADC module and perform
// acquisition on 32 single-ended channels.
// Hardware requirements:
// - MAXT 500 series carrier with IPM-ADC (jumpers must be set for +/- 10V operation).
//
*****************************************************************************/
#include "example.h"
#define MAX_ANALOG_CHN_NUM 32
#define MAX_REC 1000
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_MODULE module=0;
HMXF_CHANNEL rxChn[MAX_ANALOG_CHN_NUM];
HMXF_BUFFER rxBuffer[MAX_ANALOG_CHN_NUM];
MXF_ANALOG_DATAREC recANALOG[MAX_REC];
int iPort;
uint64 count=0;
uint64 status=0, byteCount, iRec;
// Connect to services and initialize environment
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
if (rc != MAXT_SUCCESS)
{
printf("Failed to connect; rc=0x%08x", rc);
printf("\nPress a key to terminate\n");
getchar();
return 0;
}
// Initialize the server
printf("\nStarting\n");
rc = mxfSystemInit(server);
// Get a handle to 32 Analog IPM-ADC channel
if (!rc)
rc = mxfChannelAllGet(server, MXF_CLASS_ANALOG, MXF_SCLASS_RX_CHANNEL, MXF_MODULE_ALL, MAX_ANALOG_CHN_NUM, &count, rxChn);
// If channel not found, return an error
if (!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
if (!rc)
rc = mxfChannelInfoGet(rxChn[0], NULL, &module);
// Set time base
if(!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_USEC);
// Set the scan mode to burst continuous
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_SCAN_MODE, VMXF_ANALOG_MODULE_ADC_SCAN_MODE_BURST_CONTINUOUS);
// Set the conversion rate to 1 millisecond
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_CONVERSION_PERIOD, 1000);
// Set calibration mode to disable
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_CALIBRATION_MODE, VMXF_ANALOG_MODULE_ADC_CALIBRATION_MODE_DISABLE);
// Set the input range to +/-10v
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_INPUT_RANGE, VMXF_ANALOG_MODULE_ADC_INPUT_RANGE_10v);
// Set the data format to float
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_DATA_FORMAT, VMXF_ANALOG_MODULE_ADC_DATA_FORMAT_FLOAT);
// Set the channel differential selection to none (all single ended)
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_CHN_DIFF_SELECTION, 0x0000);
// Set the channel selection to all
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_CHN_SELECTION, 0xffffffff);
for(iPort=0;!rc && iPort<MAX_ANALOG_CHN_NUM;iPort++)
{
// Allocate RX acquisition buffer
rc = mxfRxAcqBufferAlloc(rxChn[iPort], sizeof(recANALOG), &rxBuffer[iPort], NULL);
//Start acquisition
if(!rc)
rc = mxfRxAcqStart(rxBuffer[iPort], MXF_RXACQ_FLAG_DEFAULT, 0, 0);
}
// Wait a little
if(!rc)
mxfSleep(100);
for (iPort = 0; !rc && iPort < MAX_ANALOG_CHN_NUM; iPort++)
{
//Stop acquisition
rc = mxfRxAcqStop(rxBuffer[iPort]);
}
for(iPort=0;!rc && iPort<MAX_ANALOG_CHN_NUM;iPort++)
{
rc = mxfAnalogRxAcqRead(rxBuffer[iPort], 0, sizeof(recANALOG), &status, &count, &byteCount, recANALOG);
p = recANALOG;
for(iRec=0;!rc && iRec<count;iRec++)
{
printf( "Value of channel %d at %llu is %.3f. V\n\r", iPort, p->timeTag, p->data.value);
}
if (!rc)
rc = mxfRxAcqClear(rxBuffer[iPort]);
if (!rc)
rc = mxfRxAcqBufferFree(rxBuffer[iPort]);
}
if (rc)
{
char buffer[256];
if (mxfSystemErrorStringGet(server, rc, sizeof(buffer), buffer))
sprintf(buffer, "ERROR # 0x%08X", rc);
printf("%s\n\r", buffer);
}
// Terminate
printf("\nPress enter to terminate\n");
getchar();
return rc;
}
Updated 10/23/2023