Logo
NGFC_KnockSensor_Demo

Demo program for Knock Sensor 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 KnockSensorUsage ()
 
int main (int argc, char *argv[])
 
void Display_channels ()
 

Variables

uint enable =1
 enable mode bit for the Knock Sensor 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 Knock Sensor 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
 
int channel =-1
 channel number for the Knock Sensor 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
 
fpgawb_ipcore_knock_sensor_info_t all_info [FPGAWB_MAX_IPCORE_CHANNELS]
 fpgawb_ipcore_knock_sensor_info_t struct to read channel data for the Knock Sensor IP Core Channel. Check fpgawb_lib.h or api call documentation for more information on the struct members
 
fpgawb_ipcore_knock_sensor_configure_t config
 fpgawb_ipcore_knock_sensor_configure_t struct used to pass config parameters for the Knock Sensor IP Core Channel. Check fpgawb_lib.h or api call documentation for more information on the struct members
 
double start_angle =0
 The knock signal is synchronized with the crank angle that the engine generates. This value causes the shift on the knock signal where the knock is delayed by the number of degrees specified. It takes values 0 to 720 in degrees and defaults to 0.
 
double dc_offset =0
 This value is added to the knock signal to cause a positive or negative voltage offset. It takes input in volts and defaults to 0. i The value should be less than (max allowed voltage - max voltage in knock file). The max allowed voltage can be determined from your DAC Configuration.
 
int gain =-1
 It is used to reduce the knock signal. The user will enter values 0 to 5 which means 0-No amplification or reduction, 1-Divide by 2, 2-Divide by 4, 3-Divide by 8, 4-Divide by 16, 5-Divide by 32. It defaults to -1 which means user does not want to over write the gain calculated from the knock file in the configuration mode.
 
uint config_mode =0
 Configuration mode for the test program which indicates to run the program in static configure mode or dynamic read/write mode. It defaults to 0. 0-Config static parameters for the IP/ 1-Dynamically changing gain, dc offset and reading crank angle and knock out.
 
char file_name [300]
 Input knock file which contains two columns separated by comma. First column is the angle step and it should be atleast 0.05 degrees. Second column is the voltage in volts. The file can contain a maximum of 16385 values.
 

Function Documentation

void Display_channels ( )

Step 10: READ KNOCK SENSOR CHANNEL DATA
fpgawb_Decoder_Knock_Sensor_Ch_Data(handle, Chan, &all_info[Chan])
This call returns the Knock_Sensor IP Core Channel data such as knock out and crank angle in &all_info struct.

void KnockSensorUsage ( )

Usage:
./fpgawb_ipcore_knock_sensor [-A Activate] [-b Board] [-c ChannelNumber] [-C ConfigMode] [-d DCOffset] [-e Enable] [-g Gain][-i InputDataFile] [-s StartingAngle]

Options Default value
-A Activate (0/1) 0
-b Board Number 0
-c channel Number (0- (NumChans-1)) -1
-C Config Mode [0-Config static parameters for the IP/ 1-Dynamically changing gain, dc offset and reading crank angle and knock out] 0
-d DC Offset in volts. dc offset < (max voltage allowed - max voltage in knock file) 0 volts
-e Enable (0/1) 1
-g Gain [0-No amplification or reduction, 1-Divide by 2, 2-Divide by 4, 3-Divide by 8, 4-Divide by 16, 5-Divide by 32] -1
-i Input Data File - The file contains 2 columns; col 0 is step and col 2 is voltage. It can have a max of 16385 values null
-s Start angle of Knock Signal (0 degrees - 720 degrees) 0 degree


Examples:
./fpgawb_ipcore_knock_sensor -iangles/f1.knock
./fpgawb_ipcore_knock_sensor -iangles/f1.knock -s15
./fpgawb_ipcore_knock_sensor -C1 -g1 -d1

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 4: GET IP INFO
fpgawb_Knock_Sensor_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 5: ACTIVATE KNOCK SENSOR
fpgawb_Knock_Sensor_Activate_Ch(handle,Chan,enable,activate)
This call activates the Knock Sensor 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 6: CONFIGURES KNOCK SENSOR STATIC PARAMETERS AND INITIAL CONDITIONS
C_fpgawb_Knock_Sensor_Configure_Ch(handle,Chan,&config) This call programs the input voltages, angle increment, gain, starting angle and RAM last address for the Knock Sensor IP Core Channel.

Step 7: ACTIVATE KNOCK SENSOR
fpgawb_Knock_Sensor_Activate_Ch(handle,Chan,enable,1)
This call activates the Knock Sensor 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 8: SET GAIN
fpgawb_Knock_Sensor_Set_Ch_Gain(handle,Chan,gain) This call programs the gain which is used to reduce the knock signal of the Knock Sensor IP Core Channel.

Step 9: SET DC OFFSET
fpgawb_Knock_Sensor_Set_Ch_DC_Offset(handle,Chan,dc_offset) This call programs the DC Offset added to the knock signal causing a positive or negative voltage offset.

Step 11: CLOSE DEVICE
ccrtNGFC_Close(handle)
Closes the device with the handle