![]() |
Demo program for PID Controller IP Core.
The Usage() function shows how to execute the test program, options available and default values set for different configuration variables. The Variables section specifies variables used in the test program, what they specify, the values it holds and can take. The main() function specifies sequence of api calls executed and tested.
Functions | |
void | PIDUsage () |
int | main (int argc, char *argv[]) |
Variables | |
uint | enable =1 |
enable mode bit for the PID IP Core Channel. Toggling the enable signal will cause the registers to revert to default power-on states. It takes values 0 or 1 and defaults to 1 | |
uint | activate =0 |
output enable for the PID IP Core Channel. Enable this after configuring the registers associated with api calls starting with C. It takes values 0 or 1 and defaults to 0 | |
fpgawb_ipcore_t | ip_core |
fpgawb_ipcore_t struct which stores useful information about the IP Core after executing get IP Info api call. Check fpgawb_lib.h or api call documentation for more information | |
int | channel =-1 |
Channel number for the PID IP Core Channel. It takes values 0 to (number of IP Core channels-1) and defaults to -1 (test program executed for all channels) | |
double | timer_us =5 |
timer_us is the number of microseconds before the PID Controller updates. It takes a double floating point value but is converted to the number of cycles with the IP Core Channel operating at 200 MHz. The number of cycles must be a nonzero unsigned integer. | |
fpgawb_ipcore_pid_controller_timer_t | pid_timer |
fpgawb_ipcore_pid_controller_timer_t struct passed as argument for the set timer count api call. Check fpgawb_lib.h or api call documentation for more information | |
double | target = 0 |
Target is the desired value and takes a signed 16-bit integer. | |
fpgawb_ipcore_pid_controller_target_t | pid_target |
fpgawb_ipcore_pid_controller_target_t struct passed as argument for the set target api call. Check fpgawb_lib.h or api call documentation for more information | |
float | proportional = 0 |
Proportional is the tuning constant for the proportional action and takes a single floating point value. | |
float | integral = 0 |
Integral is the tuning constant for the integral action and takes a single floating point value. | |
float | derivative = 0 |
Derivative is the tuning constant for the derivative action and takes a single gloating point value. | |
fpgawb_ipcore_pid_controller_coeff_t | pid_coeff |
fpgawb_ipcore_pid_controller_coeff_t struct passed as argument for the set coefficients api call. Check fpgawb_lib.h or api call documentation for more information | |
int main | ( | int | argc, |
char * | argv[] | ||
) |
Step 1: OPEN DEVICE
ccrtNGFC_Open(&handle,board_no,oflags)
Before using any API calls, the user needs to open the device and get a handle. This handle is then used as the first argument in most of the following APIs.
Step 2: GET DRIVER INFO
ccrtNGFC_Get_Driver_Info(handle, &binfo)
This call returns useful driver information and saves in the ccrtngfc_driver_info_t structure for later use.
Step 3: GET LIBRARY INFO
ccrtNGFC_Get_Library_Info(handle, &linfo)
This call returns useful library information and saves in the ccrtngfc_library_info_t structure for later use.
Step 5: ACTIVATE PID_CONTROLLER CHANNEL
fpgawb_PID_Activate_Ch(handle,chan,enable,activate)
This call activates the PID IP Core Channel by setting enable to 1. Note to set activate to 0 because we will be using the Config api calls which requires activate be 0. The default for activate is 0 in this test program. It is set to 1 at the end. Please be careful to give in the value as 0 when running the test program.
Step 6: SET TARGET
fpgawb_PID_Set_Ch_Target(handle, chan, &pid_target)
This call programs the mode for the PID IP Core channel.
Step 7: SET COEFFICIENTS
fpgawb_PID_Set_Ch_Proportional(handle, chan, &pid_coeff)
fpgawb_PID_Set_Ch_Integral(handle, chan, &pid_coeff)
fpgawb_PID_Set_Ch_Derivative(handle, chan, &pid_coeff)
This call programs the mode for the PID IP Core channel.
Step 8: SET TIMER PERIOD
fpgawb_PID_Set_Ch_Timer_Count(handle,chan,fpgawb_ipcore_pid_controller_timer_t)
This call programs the number of cycles (200MHz) before the PID Controller updates
Step 9: ACTIVATE PID_CONTROLLER CHANNEL
fpgawb_PID_Activate_Ch(handle,chan,1,1)
This call activates the PID IP core channel for Running after the configuration phase. Note that you put the activate to 0 before configuration so make it 1 now.
Step 10: CLOSE DEVICE
ccrtNGFC_Close(handle)
Closes the device with the handle.
void PIDUsage | ( | ) |
Usage:
./fpgawb_ipcore_pid_controller [-A Activate] [-b BoardNumber] [-c channelNumber] [-C ConfigMode] [-d Derivative] [-e Enable] [-i Integral] [-p Proportional] [-t Target] [-T Timer]
Options | Default value |
---|---|
-A Activate (0/1) | 0 |
-b Board Number | 0 |
-c channel Number (0-(Numchans-1) | -1 (all channels) |
-C Config (0/1) | 0 |
-d Derivative (Float) | 0 |
-e Enable (0/1) | 1 |
-i Integral (Float) | 0 |
-p Proportional (Float) | 0 |
-t Target (-1:1-2^(-15)) | 0 |
-T Timer (us) | 5 |
Examples:
SETUP: ./fpgawb_ipcore_pid_controller -C 0 -t 0.2 -T 5.5 -p 0.001 -i 0.0001 -d 0.001
RUNTIME: ./fpgawb_ipcore_pid_controller -C 1 -t 0 -p 0.0001 -i 0.0003 -d 0.001