DT PWM
Edit this on GitLab
DT PWM Sample Application (SSK 2.x)
Overview
The DT PWM sample application demonstrates how to configure and output Pulse Width Modulation (PWM) signals on DT (Discrete) channels using the NAI Software Support Kit (SSK 2.x). It shows how to set the pulse period, pulse width, polarity, and burst count, and how to start and stop PWM output on individual channels or across all channels simultaneously.
PWM output on DT modules is an enhanced operating mode where the FPGA generates a precisely timed pulse train on the selected channel. The module supports two PWM modes: continuous (repeats indefinitely) and burst (repeats for a specified count). The DT PWM application also supports configuring push-pull, high-side, and low-side output formats, and includes a demo mode that automatically configures all channels with incrementing parameters for quick testing.
Supported modules: DT4, and combination modules CM1, CM2, CM8 (also KA and K6 with limitations).
For the SSK 1.x version, see DT PWM (SSK 1.x). For detailed register-level information, consult the DT1 Manual.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a supported DT module installed.
-
SSK 2.x installed on your development host.
-
The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.
-
Appropriate output connections or an oscilloscope on the DT channel(s) under test.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. For details on board connection configuration, see the SSK 2.x Software Development Guide. |
The main() function checks for supported module IDs before proceeding:
#ifdef NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS
int32_t DT_PWM(void)
#else
int32_t main(void)
#endif
{
/* ... standard startup ... */
if (moduleID == NAIBRD_MODULE_ID_DT4
|| moduleID == NAIBRD_MODULE_ID_CM1
|| moduleID == NAIBRD_MODULE_ID_CM2
|| moduleID == NAIBRD_MODULE_ID_CM8)
Run_DT_PWM(cardIndex, module, moduleID);
else
naiif_printf("\r\nModule does have DT enhanced functionality\r\n");
/* ... */
}
The module is further validated with naibrd_DT_GetChannelCount().
|
Important
|
Common connection errors:
|
Program Structure
Entry Point
On standard platforms the entry point is main(). On VxWorks the entry point is DT_PWM().
Command Loop
| Command | Description |
|---|---|
Mode |
Select continuous, burst, or standard input mode |
Period |
Set PWM period (ms) |
Width |
Set PWM pulse width (ms) |
Count |
Set burst count |
POlarity |
Set output polarity (positive or negative) |
PM |
Display current PWM configuration |
Trigger |
Start PWM output |
Halt |
Stop PWM output |
Demo |
Configure all channels with incrementing parameters |
Reset |
Reset all channels to initial settings |
Stat |
Display channel status |
SETBurst |
Set all channels to PWM burst mode |
SETCont |
Set all channels to PWM continuous mode |
PWM Mode Selection
Continuous Mode
check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan,
NAIBRD_DT_MODE_OUTPUT_PWM_FOREVER));
PWM Parameter Configuration
Period
check_status(naibrd_DT_SetPWM_Period(cardIndex, module, chan, time));
The valid range depends on the module. For DT4/CM modules, the maximum is 0xFFFFFFFF * LSB. For KA/K6 modules, the maximum is 0xFFFF * LSB.
Displaying Configuration and Status
PWM Configuration
check_status(naibrd_DT_GetPWM_Period(cardIndex, module, chan, &period));
check_status(naibrd_DT_GetPWM_Pulsewidth(cardIndex, module, chan,
&pulsewidth));
check_status(naibrd_DT_GetPWM_BurstNum(cardIndex, module, chan,
&burstnumber));
check_status(naibrd_DT_GetPWM_Polarity(cardIndex, module, chan,
&polaritysetting));
Troubleshooting Reference
| Symptom | Possible Cause and Resolution |
|---|---|
No PWM output |
PWM has not been triggered. Call |
PWM period is incorrect |
Verify the period value. Check valid range using |
Burst mode not supported |
KA and K6 modules do not support burst mode. |
Module not recognized |
|
Overcurrent status |
Output may be shorted or overloaded. |
Output polarity inverted |
Check polarity with |
Full Source
Full Source — dt_pwm.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"
/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_dt.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"
static const int8_t *DEF_CONFIG_FILE = (const int8_t *)"default_DT_PWM.txt";
/* Function prototypes */
static void Run_DT_PWM(int32_t cardIndex, int32_t module, uint32_t modid);
static void Cfg_DT_PWM_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static nai_status_t Display_DT_PWM_Configuration(int32_t paramCnt, int32_t* p_params);
static nai_status_t Display_DT_Status(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PWM_Mode(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PWM_Polarity(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PWM_Period(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PWM_Pulsewidth(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PWM_Burstcount(int32_t paramCnt, int32_t* p_params);
static void Verify_DT_ParamCnt(int32_t paramCnt);
static const int32_t DEF_DT_CARD_INDEX = 0;
static const int32_t DEF_DT_MODULE = 1;
static const int32_t DEF_DT_CHANNEL = 1;
static const int32_t DEF_DT_KA_CHANNEL = 13;
/****** Command Table *******/
enum dt_pwm_commands
{
DT_PWM_CMD_MODE,
DT_PWM_CMD_PERIOD,
DT_PWM_CMD_PULSEWIDTH,
DT_PWM_CMD_BURSTCOUNT,
DT_PWM_CMD_POLARITY,
DT_PWM_CMD_PWM_CFG,
DT_PWM_CMD_PWM_START,
DT_PWM_CMD_PWM_STOP,
DT_PWM_CMD_PWM_DEMO,
DT_PWM_CMD_PWM_INITIAL,
DT_PWM_CMD_STATUS,
DT_PWM_CMD_PWM_BURST,
DT_PWM_CMD_PWM_CONT,
DT_PWM_CMD_COUNT
};
/****** Command Tables *******/
static naiapp_cmdtbl_params_t DT_PWM_MenuCmds[] = {
{"Mode", " DT Select PWM Mode", DT_PWM_CMD_MODE, Configure_DT_PWM_Mode},
{"Period", " DT Set PWM Period", DT_PWM_CMD_PERIOD, Configure_DT_PWM_Period},
{"Width", " DT Set PWM Pulsewidth", DT_PWM_CMD_PULSEWIDTH, Configure_DT_PWM_Pulsewidth},
{"Count", " DT Set PWM Burst count", DT_PWM_CMD_BURSTCOUNT, Configure_DT_PWM_Burstcount},
{"POlarity", " DT Set PWM Polarity", DT_PWM_CMD_POLARITY, Configure_DT_PWM_Polarity},
{"PM", " DT Display PWM configuration settings", DT_PWM_CMD_PWM_CFG, Display_DT_PWM_Configuration},
{"Trigger", " DT Start PWM output", DT_PWM_CMD_PWM_START, NULL},
{"Halt", " DT Stop PWM output", DT_PWM_CMD_PWM_STOP, NULL},
{"Demo", " DT Demo PWM Settings", DT_PWM_CMD_PWM_DEMO, NULL},
{"Reset", " DT Reset All Channels to Initial Settings",DT_PWM_CMD_PWM_INITIAL, NULL},
{"Stat", " DT Display Status", DT_PWM_CMD_STATUS, Display_DT_Status},
{"SETBurst", " DT Set all channels to PWM Burst", DT_PWM_CMD_PWM_BURST, NULL},
{"SETCont", " DT Set all channels to PWM Continuous", DT_PWM_CMD_PWM_CONT, NULL},
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the DT_PWM is to illustrate the methods to call in the naibrd library to perform configuration
setup for output in PWM operation mode. Pulse period, pulse width, pulse polarity settings are configurable.
The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd DT routines.
- ClearDeviceCfg
- QuerySystemCfg
- DisplayDeviceCfg
- GetBoardSNModCfg
- SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#ifdef NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS
int32_t DT_PWM(void)
#else
int32_t main(void)
#endif
{
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
bool_t stop = NAI_FALSE;
uint32_t moduleID;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Select Card Index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_DT_CARD_INDEX, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Select Module */
stop = naiapp_query_ModuleNumber(moduleCnt, DEF_DT_MODULE, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
if (moduleID == NAIBRD_MODULE_ID_DT4 || moduleID == NAIBRD_MODULE_ID_CM1 || moduleID == NAIBRD_MODULE_ID_CM2 || moduleID == NAIBRD_MODULE_ID_CM8)
Run_DT_PWM(cardIndex, module, moduleID);
else naiif_printf("\r\nModule does have DT enhanced functionality\r\n");
naiif_printf("\r\nType Q to quit or Enter to continue:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
}
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/**************************************************************************************************************/
/**
* <summary>
* Verify_DT_ParamCnt verifies parameter count and displays error message if invalid.
* </summary>
*/
/**************************************************************************************************************/
static void Verify_DT_ParamCnt(int32_t paramCnt)
{
if (paramCnt != APP_PARAM_COUNT)
{
naiif_printf(" *** Parameter count specified is incorrect!!! ***\r\n");
}
}
/**************************************************************************************************************/
/**
<summary>
Run_DT_PWM prompts the user for the card, module and channel to use for the application and calls
Cfg_DT_PWM_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
static void Run_DT_PWM(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit = NAI_FALSE;
int32_t maxchannel;
if (!bQuit)
{
maxchannel = naibrd_DT_GetChannelCount(modid);
if (maxchannel == 0)
{
naiif_printf(" *** Module selection not recognized as DT module. ***\r\n\r\n");
}
else
{
Cfg_DT_PWM_Channel(cardIndex, module, modid, maxchannel);
}
}
}
/**************************************************************************************************************/
/**
<summary>
Cfg_DT_PWM_Channel handles calling the Display_DT_PWM_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_DT_PWM_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
bool_t bQuit = NAI_FALSE;
bool_t bContinue = NAI_TRUE;
bool_t bCmdFound = NAI_FALSE;
int32_t chan, defaultchan = 1;
int32_t ch_loop;
int32_t cmd;
float64_t time;
nai_status_t status = 0;
naiapp_AppParameters_t dtparams;
p_naiapp_AppParameters_t dtParams = &dtparams;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
while (bContinue)
{
naiif_printf("\r\n\r\n");
naiif_printf("Channel selection\r\n");
naiif_printf("=================\r\n");
if (ModuleID == NAIBRD_MODULE_ID_KA)
{
naiif_printf("\r\n For KA modules, only Channels 13-16 are configurable.");
naiif_printf("\r\n Ch.01-12 are output only, Ch.17-28 are input only.\r\n");
defaultchan = DEF_DT_KA_CHANNEL;
}
else
{
defaultchan = DEF_DT_CHANNEL;
}
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
dtParams->cardIndex = cardIndex;
dtParams->module = module;
dtParams->channel = chan;
naiapp_utils_LoadParamMenuCommands(DT_PWM_CMD_COUNT, DT_PWM_MenuCmds);
while (bContinue)
{
Display_DT_PWM_Configuration(APP_PARAM_COUNT, (int32_t*)dtParams);
naiapp_display_ParamMenuCommands((int8_t *)"DT PWM Operation Menu");
naiif_printf("\r\nType DT command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
status = 0;
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case DT_PWM_CMD_MODE:
case DT_PWM_CMD_PERIOD:
case DT_PWM_CMD_PULSEWIDTH:
case DT_PWM_CMD_BURSTCOUNT:
case DT_PWM_CMD_POLARITY:
case DT_PWM_CMD_PWM_CFG:
case DT_PWM_CMD_STATUS:
DT_PWM_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dtParams);
break;
case DT_PWM_CMD_PWM_START:
check_status(naibrd_DT_StartPWM(cardIndex, module, chan));
break;
case DT_PWM_CMD_PWM_STOP:
check_status(naibrd_DT_StopPWM(cardIndex, module, chan));
naiif_printf("Mode reset to Input\r\n");
break;
case DT_PWM_CMD_PWM_DEMO:
{
if ((ModuleID == NAIBRD_MODULE_ID_KA) || (ModuleID == NAIBRD_MODULE_ID_K6))
{
naiif_printf("PWM burst mode not supported for this module\r\n");
break;
}
naiif_printf("Set up all channels in incrementing period/pulsewidths and burstcounts? \r\n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= MaxChannel; ch_loop++)
{
time = ch_loop;
status |= check_status(naibrd_DT_SetPWM_Period(cardIndex, module, ch_loop, time));
time /= 10.0;
status |= check_status(naibrd_DT_SetPWM_Pulsewidth(cardIndex, module, ch_loop, time));
status |= check_status(naibrd_DT_SetPWM_BurstNum(cardIndex, module, ch_loop, ch_loop));
}
if (status == NAI_SUCCESS)
naiif_printf("\r\n PWM channel configuration initialized for all channels. \r\n Set PWM Mode as needed. ");
else
naiif_printf("\r\n Configuration not completed successfully. \r\n");
}
}
}
}
break;
case DT_PWM_CMD_PWM_INITIAL:
{
naiif_printf("Reset all channels to initial configuration? \r\n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= MaxChannel; ch_loop++)
{
status |= check_status(naibrd_DT_SetOutputState(cardIndex, module, ch_loop, NAIBRD_DT_STATE_LO));
status |= check_status(naibrd_DT_SetIOFormat(cardIndex, module, ch_loop, NAIBRD_DT_IOFORMAT_INPUT));
status |= check_status(naibrd_DT_SetPWM_Pulsewidth(cardIndex, module, ch_loop, 0.01));
status |= check_status(naibrd_DT_SetPWM_BurstNum(cardIndex, module, ch_loop, 1));
status |= check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, ch_loop, NAIBRD_DT_MODE_STD_INPUT_OUTPUT));
status |= check_status(naibrd_DT_SetDebounceTime(cardIndex, module, ch_loop, 0.01));
status |= check_status(naibrd_DT_GetDebounceTime(cardIndex, module, ch_loop, &time));
if (time > 1E-10)
status++;
}
if (status == NAI_SUCCESS)
naiif_printf("\r\n PWM channel configuration initialized for all channels. \r\n");
else
naiif_printf("\r\n Initialization not completed successfully. \r\n");
}
}
}
}
break;
case DT_PWM_CMD_PWM_BURST:
{
if ((ModuleID == NAIBRD_MODULE_ID_KA) || (ModuleID == NAIBRD_MODULE_ID_K6))
{
naiif_printf("PWM burst mode not supported for this module\r\n");
break;
}
naiif_printf("Reset all channels to PWM burst mode? \r\n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= MaxChannel; ch_loop++)
{
status |= check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, ch_loop, NAIBRD_DT_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES));
status |= check_status(naibrd_DT_SetIOFormat(cardIndex, module, ch_loop, NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL));
}
if (status == NAI_SUCCESS)
naiif_printf("\r\n PWM channel configuration set for PWM Burst mode for all channels. \r\n");
else
naiif_printf("\r\n Initialization not completed successfully. \r\n");
}
}
}
}
break;
case DT_PWM_CMD_PWM_CONT:
{
naiif_printf("Reset all channels to PWM continuous mode? \r\n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= MaxChannel; ch_loop++)
{
status |= check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, ch_loop, NAIBRD_DT_MODE_OUTPUT_PWM_FOREVER));
status |= check_status(naibrd_DT_SetIOFormat(cardIndex, module, ch_loop, NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL));
}
if (status == NAI_SUCCESS)
naiif_printf("\r\n PWM channel configuration set for PWM Continuous mode for all channels. \r\n");
else
naiif_printf("\r\n Initialization not completed successfully. \r\n");
}
}
}
}
break;
default:
naiif_printf("Invalid command entered\r\n");
break;
}
}
else
naiif_printf("Invalid command entered\r\n");
}
}
else
bContinue = NAI_FALSE;
}
}
}
/**************************************************************************************************************/
/**
<summary>
Display_DT_PWM_Configuration illustrate the methods to call in the naibrd library to retrieve the PWM
configuration settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DT_PWM_Configuration(int32_t paramCnt, int32_t* p_params)
{
naibrd_dt_pwm_polarity_t polaritysetting;
float64_t period;
float64_t pulsewidth;
int32_t burstnumber;
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
/* Available configuration settings:
PWM period", (Value read back in milliseconds)
PWM pulsewidth", (Value read back in milliseconds)
PWM burst count (Number of pulses issued upon trigger in burst mode)
PWM polarity", 0 = positive going pulsewidth, 1 = negative going
*/
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\n");
naiif_printf(" -------------PWM Configuration Settings--------------------------------------------\r\n");
naiif_printf(" Period (ms) Pulsewidth (ms) Burst Cnt Polarity\r\n");
naiif_printf(" -------------- ---------------- ----------- -----------\r\n");
check_status(naibrd_DT_GetPWM_Period(cardIndex, module, chan, &period));
naiif_printf(" %10.6f ", period);
check_status(naibrd_DT_GetPWM_Pulsewidth(cardIndex, module, chan, &pulsewidth));
naiif_printf(" %10.6f ", pulsewidth);
check_status(naibrd_DT_GetPWM_BurstNum(cardIndex, module, chan, &burstnumber));
naiif_printf(" 0x%08X ", burstnumber);
status = check_status(naibrd_DT_GetPWM_Polarity(cardIndex, module, chan, &polaritysetting));
if (polaritysetting == 0)
naiif_printf(" POS ");
else
naiif_printf(" NEG ");
naiif_printf("\r\n\r\n");
return status;
}
/**************************************************************************************************************/
/**
<summary>
Display_DT_Status illustrate the methods to call in the naibrd library to retrieve the status settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DT_Status(int32_t paramCnt, int32_t* p_params)
{
naibrd_dt_ioformat_t IOformat;
naibrd_dt_state_t state;
uint32_t ModuleID;
nai_status_t retstatus = NAI_ERROR_NOT_SUPPORTED;
nai_status_bit_t status = 0;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
Verify_DT_ParamCnt(paramCnt);
/* Available settings:
IO configuration,
Output setting,
Input state,
BIT status RT/Latched,
Low-High transition RT/Latched,
High-Low transition RT/Latched,
Overcurrent RT/Latched
*/
naiif_printf("\r\n");
naiif_printf(" -----------------DT Status ---------------------------- \r\n");
naiif_printf(" BIT \r\n");
naiif_printf(" IOConfig OutputSetting InputState Latched / RT \r\n");
naiif_printf(" --------- --------------- ----------- --------------- \r\n");
naibrd_GetModuleName(cardIndex, module, &ModuleID);
check_status(naibrd_DT_GetIOFormat(cardIndex, module, chan, &IOformat));
switch (ModuleID)
{
case NAIBRD_MODULE_ID_DT1:
case NAIBRD_MODULE_ID_DT4:
case NAIBRD_MODULE_ID_CM1:
case NAIBRD_MODULE_ID_CM2:
case NAIBRD_MODULE_ID_CM8:
case NAIBRD_MODULE_ID_K6:
case NAIBRD_MODULE_ID_K9:
case NAIBRD_MODULE_ID_KB:
case NAIBRD_MODULE_ID_PD:
{
switch (IOformat)
{
case NAIBRD_DT_IOFORMAT_INPUT:
naiif_printf(" INPUT ");
break;
case NAIBRD_DT_IOFORMAT_OUTPUT_LOW:
naiif_printf(" Low Side");
break;
case NAIBRD_DT_IOFORMAT_OUTPUT_HIGH:
naiif_printf("High Side");
break;
case NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL:
naiif_printf("Push/Pull");
break;
default:
naiif_printf(" ERROR ");
break;
}
break;
}
case NAIBRD_MODULE_ID_KA:
switch (IOformat)
{
case NAIBRD_DT_IOFORMAT_INPUT:
naiif_printf(" INPUT ");
break;
case NAIBRD_DT_IOFORMAT_OUTPUT_LOW:
naiif_printf(" Low Side");
break;
default:
naiif_printf(" ERROR ");
break;
}
break;
default:
naiif_printf(" UNKNOWN ");
break;
}
naiif_printf(" ");
check_status(naibrd_DT_GetOutputState(cardIndex, module, chan, &state));
switch (state)
{
case NAIBRD_DT_STATE_HI:
naiif_printf(" HI ");
break;
case NAIBRD_DT_STATE_LO:
naiif_printf(" LO ");
break;
default:
naiif_printf(" UNK ");
break;
}
naiif_printf(" ");
check_status(naibrd_DT_GetInputState(cardIndex, module, chan, &state));
switch (state)
{
case NAIBRD_DT_STATE_HI:
naiif_printf(" HI ");
break;
case NAIBRD_DT_STATE_LO:
naiif_printf(" LO ");
break;
default:
naiif_printf(" UNK ");
break;
}
naiif_printf(" ");
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_BIT_LATCHED, &status)); /*BIT latched*/
naiif_printf(" %d ", status);
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_BIT_REALTIME, &status)); /*BIT RT*/
naiif_printf(" %d ", status);
naiif_printf("\r\n\r\n\r\n\r\n");
naiif_printf(" Lo-hi Transition Hi-lo Transition Overcurrent\r\n");
naiif_printf(" Latched / RT Latched / RT Latched / RT\r\n");
naiif_printf(" ---------------- ------------------ ----------------\r\n");
naiif_printf(" ");
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_LO_HI_TRANS_LATCHED, &status));
naiif_printf(" %d ", status);
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_LO_HI_TRANS_REALTIME, &status));
naiif_printf(" %d ", status);
naiif_printf(" ");
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_HI_LO_TRANS_LATCHED, &status));
naiif_printf(" %d ", status);
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_HI_LO_TRANS_REALTIME, &status));
naiif_printf(" %d ", status);
naiif_printf(" ");
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_OVERCURRENT_LATCHED, &status));
naiif_printf(" %d ", status);
retstatus = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_OVERCURRENT_REALTIME, &status));
naiif_printf(" %d ", status);
naiif_printf("\r\n\r\n");
return retstatus;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_PWM_Mode handles the user request to select the PWM mode for the selected channel
and calls the method in the naibrd library to set the mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_PWM_Mode(int32_t paramCnt, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
bool_t bQuit = NAI_FALSE;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\n == PWM Mode Selection == \r\n C Continuous PWM mode \r\n Burst PWM Burst mode \r\n None Basic input mode \r\n\r\n Type DT command : ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'C'))
{
status = check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan, NAIBRD_DT_MODE_OUTPUT_PWM_FOREVER));
}
else if ((toupper(inputBuffer[0]) == 'B'))
{
status = check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan, NAIBRD_DT_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES));
}
else if ((toupper(inputBuffer[0]) == 'N'))
{
status = check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan, NAIBRD_DT_MODE_STD_INPUT_OUTPUT));
}
}
}
return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_PWM_Polarity handles the user request to select the PWM output polarity for the selected channel
and calls the method in the naibrd library for the setting.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_PWM_Polarity(int32_t paramCnt, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
bool_t bQuit = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\n == PWM Output Polarity Selection == \r\n Pos DT PWM positive going pulse output \r\n Neg DT PWM negative going pulse output \r\n\r\n Type DT command : ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'P'))
status = check_status(naibrd_DT_SetPWM_Polarity(cardIndex, module, chan, NAIBRD_DT_PWMPOLARITY_POS));
else if ((toupper(inputBuffer[0]) == 'N'))
status =check_status(naibrd_DT_SetPWM_Polarity(cardIndex, module, chan, NAIBRD_DT_PWMPOLARITY_NEG));
}
}
return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_PWM_Period handles the user request to configure the time values for period on the selected
channel and calls the method in the naibrd library to set the period.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_PWM_Period(int32_t paramCnt, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
float64_t time = 0.0;
float64_t lsb = 0;
float64_t min = 1;
float64_t max = -1;
uint32_t ModuleID;
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\nEnter the desired period in ms: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
naibrd_GetModuleName(cardIndex, module, &ModuleID);
time = atof((const char *)inputBuffer); /*entry in milliseconds*/
lsb = naibrd_DT_GetTimebaseLSB(ModuleID);
switch (ModuleID)
{
case NAIBRD_MODULE_ID_DT1:
case NAIBRD_MODULE_ID_DT4:
case NAIBRD_MODULE_ID_CM1:
case NAIBRD_MODULE_ID_CM2:
case NAIBRD_MODULE_ID_CM8:
min = (float64_t)(0x2u * lsb);
max = (float64_t)(0xFFFFFFFF * lsb);
break;
case NAIBRD_MODULE_ID_KA:
case NAIBRD_MODULE_ID_K6:
min = (float64_t)(0x2u * lsb);
max = (float64_t)(0xFFFF * lsb);
break;
default:
break;
}
if (time > max || time < min)
naiif_printf(" Entry out of range. Range %7.3f to %7.3f ms\r\n", min, max);
else
{
status = check_status(naibrd_DT_SetPWM_Period(cardIndex, module, chan, time));
}
}
}
return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_PWM_Pulsewidth handles the user request to configure the time values for pulsewidth on the selected
channel and calls the method in the naibrd library to set the width.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_PWM_Pulsewidth(int32_t paramCnt, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
float64_t time = 0.0;
float64_t lsb = 0;
float64_t min = 1;
float64_t max = -1;
uint32_t ModuleID;
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\nEnter the desired pulsewidth in milliseconds: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
status = naibrd_GetModuleName(cardIndex, module, &ModuleID);
time = atof((const char *)inputBuffer);
lsb = naibrd_DT_GetTimebaseLSB(ModuleID);
switch (ModuleID)
{
case NAIBRD_MODULE_ID_DT1:
case NAIBRD_MODULE_ID_DT4:
case NAIBRD_MODULE_ID_CM1:
case NAIBRD_MODULE_ID_CM2:
case NAIBRD_MODULE_ID_CM8:
min = (float64_t)(0x1u * lsb);
max = (float64_t)(0xFFFFFFFE * lsb);
break;
case NAIBRD_MODULE_ID_KA:
case NAIBRD_MODULE_ID_K6:
min = (float64_t)(0x1u * lsb);
max = (float64_t)(0xFFFE * lsb);
break;
default:
break;
}
if (time > max || time < min)
naiif_printf(" Entry out of range. Range %7.3f to %7.3f ms\r\n", min, max);
else
{
status = check_status(naibrd_DT_SetPWM_Pulsewidth(cardIndex, module, chan, time));
}
}
}
return status;
}
/**************************************************************************************************************/
/**
<summary>
Handles the user request to set the burst count value for the number of pulses to be issued upon trigger in
PWM burst mode operation on the selected channel, calling the method in the naibrd library to set the burst number.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_PWM_Burstcount(int32_t paramCnt, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
uint32_t burstcount;
uint32_t ModuleID;
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\nEnter the desired burst count: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
status = naibrd_GetModuleName(cardIndex, module, &ModuleID);
burstcount = atoi((const char *)inputBuffer);
switch (ModuleID)
{
case NAIBRD_MODULE_ID_DT1:
case NAIBRD_MODULE_ID_DT4:
case NAIBRD_MODULE_ID_CM1:
case NAIBRD_MODULE_ID_CM2:
case NAIBRD_MODULE_ID_CM8:
if (burstcount < 1)
{
burstcount = 1; /*minimum count is one*/
naiif_printf("Setting burstcount to minimum of 1.\r\n");
}
status = check_status(naibrd_DT_SetPWM_BurstNum(cardIndex, module, chan, burstcount));
break;
default:
naiif_printf("Unsupported function for this module.\r\n");
break;
}
}
}
return status;
}