Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

TTL PWM

TTL PWM Sample Application (SSK 2.x)

Overview

The TTL PWM sample application demonstrates how to configure and output PWM signals on TTL channels using the NAI Software Support Kit (SSK 2.x). PWM is supported on TL2 modules.

Supported modules: TL1, TL2 (PWM restricted to TL2).

For the SSK 1.x version, see TTL PWM (SSK 1.x). For detailed register-level information, consult the TL1 Manual.

Prerequisites

How to Run

Launch the ttl_pwm executable. The configuration file is default_TTL_PWM.txt.

Board Connection and Module Selection

Note

For details on board connection configuration, see the SSK 2.x Software Development Guide.

On VxWorks, the entry point is TTL_PWM(). The module is validated with naibrd_TTL_GetChannelCount(), and the channel configuration checks for NAIBRD_MODULE_ID_TL2.

Program Structure

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

PM

Display PWM configuration

Trigger

Start PWM output

Halt

Stop PWM output

Demo

Auto-configure all channels

Reset

Reset all channels

Stat

Display channel status

SETBurst

Set all channels to burst mode

SETCont

Set all channels to continuous mode

PWM Mode Selection

naibrd_TTL_SetEnhancedMode(cardIndex, module, chan, NAIBRD_TTL_MODE_OUTPUT_PWM_FOREVER);
naibrd_TTL_SetEnhancedMode(cardIndex, module, chan, NAIBRD_TTL_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES);
naibrd_TTL_SetEnhancedMode(cardIndex, module, chan, NAIBRD_TTL_MODE_STD_INPUT_OUTPUT);

PWM Configuration

naibrd_TTL_SetPWM_Period(cardIndex, module, chan, time);
naibrd_TTL_SetPWM_Pulsewidth(cardIndex, module, chan, time);
naibrd_TTL_SetPWM_BurstNum(cardIndex, module, chan, burstcount);
naibrd_TTL_SetPWM_Polarity(cardIndex, module, chan, NAIBRD_TTL_PWMPOLARITY_POS);

Starting and Stopping

naibrd_TTL_StartPWM(cardIndex, module, chan);
naibrd_TTL_StopPWM(cardIndex, module, chan);

Troubleshooting Reference

Symptom Possible Cause and Resolution

PWM not supported

Only TL2 supports PWM.

No output

Call naibrd_TTL_StartPWM().

Module not recognized

naibrd_TTL_GetChannelCount() returned zero.

Full Source

Full Source — ttl_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_ttl.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_TTL_PWM.txt";

/* Function prototypes */
static void Run_TTL_PWM(int32_t cardIndex, int32_t module, uint32_t modid);
static void Cfg_TTL_PWM_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);

static nai_status_t Display_TTL_PWM_Configuration(int32_t paramCnt, int32_t* p_params);
static nai_status_t Display_TTL_Status(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_PWM_Mode(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_PWM_Polarity(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_PWM_Period(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_PWM_Pulsewidth(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_PWM_Burstcount(int32_t paramCnt, int32_t* p_params);
static void Verify_TTL_ParamCnt(int32_t paramCnt);
static const int32_t DEF_TTL_CARD_INDEX = 0;
static const int32_t DEF_TTL_MODULE = 1;
static const int32_t DEF_TTL_CHANNEL = 1;

/****** Command Table *******/
enum ttl_pwm_commands
{
   TTL_PWM_CMD_MODE,
   TTL_PWM_CMD_PERIOD,
   TTL_PWM_CMD_PULSEWIDTH,
   TTL_PWM_CMD_BURSTCOUNT,
   TTL_PWM_CMD_POLARITY,
   TTL_PWM_CMD_PWM_CFG,
   TTL_PWM_CMD_PWM_START,
   TTL_PWM_CMD_PWM_STOP,
   TTL_PWM_CMD_PWM_DEMO,
   TTL_PWM_CMD_PWM_INITIAL,
   TTL_PWM_CMD_STATUS,
   TTL_PWM_CMD_PWM_BURST,
   TTL_PWM_CMD_PWM_CONT,
   TTL_PWM_CMD_COUNT
};

/****** Command Tables *******/
static naiapp_cmdtbl_params_t TTL_PWM_MenuCmds[] = {
   {"Mode",       "    TTL Select PWM Mode",                       TTL_PWM_CMD_MODE,            Configure_TTL_PWM_Mode},
   {"Period",     "    TTL Set PWM Period",                        TTL_PWM_CMD_PERIOD,          Configure_TTL_PWM_Period},
   {"Width",      "    TTL Set PWM Pulsewidth",                    TTL_PWM_CMD_PULSEWIDTH,      Configure_TTL_PWM_Pulsewidth},
   {"Count",      "    TTL Set PWM Burst count",                   TTL_PWM_CMD_BURSTCOUNT,      Configure_TTL_PWM_Burstcount},
   {"POlarity",   "    TTL Set PWM Polarity",                      TTL_PWM_CMD_POLARITY,        Configure_TTL_PWM_Polarity},
   {"PM",         "    TTL Display PWM configuration settings",    TTL_PWM_CMD_PWM_CFG,         Display_TTL_PWM_Configuration},
   {"Trigger",    "    TTL Start PWM output",                      TTL_PWM_CMD_PWM_START,       NULL},
   {"Halt",       "    TTL Stop PWM output",                       TTL_PWM_CMD_PWM_STOP,        NULL},
   {"Demo",       "    TTL Demo PWM Settings",                     TTL_PWM_CMD_PWM_DEMO,        NULL},
   {"Reset",      "    TTL Reset All Channels to Initial Settings",TTL_PWM_CMD_PWM_INITIAL,     NULL},
   {"Stat",       "    TTL Display Status",                        TTL_PWM_CMD_STATUS,          Display_TTL_Status},
   {"SETBurst",   "    TTL Set all channels to PWM Burst",         TTL_PWM_CMD_PWM_BURST,       NULL},
   {"SETCont",    "    TTL Set all channels to PWM Continuous",    TTL_PWM_CMD_PWM_CONT,        NULL},
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the TTL_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 TTL routines.
 - ClearDeviceCfg
 - QuerySystemCfg
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#ifdef NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS
int32_t TTL_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_TTL_CARD_INDEX, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Select Module */
            stop = naiapp_query_ModuleNumber(moduleCnt, DEF_TTL_MODULE, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_TTL_PWM(cardIndex, module, moduleID);
                  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_TTL_ParamCnt verifies parameter count and displays error message if invalid.
 * </summary>
 */
 /**************************************************************************************************************/
static void Verify_TTL_ParamCnt(int32_t paramCnt)
{
   if (paramCnt != APP_PARAM_COUNT)
   {
      naiif_printf(" *** Parameter count specified is incorrect!!! ***\r\n");
   }
}
/**************************************************************************************************************/
/**
<summary>
Run_TTL_PWM prompts the user for the card, module and channel to use for the application and calls
Cfg_TTL_PWM_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
static void Run_TTL_PWM(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = NAI_FALSE;
   int32_t maxchannel;

   if (!bQuit)
   {
      maxchannel = naibrd_TTL_GetChannelCount(modid);
      if (maxchannel == 0)
      {
         naiif_printf(" *** Module selection not recognized as TTL module. ***\r\n\r\n");
      }
      else
      {
         Cfg_TTL_PWM_Channel(cardIndex, module, modid, maxchannel);
      }
   }
}
/**************************************************************************************************************/
/**
<summary>
Cfg_TTL_PWM_Channel handles calling the Display_TTL_PWM_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_TTL_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  ttlparams;
   p_naiapp_AppParameters_t ttlParams = &ttlparams;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      if (ModuleID == NAIBRD_MODULE_ID_TL2)
      {
         naiif_printf("\r\n\r\n");
         naiif_printf("Channel selection\r\n");
         naiif_printf("=================\r\n");

         defaultchan = DEF_TTL_CHANNEL;
         bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
         ttlParams->cardIndex = cardIndex;
         ttlParams->module = module;
         ttlParams->channel = chan;



         naiapp_utils_LoadParamMenuCommands(TTL_PWM_CMD_COUNT, TTL_PWM_MenuCmds);
         while (bContinue)
         {
            Display_TTL_PWM_Configuration(APP_PARAM_COUNT, (int32_t*)ttlParams);
            naiapp_display_ParamMenuCommands((int8_t *)"TTL PWM Operation Menu");
            naiif_printf("\r\nType TTL command or %c to quit : ", NAI_QUIT_CHAR);
            bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
            if (!bQuit)
            {
               if (inputResponseCnt > 0)
               {
                  bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
                  if (bCmdFound)
                  {
                     switch (cmd)
                     {
                     case TTL_PWM_CMD_MODE:
                     case TTL_PWM_CMD_PERIOD:
                     case TTL_PWM_CMD_PULSEWIDTH:
                     case TTL_PWM_CMD_BURSTCOUNT:
                     case TTL_PWM_CMD_POLARITY:
                     case TTL_PWM_CMD_PWM_CFG:
                     case TTL_PWM_CMD_STATUS:
                        TTL_PWM_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttlParams);
                        break;
                     case TTL_PWM_CMD_PWM_START:
                        check_status(naibrd_TTL_StartPWM(cardIndex, module, chan));
                        break;
                     case TTL_PWM_CMD_PWM_STOP:
                        check_status(naibrd_TTL_StopPWM(cardIndex, module, chan));
                        naiif_printf("Mode reset to Input\r\n");
                        break;
                     case TTL_PWM_CMD_PWM_DEMO:
                     {
                        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 <= 24; ch_loop++)
                                 {
                                    time = ch_loop;
                                    status |= check_status(naibrd_TTL_SetPWM_Period(cardIndex, module, ch_loop, time));
                                    time /= 10.0;
                                    status |= check_status(naibrd_TTL_SetPWM_Pulsewidth(cardIndex, module, ch_loop, time));
                                    status |= check_status(naibrd_TTL_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 TTL_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 <= 24; ch_loop++)
                                 {
                                    status |= check_status(naibrd_TTL_SetOutputState(cardIndex, module, ch_loop, NAIBRD_TTL_STATE_LO));
                                    status |= check_status(naibrd_TTL_SetIOFormat(cardIndex, module, ch_loop, NAIBRD_TTL_IOFORMAT_INPUT));
                                    status |= check_status(naibrd_TTL_SetPWM_Pulsewidth(cardIndex, module, ch_loop, 0.01));
                                    status |= check_status(naibrd_TTL_SetPWM_BurstNum(cardIndex, module, ch_loop, 0));
                                    status |= check_status(naibrd_TTL_SetEnhancedMode(cardIndex, module, ch_loop, NAIBRD_TTL_MODE_STD_INPUT_OUTPUT));
                                    status |= check_status(naibrd_TTL_SetDebounceTime(cardIndex, module, ch_loop, 0.01));
                                    status |= check_status(naibrd_TTL_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 TTL_PWM_CMD_PWM_BURST:
                     {
                        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 <= 24; ch_loop++)
                                 {
                                    status |= check_status(naibrd_TTL_SetEnhancedMode(cardIndex, module, ch_loop, NAIBRD_TTL_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES));
                                    status |= check_status(naibrd_TTL_SetIOFormat(cardIndex, module, ch_loop, NAIBRD_TTL_IOFORMAT_OUTPUT));
                                 }
                                 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 TTL_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 <= 24; ch_loop++)
                                 {
                                    status |= check_status(naibrd_TTL_SetEnhancedMode(cardIndex, module, ch_loop, NAIBRD_TTL_MODE_OUTPUT_PWM_FOREVER));
                                    status |= check_status(naibrd_TTL_SetIOFormat(cardIndex, module, ch_loop, NAIBRD_TTL_IOFORMAT_OUTPUT));
                                 }
                                 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;
                     default:
                        naiif_printf("Invalid command entered\r\n");
                        break;
                     }
                  }
                  else
                     naiif_printf("Invalid command entered\r\n");
               }
            }
            else
               bContinue = NAI_FALSE;
         }
      }
      else
      {
         bContinue = NAI_FALSE;
         naiif_printf("PWM not supported on this module yet\r\n");
      }

    }
}
/**************************************************************************************************************/
/**
<summary>
Display_TTL_PWM_Configuration illustrate the methods to call in the naibrd library to retrieve the PWM
configuration settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_TTL_PWM_Configuration(int32_t paramCnt, int32_t* p_params)
{
   naibrd_ttl_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 ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->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_TTL_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_TTL_GetPWM_Period(cardIndex, module, chan, &period));
   naiif_printf("    %10.6f   ", period);

   check_status(naibrd_TTL_GetPWM_Pulsewidth(cardIndex, module, chan, &pulsewidth));
   naiif_printf("     %10.6f   ", pulsewidth);

   check_status(naibrd_TTL_GetPWM_BurstNum(cardIndex, module, chan, &burstnumber));
   naiif_printf("     0x%08X   ", burstnumber);

   status = check_status(naibrd_TTL_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_TTL_Status illustrate the methods to call in the naibrd library to retrieve the status settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_TTL_Status(int32_t paramCnt, int32_t* p_params)
{
   naibrd_ttl_ioformat_t IOformat;
   naibrd_ttl_state_t state;
   uint32_t ModuleID;
   nai_status_t retstatus = NAI_ERROR_NOT_SUPPORTED;
   nai_status_bit_t status = 0;
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   Verify_TTL_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(" -----------------TTL 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_TTL_GetIOFormat(cardIndex, module, chan, &IOformat));
   switch (IOformat)
   {
      case NAIBRD_TTL_IOFORMAT_INPUT:
         naiif_printf("  INPUT  ");
         break;
      case NAIBRD_TTL_IOFORMAT_OUTPUT:
         naiif_printf(" OUTPUT  ");
         break;
      case NAIBRD_TTL_IOFORMAT_INVALID:
      default:
         naiif_printf("  ERROR  ");
         break;
   }


   naiif_printf("        ");

   check_status(naibrd_TTL_GetOutputState(cardIndex, module, chan, &state));
   switch (state)
   {
      case NAIBRD_TTL_STATE_HI:
         naiif_printf("  HI  ");
         break;
      case NAIBRD_TTL_STATE_LO:
         naiif_printf("  LO  ");
         break;
      default:
         naiif_printf("  UNK ");
         break;
   }
   naiif_printf("         ");

   check_status(naibrd_TTL_GetInputState(cardIndex, module, chan, &state));
   switch (state)
   {
      case NAIBRD_TTL_STATE_HI:
         naiif_printf("  HI  ");
         break;
      case NAIBRD_TTL_STATE_LO:
         naiif_printf("  LO  ");
         break;
      default:
         naiif_printf("  UNK ");
         break;
   }
   naiif_printf("       ");

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_BIT_LATCHED, &status)); /*BIT latched*/
   naiif_printf("  %d   ", status);
   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_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_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, &status));
   naiif_printf("  %d   ", status);
   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_LO_HI_TRANS_REALTIME, &status));
   naiif_printf("  %d       ", status);
   naiif_printf("        ");

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED, &status));
   naiif_printf("  %d   ", status);
   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_HI_LO_TRANS_REALTIME, &status));
   naiif_printf("  %d       ", status);
   naiif_printf("        ");

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED, &status));
   naiif_printf("  %d   ", status);
   retstatus = check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_OVERCURRENT_REALTIME, &status));
   naiif_printf("  %d       ", status);

   naiif_printf("\r\n\r\n");

   return retstatus;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_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_TTL_PWM_Mode(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;


   bool_t bQuit = NAI_FALSE;
   Verify_TTL_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 TTL 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_TTL_SetEnhancedMode(cardIndex, module, chan, NAIBRD_TTL_MODE_OUTPUT_PWM_FOREVER));
         }
         else if ((toupper(inputBuffer[0]) == 'B'))
         {
            status = check_status(naibrd_TTL_SetEnhancedMode(cardIndex, module, chan, NAIBRD_TTL_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES));
         }
         else if ((toupper(inputBuffer[0]) == 'N'))
         {
            status = check_status(naibrd_TTL_SetEnhancedMode(cardIndex, module, chan, NAIBRD_TTL_MODE_STD_INPUT_OUTPUT));
         }
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_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_TTL_PWM_Polarity(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   bool_t bQuit = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_TTL_ParamCnt(paramCnt);
   naiif_printf("\r\n == PWM Output Polarity Selection == \r\n Pos  TTL PWM positive going pulse output \r\n Neg  TTL PWM negative going pulse output \r\n\r\n Type TTL 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_TTL_SetPWM_Polarity(cardIndex, module, chan, NAIBRD_TTL_PWMPOLARITY_POS));
         else if ((toupper(inputBuffer[0]) == 'N'))
            status = check_status(naibrd_TTL_SetPWM_Polarity(cardIndex, module, chan, NAIBRD_TTL_PWMPOLARITY_NEG));
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_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_TTL_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 ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_TTL_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_TTL_GetTimebaseLSB(ModuleID);
         min = (float64_t)(0x2u * lsb);
         max = (float64_t)(0xFFFFFFFF * lsb);

         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_TTL_SetPWM_Period(cardIndex, module, chan, time));
         }
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_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_TTL_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 ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_TTL_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_TTL_GetTimebaseLSB(ModuleID);

         min = (float64_t)(0x1u * lsb);
         max = (float64_t)(0xFFFFFFFE * lsb);

         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_TTL_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_TTL_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 ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_TTL_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);
         if (burstcount < 1)
         {
            burstcount = 1; /*minimum count is one*/
            naiif_printf("Setting burstcount to minimum of 1.\r\n");
         }
         status = check_status(naibrd_TTL_SetPWM_BurstNum(cardIndex, module, chan, burstcount));

      }
   }
   return status;
}

Help Bot

X