MX Foundation 4
flexadc.c
/*****************************************************************************
//
// File:
// flexadc.c
//
// Copyright (c) MAX Technologies Inc. 1988-2021, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the configuration of an FlexADC module and perform
// acquisition on 5 single-ended channels.
//
// Hardware requirements:
// - MAXT FlexMAX with FlexADC module.
//
*****************************************************************************/
#include "example.h"
#define MAX_ANALOG_CHN_NUM 64
#define MAX_REC 100
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_MODULE module=0;
HMXF_CHANNEL rxChn[MAX_ANALOG_CHN_NUM];
HMXF_BUFFER rxBuffer;
MXF_FLEXANALOG_DATAREC recANALOG[MAX_REC];
int iPort;
uint64 count=0;
uint64 status=0, byteCount, iRec;
float value;
uint64 index;
// Connect to services and initialize environment
rc = mxfServerConnect("192.168.0.1", "admin", "admin", 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);
if (rc == MAXT_ERROR_ANOTHER_PROCESS_RUNNING)
rc = mxfSystemResourcesInit(server, 0);
// Get a handle to 64 Analog FlexADC channel
if (!rc)
rc = mxfChannelAllGet(server, MXF_CLASS_FLEXANALOG, MXF_SCLASS_RX_CHANNEL, MXF_MODULE_FLEXADC, 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 conversion rate to 10 millisecond
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_FLEXADC_MODULE_CONVERSION_PERIOD, 10000);
// Set the input range to +/-10V single-ended
for(iPort=0; iPort<MAX_ANALOG_CHN_NUM && !rc; iPort++)
rc = mxfAttributeUint64Set(rxChn[iPort], KMXF_FLEXADC_CHN_INPUT_RANGE, VMXF_FLEXADC_CHN_INPUT_RANGE_SE_BIPOLAR_10V);
// Set the channel selection to ADC #0, 4, 17, 18 and 63
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_FLEXADC_MODULE_CHN_SELECTION, 0x8000000000060011ULL);
// Allocate RX acquisition buffer
if(!rc)
rc = mxfRxAcqBufferAlloc(module, sizeof(recANALOG), &rxBuffer, NULL);
//Start acquisition
if(!rc)
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
// Wait a little
if(!rc)
mxfSleep(500);
//Stop acquisition
if(!rc)
rc = mxfRxAcqStop(rxBuffer);
if(!rc)
{
rc = mxfFlexAnalogRxAcqRead(rxBuffer, 0, sizeof(recANALOG), &status, &count, &byteCount, recANALOG);
p = recANALOG;
for(iRec=0;!rc && iRec<count;iRec++)
{
iPort = 0;
index = 0;
do
{
if(p->dataMask & 0x1)
{
rc = mxfFlexAdcDataConvert(rxChn[iPort], p->data[index], &value);
if(!rc)
printf( "Value of ADC %d at %llu is %.3f. V\n\r", iPort, p->timeTag, value);
index++;
}
p->dataMask >>= 1;
iPort++;
}while(!rc && p->dataMask);
}
}
if (!rc)
rc = mxfRxAcqClear(rxBuffer);
if (!rc)
rc = mxfRxAcqBufferFree(rxBuffer);
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