Hardware Utilities API
The Hardware Utilities API encompasses the needed software to control and
monitor certain functionalities on the ARCS motion control board which
are needed for realtime control, such as interrupt initialization and
handling.
Example Use
In the following example, an Interrupt Service Routine is created,
which computes the control signal per sampling interval.
- float testValue0 = 0.0;
- float pi = 3.1415926;
- float Nperiod = 1000.0;
- float A = 1.0;
- float k = 0.0;
- float DT0 = 0.001;
- float DT1 = 0.01;
- float execTime;
- int flag = 0;
- /* main program for control applications */
- #pragma INTERRUPT (timer0)
- void timer0 ()
- {
- volatile unsigned int i;
- startIsrExecTime (0);
-
- if (flag)
-
- setDioWord (0, 0xaaaa);
- else
-
- setDioWord (0, 0x5555);
-
- flag = flag == 0 ? 1 : 0;
- if (k>Nperiod)
-
- k=0.0;
- testValue0 = A* sin((2.0*pi*k)/Nperiod);
- k = k+1.0;
- setActuator ( 0, testValue0 ));
- k = k+1.0;
- setActuator ( 0, testValue0 );
execTime = finishIsrExecTime (0);
- }
- #pragma INTERRUPT (timer1)
- void timer1 ()
- {
- volatile unsigned int i;
- startIsrExecTime (0);
-
- if (flag)
-
- setDioWord (1, 0xaaaa);
- else
-
- setDioWord (1, 0x5555);
-
- flag = flag == 0 ? 1 : 0;
- execTime = finishIsrExecTime (0);
- }
-
-
- main()
- {
- unsigned int ii;
- unsigned int numDacChannels;
- unsigned int numDioChannels = 2;
- dspInit (8, 8, 2, 0, 0, 2);
- numDacChannels = getNumDacs();
- for (ls = getNumDacs();
- for (ii=0;ii<numDacChannels;ii++)
-
- {
- initDac (ii, 1, 0, 12, 10.0);
- initAct (ii,-10.0,-10.0,10.0,10.0);
- }
- setDioWordConfig (0,0xffff);
- setDioWordConfig (1,0xffff);
- initIsr (0, ISR_TIMER0, &timer0, NO_ISR, 0x0000);
- initIsr (1, ISR_TIMER1, &timer1, NO_ISR, 0x0000);
- setSamplingPeriod( 0, DT0);
- enableIsr (0);
- setSamplingPeriod( 1, DT1);
- enableIsr (1);
- while(1)
-
-
communications();
- }

-
hdwInit()
-
clearErrors()
-
checkError()
-
setNumIsrs ()
-
getNumIsrs ()
-
initIsr()
-
initTimerIsr()
initTimerIsr()
-
enableIsr()
-
disableIsr()
-
startIsrExecTime()
-
finishIsrExecTime()
-
setSamplingPeriod()
-
getSamplingPeriod()
-
checkOverTime()

hdwInit
void hdwInit( unsigned int numOfEncoders, unsigned int numOfDACs,
unsigned int numOfDIOs, unsigned int numOfADCs, unsigned int
numOfPWMs, unsigned int numOfSTEPPERs, unsigned int numOfISRs
);
- Initializes the hardware configuration.
Parameters:
-
numOfEncoders: number of encoder channels
-
numOfDACs: number of actuator (D/A) channelsumber of actuator (D/A) channels
-
numOfDIOs: number of dscrete (digital) inputs/outputs
-
numOfADCs: number of analog sensor (A/D) channels
-
numOfPWMs: number of pulse width modulated outputs
-
numOfSTEPPERs: number of stepper motor channels
-
numOfISRs: number of Interrupt Service Routines; currently the ARCS system
supports only two hardware interrupts, 0 and 1.
clearErrors
void clearErrors();
- Clears all errors.
checkError
unsigned int checkError();
-
Returns
- the integer value associated with the error.
setNumIsrs
void setNumIsrs (unsigned int noChannels);
- Sets the number of interrupts.
Parameters:
- noChannels: sets number of interrupts- currently only 2 are supported.
getNumIsrs
unsigned int getNumIsrs ();
-
- Returns
- The total number of Interrupt Service Routines
initIsr
void initIsr(unsigned int isrChannel, unsigned int isrLevel, void
(*isrHander)(), unsigned int trapLevel, void (*trapHander)());
-
Initializes the interrupt
handlers, generally to perform specific realtime calculations.
Parameters
-
isrChannel: interrupt number, 0 or 1.
-
isrLevel: Interrupt level; ISR_TIMER0 or ISR_TIMER1. ISR_TIMER0 has higher
priority.
-
*isrHandler: pointer to interrupt routine function, e.g. to controlLoop()
in example.
-
trapLevel:
-
*trapHandler: pointer to routine for handling errors.
initTimerIsr
void initTimerIsr(unsigned int isrChannel, unsigned int isrLevel, void
(*isrCalledFunc)(), unsigned int trapLevel, void (*trapHander)());
- Initializes timer based ISR
enableIsr
void enableIsr(unsigned int Channel);
- Enables interrupts.
Parameters
Channel: interrupt number (0 or 1 in current hardware configuration).
disableIsr
void disableIsr(unsigned int Channel);
- Disables interrupts.
Parameters
ables interrupts.
Parameters
- Channel: interrupt number
startIsrExec
void startIsrExecTime(unsigned int isrChannel);
- Starts the clock to time
to determine the total time taken for the execution of then of the interrupt service
routine.
Parameters:
- isrChannel: interrupt number
finishIsrExecTime
float finishIsrExecTime(unsigned int isrChannel);
- Determines the time taken
for the end of the interrupt service routine.
Parameters
- isrChannel: interrupt number (0 or 1).
- Returns
-
Total time for executio of the interrupt service routine.
setSamplingPeriod
void setSamplingPeriod(unsigned int isrChannel, float T);
- Sets the sampling period
for the specific interrupt.
Parameters
- isrChannel: interrupt service number (0 or 1).
- T: sampling period in seconds.
getSamplingPeriod
float getSamplingPeriod(unsigned int isrChannel);
- Provides
the sampling period for the specific interrupt routine.
Parameters
-
isrChannel: interrupt number
-
Returns
-
sampling interval for the specific interrupt number.
checkOverTime
unsignerTime">
checkOverTime
unsigned int checkOverTime();
-
Check if any of the ISR over time flags has been set.
Return
-
0: No over time
-
1: Over time flag has been set
Last modified: Mon Feb 15 00:02:37 Eastern Standard
Time 1999