![]() |
Demo program for Encoder 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 | EncoderUsage () |
int | main (int argc, char *argv[]) |
Variables | |
double | starting_angle =0 |
Starting angle of the Encoder IP Core Channel rotation. It takes values 0 - rotation in degrees and defaults to 0 degree. | |
int | rotation =360 |
Rotation of the Encoder IP Core Channel. It takes values 360/720 degrees and defaults to 360 degree. | |
uint | manual_mode =0 |
Manual mode enable/disable variable. It takes values 0 or 1 and defaults to 0. | |
double | z_start_angle =1 |
This is the starting angle for the z pulse’s rising edge in degrees. It takes values 0 - rotation in degrees and defaults to 1 degree. | |
double | z_pulse_width =15 |
This is the width of the z-pulse in degrees. It takes values 0 - rotation in degrees and defaults to 15 degree. | |
uint | enable =1 |
enable mode bit for the Encoder 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 Encoder 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 | |
uint | active_high =1 |
Active High for the Encoder IP Core Channel. This represents active high for all four ab and zpulse. You can have separate variables too. It takes values 0 or 1 and defaults to 1. | |
uint | num_of_revolutions =0 |
Number of revolutions for the manual mode operation. This specifies the number of full rotation of the Encoder IP Core Channel. It defaults to 0. | |
double | stop_angle =0 |
Stop/Remainder angle for the manual mode operation. It takes values 0 to rotation in degrees and defaults to 0 degree. | |
double | rpm =0 |
RPM for the Encoder IP Core Channel. Positive value for forward rotation and negative value for reverse rotation. | |
fpgawb_ipcore_encoder_tooth_profile_configure_t | config |
fpgawb_ipcore_encoder_tooth_profile_configure_t struct passed as argument for setting the tooth profile. Check fpgawb_lib.h or api call documentation for more information | |
fpgawb_ipcore_encoder_active_high_configure_t | active_high_config |
fpgawb_ipcore_encoder_active_high_configure_t struct passed as argument for setting active high for the ab and zpulse. Check fpgawb_lib.h or api call documentation for more information | |
fpgawb_ipcore_encoder_modes_configure_t | modes_config |
fpgawb_ipcore_encoder_modes_configure_t struct passed as argument configuring modes for the Encoder IP Core Channel. Check fpgawb_lib.h or api call documentation for more information | |
double | angle |
Current angle of the Encoder IP Core Channel is stored in this variable after execution of get angle api call. | |
uint | config_mode =0 |
Configuration mode for the test program. Indicates to run the program in configure mode or set RPM on fly and read current crank angle on fly. It takes values 0-Configuration mode/1-set RPM and read current crank angle on fly. It defaults to 0. | |
int | channel =-1 |
Channel number for the Encoder IP Core Channel. It takes values 0 to (number of IP Core channels-1) and defaults to -1 (test program executed for all channels) | |
fpgawb_ipcore_t | ip_core |
fpgawb_ipcore_t struct which stores useful information about the IP Core after get IP Info api call. Check fpgawb_lib.h or api call documentation for more information | |
uint | num_of_teeths =36 |
num_of_teeths specifies the size of A rising edges. It defaults to 36 | |
void EncoderUsage | ( | ) |
Usage:
./fpgawb_ipcore_encoder [-a ActiveHigh] [-A Activate] [-b Board] [-c ChannelNumber] [-C config_mode] [-e Enable] [-i rpm/increment] [-l RolloverMode] [-m ManualMode] [-n NumberOfTeeths] [-o Rotation] [-s StartingAngle] [-S StopAngle] [-v NumberOfRevolutions]
Options | Default value |
---|---|
-a Active High (0/1) | 1 |
-A Activate (0/1) | 0 |
-b Board Number | 0 |
-c Channel Number (0- (NumChans-1)) | -1 |
-C Config Mode (0-Configuration mode/1-set RPM on fly and read current crank angle) | 0 |
-e Enable (0/1) | 1 |
-i RPM | 0 |
-l Rollover mode (15,30,45,60,90,180,270,360 in degrees | 15 |
-m Manual mode (0/1) | 0 |
-n Number of teeths – size of A rising edges. | 36 |
-o Rotation (360 or 720 degrees) | 360 |
-s Starting Angle (0 degrees - <rotation> degrees) | 0 |
-S Stop/Remainder Angle for manual mode (0 degrees - <rotation> degrees) | 0 |
-v Number of Revolutions for manual mode | 0 |
-z Position to start Z pulse (0 degrees - <rotation> degrees) | 1 |
-Z Width of Z Pulse (0 degrees - <rotation> degrees) | 15 |
Examples:
./fpgawb_ipcore_encoder
./fpgawb_ipcore_encoder -C1 -i100 > readdata
int main | ( | int | argc, |
char * | argv[] | ||
) |
Step 1: OPEN DEVICE
ccurPMFC_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
ccurPMFC_Get_Driver_Info(handle, &binfo)
This call returns useful driver information and saves in the ccurpmfc_driver_info_t structure for later use.
Step 3: GET LIBRARY INFO
ccurPMFC_Get_Library_Info(handle, &linfo)
This call returns useful library information and saves in the ccurpmfc_library_info_t structure for later use.
Step 4: ACTIVATE DAC
ccurPMFC_DAC_Activate(handle, CCURPMFC_DAC_ALL_ENABLE, NULL)
This call activates DAC. The test program should do DAC activation/configuration using ccurpmfc provided api calls.
Step 5: GET IP INFO
fpgawb_Encoder_Get_Ip_Info(handle, &ip_core)
This call returns useful IP Core information and saves in the fpgawb_ipcore_t structure for later use
Step 6: ACTIVATE ENCODER
fpgawb_Encoder_Activate_Ch(handle,Chan,enable,activate)
This call activates the Encoder IP Core Channel. Note to set activate to 0 because we will be using the Config api calls which requires that 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 7: SET ENCODER TOOTH PROFILE
C_fpgawb_Encoder_Set_Ch_Tooth_Profile(handle,Chan,&config)
This call sets the Tooth Profile and initial conditions for Encoder IP Core Channel. It configures the tooth profile, rotation, starting angle of encoder, starting angle of z-pulse and width of z-pulse.
Step 8: CONFIGURES MODES
C_fpgawb_Encoder_Configure_Ch_Modes(handle,Chan,&modes_config) This call sets the modes such as maual mode, rollover mode using the modes_config for the Encoder IP Core Channel.
Step 9: CONFIGURE MANUAL MODE
C_fpgawb_Encoder_Configure_Ch_Manual_Mode(handle,Chan,num_of_revolutions,stop_angle)
This call configure Encoder IP Core Channel parameters like num_of_revolutions and stop_angle to run in manual mode.
Step 10: SET ACTIVE HIGH
fpgawb_Encoder_Set_Ch_Active_High(handle,Chan,&active_high_config)
This call configures the active high for the AB and ZPulse for Encoder IP Core Channel.
Step 11: ACTIVATE ENCODER
fpgawb_Encoder_Activate_Ch(handle,Chan,enable,1)
This call activates the Encoder 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 12: SET ENCODER RPM
fpgawb_Encoder_Set_Ch_RPM(handle,Chan,rpm)
This call sets the RPM for the Encoder IP Core Channel for it to run.
Step 13: GET CURRENT ANGLE
fpgawb_Encoder_Get_Ch_Angle(handle,Chan,&angle)
This call returns the current angle of the Encoder IP Core Channel in angle pointer. This can be written to a file and plotted to view it better.
Step 14: CLOSE DEVICE
ccurPMFC_Close(handle)
Closes the device with the handle