MX Foundation 4
adc_sampling.c
/*****************************************************************************
//
// File:
// adc_sampling.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
// sampling on 16 differential 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 16
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
HMXF_CHANNEL rxChn[MAX_ANALOG_CHN_NUM];
HMXF_BUFFER rxBuffer[MAX_ANALOG_CHN_NUM];
int iPort;
uint64 count=0;
uint64 byteCount;
uint64 timerStart=0, timer=0;
// 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 16 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], &device, &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 all differential
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_CHN_DIFF_SELECTION, 0xffff);
// Set the channel selection to 16
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_ANALOG_MODULE_ADC_CHN_SELECTION, 0x0000ffff);
for(iPort=0;!rc && iPort<MAX_ANALOG_CHN_NUM;iPort++)
{
// Allocate RX sampling buffer
rc = mxfRxSamplingBufferAlloc(rxChn[iPort], sizeof(recANALOG), &rxBuffer[iPort], NULL);
//Start sampling
if(!rc)
rc = mxfRxSamplingStart(rxBuffer[iPort]);
}
if(!rc)
rc = mxfDeviceTimerGet(device, &timerStart);
if(!rc)
{
do
{
mxfSleep(1000);
for (iPort = 0; !rc && iPort < MAX_ANALOG_CHN_NUM; iPort++)
{
rc = mxfAnalogRxSamplingRead(rxBuffer[iPort], MXF_RXSAMPLING_FLAG_DEFAULT, sizeof(recANALOG), &count, &byteCount, &recANALOG);
printf("Value of channel %d at %llu is %.3f. V\n\r", iPort, recANALOG.timeTag, recANALOG.data.value);
}
if (!rc)
rc = mxfDeviceTimerGet(device, &timer);
}while(!rc && ((timer-timerStart) < 5000000));
}
for(iPort=0;!rc && iPort<MAX_ANALOG_CHN_NUM;iPort++)
{
//Stop acquisition
rc = mxfRxSamplingStop(rxBuffer[iPort]);
if (!rc)
rc = mxfRxSamplingBufferFree(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