Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a -rd9b5f588d81e15ed3849222bed3362e15dbf4b0a --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision d9b5f588d81e15ed3849222bed3362e15dbf4b0a) @@ -45,13 +45,11 @@ #define MAX_FPGA_COMM_FAILURES 3 ///< FPGA maximum comm failures per MAX_FPGA_COMM_FAILURES_WINDOW_MS #define MIN_POWER_ON_TIME_FOR_COMM_FAILS ( 1 * MS_PER_SECOND ) ///< Allow FPGA comm errors for first second after power-up -#define FPGA_PINCH_VALVES_STOPPED 0x00 ///< FPGA pinch valve control register setting to stop valve motors. -#define FPGA_VBV_CLOSED_LOOP 0x01 ///< Bit mask for running VBV motor in closed loop mode. -#define FPGA_VBA_CLOSED_LOOP 0x02 ///< Bit mask for running VBA motor in closed loop mode. -#define FPGA_VBV_OPEN_LOOP 0x04 ///< Bit mask for running VBV motor in open loop mode. -#define FPGA_VBA_OPEN_LOOP 0x80 ///< Bit mask for running VBA motor in open loop mode. +#define FPGA_BP_ENABLE_BIT_MASK 0x01 ///< Bit mask for enabling the blood pump. +#define FPGA_BP_DIRECTION_FWD_BIT_MASK 0x02 ///< Bit mask for setting the blood pump direction. +#define FPGA_BP_HOME_BIT_MASK 0x04 ///< Bit mask for requesting a blood pump home operation. -//#define FPGA_VALVES_MIN_PWM_MODE_COUNT 2500 ///< FPGA valves minimum PWM in PWM mode in counts. +#define FPGA_VBT_OPEN_BIT_MASK 0x01 ///< Bit mask for setting VBT valve position to open. #define FPGA_INPUT_VOLTAGE_SCALE 3.0F ///< FPGA source and aux voltage. #define FPGA_PVN_VOLTAGE_SCALE 1.0F ///< FPGA pvn voltage. @@ -70,10 +68,6 @@ #define FPGA_ADV_BUBBLE_STATUS_MASK 0x0002 ///< Bit mask for venous air bubble detector input status. #define FPGA_ADV_BUBBLE_SELF_TEST_CMD 0x08 ///< Bit for venous air bubble detector self-test command. -#define FPGA_PBO_TEMP_DIVISOR 2047.0F ///< Used in conversion of PBo temperature reading to deg C. -#define FPGA_PBO_TEMP_GAIN 200.0F ///< Used in conversion of PBo temperature reading to deg C. -#define FPGA_PBO_TEMP_OFFSET 50.0F ///< Used in conversion of PBo temperature reading to deg C. - // FPGA Sensors Record #pragma pack(push,1) @@ -96,25 +90,29 @@ U08 reserved1; ///< Reg 261. Reserved and available for future use. U16 sPumpDACSet; ///< Reg 262. Syringe pump DAC setting. U16 sPumpDACEEProm; ///< Reg 264. Syringe pump DAC EEProm data. - S32 PBoPressure; ///< Reg 266. PBo raw pressure data. - S32 PBoTemperature; ///< Reg 270. PBo raw temperature data. - U08 PBoReadCount; ///< Reg 274. PBo read count. - U08 PBoErrorCount; ///< Reg 275. PBo error count. - S32 PBAPressure; ///< Reg 276. PBA raw pressure data. - S32 PBATemperature; ///< Reg 280. PBA raw temperature data. - U08 PBAReadCount; ///< Reg 284. PBA read count. - U08 PBAErrorCount; ///< Reg 285. PBA error count. - S16 ATAPSpeed; ///< Reg 286. ATAP speed. + U16 PBoPressure; ///< Reg 266. PBo raw pressure data. + S16 PBoTemperature; ///< Reg 268. PBo raw temperature data. + U08 PBoReadCount; ///< Reg 270. PBo read count. + U08 PBoErrorCount; ///< Reg 271. PBo error count. + U32 reserved3; ///< Reg 272. Reserved and available for future use. + U16 PBAPressure; ///< Reg 276. PBA raw pressure data. + S16 PBATemperature; ///< Reg 278. PBA raw temperature data. + U08 PBAReadCount; ///< Reg 280. PBA read count. + U08 PBAErrorCount; ///< Reg 281. PBA error count. + S16 VBACmdPosition; ///< Reg 282. VBA commanded position (200 steps/rev). + S16 VBAEncPosition; ///< Reg 284. VBA encoder position (1024 counts/rev). + U08 VBAStatus; ///< Reg 286. VBA status. + U08 reserved4; ///< Reg 287. Reserved and available for future use. U08 BEMStatus; ///< Reg 288. BEM status. U08 BEMEncStatus; ///< Reg 289. BEM encoder status. S32 BEMEncPosition; ///< Reg 290. BEM encoder position. - S16 BPSpeed; ///< Reg 294. BP measured speed. + S16 BPSpeed; ///< Reg 294. BP measured speed (RPM). S16 BPTorque; ///< Reg 296. BP measured torque. S16 BPSpeedFromHall; ///< Reg 298. BP measured speed from hall sensor(s). - S16 VBVPosition; ///< Reg 300. VBV encoder position. - U08 VBVStatus; ///< Reg 302. VBV status register. - U08 VBAStatus; ///< Reg 303. VBA status register. - S16 VBAPosition; ///< Reg 304. VBA encoder position. + S16 VBVCmdPosition; ///< Reg 300. VBV commanded position (200 steps/rev). + S16 VBVEncPosition; ///< Reg 302. VBV encoder position (1024 counts/rev). + U08 VBVStatus; ///< Reg 304. VBV status. + U08 BPStatus; ///< Reg 305. BP status. U16 GPIOReg; ///< Reg 306. GPIO register. U08 HEPStatus; ///< Reg 308. HEP status register. U08 HEPAdcReadCount; ///< Reg 309. HEP ADC read counter. @@ -132,6 +130,12 @@ U16 fpgaCompatibilityRev; ///< Reg 332. Compatibility revision. U08 VBTStatus; ///< Reg 334. VBT status register. U08 VBTStatusPWM; ///< Reg 335. VBT PWM status register. + S16 ACPower1Current; ///< Reg 336. AC power current - 1. + S16 ACPower1Voltage; ///< Reg 338. AC power voltage - 1. + S16 ACPower2Current; ///< Reg 340. AC power current - 2. + S16 ACPower2Voltage; ///< Reg 342. AC power voltage - 2. + S16 ACPower3Current; ///< Reg 344. AC power current - 3. + S16 ACPower3Voltage; ///< Reg 346. AC power voltage - 3. } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -145,21 +149,23 @@ U16 VBTPWMLowPeriod; ///< Reg 10. VBT PWM low signal period register. U16 VBTPWMPeriod; ///< Reg 12. VBT PWM period register. U16 VBTPWMPUllInTime; ///< Reg 14. VBT PWM pull in time register. - U16 ATAPSetSpeed; ///< Reg 16. Air pump speed set register. + U16 ACHeaterPWM; ///< Reg 16. AC heater PWM duty cycle set register. U08 ATAPControl; ///< Reg 18. Air pump control register. U08 BEMControl; ///< Reg 19. Blood ejector stepper motor control register. U16 BEMSetSpeed; ///< Reg 20. Blood ejector stepper motor step register. - U16 BPSetSpeed; ///< Reg 22. Blood pump speed set register. + U16 BPSetSpeed; ///< Reg 22. Blood pump speed set register (RPM). U08 BPControl; ///< Reg 24. Blood pump control register. - U08 pinchValveControl; ///< Reg 25. Pinch valve control register (VBA and VBV). - S16 VBVPosition; ///< Reg 26. VBV position set register. - S16 VBAPosition; ///< Reg 28. VBA position set register. - U16 VBVStepSpeed; ///< Reg 30. VBV step speed set register. - U16 VBAStepSpeed; ///< Reg 32. VBA step speed set register. - U08 alarmControl; ///< Reg 34. Alarm audio register. - U08 reserved3; ///< Reg 35. Reserved. - U32 reserved4; ///< Reg 36. Reserved. - U32 reserved5; ///< Reg 40. Reserved. + U08 VBVControl; ///< Reg 25. VBV control register. + U16 VBVPosition; ///< Reg 26. VBV position set register (200 steps/rev). + U16 VBAPosition; ///< Reg 28. VBA position set register (200 steps/rev). + U16 VBAControl; ///< Reg 30. VBA control register. + U08 reserved3; ///< Reg 31. Reserved. + U16 reserved4; ///< Reg 32. Reserved. + U08 alarmControl; ///< Reg 34. Alarm audio control register. + U08 reserved5; ///< Reg 35. Reserved. + U32 reserved6; ///< Reg 36. Reserved. + U16 reserved7; ///< Reg 40. Reserved. + U16 reserved8; ///< Reg 42. Reserved. U08 sensorTest; ///< Reg 44. Sensor self-test control register. } FPGA_ACTUATORS_T; @@ -196,9 +202,9 @@ memset( &fpgaActuatorSetPoints, 0, sizeof(FPGA_ACTUATORS_T) ); fpgaActuatorSetPoints.alarmControl = (U08)MIN_ALARM_VOLUME_ATTENUATION << 2; // Start alarm audio volume at maximum - // Set VBA and VBV to be "stopped". - // the valves will not move to 0 position - fpgaActuatorSetPoints.pinchValveControl = FPGA_PINCH_VALVES_STOPPED; + // Set VBA and VBV to default configuration + disabled so they do not run immediately on power up + fpgaActuatorSetPoints.VBAControl = FPGA_PINCH_VALVES_1_32_STEP | FPGA_PINCH_VALVES_DISABLE | FPGA_PINCH_VALVES_NOT_RESET | FPGA_PINCH_VALVES_NOT_SLEEP; + fpgaActuatorSetPoints.VBVControl = FPGA_PINCH_VALVES_1_32_STEP | FPGA_PINCH_VALVES_DISABLE | FPGA_PINCH_VALVES_NOT_RESET | FPGA_PINCH_VALVES_NOT_SLEEP; // initialize FPGA comm failures windowed timer count initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES_WINDOW_MS); @@ -407,7 +413,106 @@ /*********************************************************************//** * @brief - * The getFPGABloodPumpHallSensorCount function gets the latest blood pump + * The setBloodPumpEnabled function enables or disables the blood pump per + * the given flag. + * @details \b Inputs: none + * @details \b Outputs: Blood pump enabled or disabled (bit 0 of BP control register) + * @param enable TRUE if BP enable is requested, FALSE if BP disable is requested + * @return none + *************************************************************************/ +void setBloodPumpEnabled( BOOL enable ) +{ + if ( TRUE == enable ) + { + fpgaActuatorSetPoints.BPControl |= FPGA_BP_ENABLE_BIT_MASK; + } + else + { + fpgaActuatorSetPoints.BPControl &= ~((U08)FPGA_BP_ENABLE_BIT_MASK); + } +} + +/*********************************************************************//** + * @brief + * The setBloodPumpDirection function sets the direction for the blood pump + * motor to the given direction. + * @details \b Inputs: none + * @details \b Outputs: Blood pump motor direction is set (bit 1 of BP control register). + * 0 - CW (forward) + * 1 - CCW (reverse) + * @param dir the desired direction for the blood pump motor (fwd or rev) + * @return none + *************************************************************************/ +void setBloodPumpDirection( MOTOR_DIR_T dir ) +{ + if ( MOTOR_DIR_REVERSE == dir ) + { + fpgaActuatorSetPoints.BPControl &= ~((U08)FPGA_BP_DIRECTION_FWD_BIT_MASK); + } + else + { + fpgaActuatorSetPoints.BPControl |= FPGA_BP_DIRECTION_FWD_BIT_MASK; + } +} + +/*********************************************************************//** + * @brief + * The homeBloodPump function sets the bit requesting that the blood pump + * be homed. + * @details \b Inputs: none + * @details \b Outputs: BP home request is set (bit 2 of BP control register). + * @return none + *************************************************************************/ +void homeBloodPump( void ) +{ + fpgaActuatorSetPoints.BPControl |= FPGA_BP_HOME_BIT_MASK; +} + +/*********************************************************************//** + * @brief + * The resetBloodPumpHomeRequest function resets the fpga blood pump home + * request. + * @note This function should be called after request is made and transmission + * to FPGA is complete. + * @details \b Inputs: none + * @details \b Outputs: BP home request is cleared (bit 2 of BP control register) + * @return none + *************************************************************************/ +void resetBloodPumpHomeRequest( void ) +{ + fpgaActuatorSetPoints.BPControl &= ~((U08)FPGA_BP_HOME_BIT_MASK); +} + +/*********************************************************************//** + * @brief + * The setBloodPumpSetSpeed function sets the fpga blood pump set speed + * to the given speed (0..3000 RPM). + * @details \b Inputs: none + * @details \b Outputs: BP set speed is set + * @param rpm the set point for the BP speed (in RPM). + * @return none + *************************************************************************/ +void setBloodPumpSetSpeed( U16 rpm ) +{ + fpgaActuatorSetPoints.BPSetSpeed = rpm; +} + +/*********************************************************************//** + * @brief + * The getBloodPumpSpeed function gets the latest blood pump speed (in RPM) + * from the FPGA. + * @details \b Inputs: fpgaSensorReadings + * @details \b Outputs: none + * @return Latest blood pump speed. + *************************************************************************/ +U16 getBloodPumpSpeed( void ) +{ + return fpgaSensorReadings.BPSpeed; +} + +/*********************************************************************//** + * @brief + * The getBloodPumpHallSensorCount function gets the latest blood pump * hall sensor count. Count is a 16 bit free running counter. If counter is * counting up, indicates motor is running in forward direction. If counter is * counting down, indicates motor is running in reverse direction. Counter will @@ -416,14 +521,14 @@ * @details \b Outputs: none * @return Latest blood pump hall sensor count reading. *************************************************************************/ -U16 getFPGABloodPumpHallSensorCount( void ) +U16 getBloodPumpHallSensorCount( void ) { return 0;//fpgaSensorReadings.bloodPumpHallSensorCount; } /*********************************************************************//** * @brief - * The getFPGABloodPumpHallSensorStatus function gets the latest blood pump + * The getBloodPumpHallSensorStatus function gets the latest blood pump * hall sensor status. * Bit 7 - Derived direction of the blood pump motor (0=Fwd, 1=Rev) * Bit 6 - Unused @@ -432,22 +537,22 @@ * @details \b Outputs: none * @return latest blood pump hall sensor status reading. *************************************************************************/ -U08 getFPGABloodPumpHallSensorStatus( void ) +U08 getBloodPumpHallSensorStatus( void ) { return 0;//fpgaSensorReadings.bloodPumpHallSensorStatus; } /*********************************************************************//** * @brief * The getPBAPressure function gets the latest arterial pressure reading. - * High byte indicates alarm status for ADC channel. - * @note Low 24-bits are channel reading. Subtract 2^23 from low 24 bits to get - * signed channel reading. + * The high 2 bits are status bits: 00=ok, 01=cmd mode, 10=stale data, 11=diag + * The low 14 bits are data. Zero is at 1638. Values above are positive, + * below are negative. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none * @return latest arterial pressure reading *************************************************************************/ -S32 getPBAPressure( void ) +U16 getPBAPressure( void ) { return fpgaSensorReadings.PBAPressure; } @@ -460,7 +565,7 @@ * @details \b Outputs: none * @return latest arterial pressure sensor temperature reading *************************************************************************/ -S32 getPBATemperature( void ) +S16 getPBATemperature( void ) { return fpgaSensorReadings.PBATemperature; } @@ -501,7 +606,7 @@ * @details \b Outputs: none * @return latest venous pressure reading *************************************************************************/ -S32 getPBOPressure( void ) +U16 getPBOPressure( void ) { return fpgaSensorReadings.PBoPressure; } @@ -514,7 +619,7 @@ * @details \b Outputs: none * @return latest venous pressure sensor temperature reading *************************************************************************/ -S32 getPBOTemperature( void ) +S16 getPBOTemperature( void ) { return fpgaSensorReadings.PBoTemperature; } @@ -582,14 +687,22 @@ /*********************************************************************//** * @brief * The setFPGAValvesControlMode function sets the valves control mode. + * @note VBTControl register bit 0 will drive state of VBT valve (0=closed, 1=open). * @details \b Inputs: fpgaActuatorSetPoints * @details \b Outputs: fpgaActuatorSetPoints * @param bits : The bits to enable the PID controller of a valve * @return none *************************************************************************/ -void setFPGAValvesControlMode( U16 bits ) +void setVBTValveState( OPN_CLS_STATE_T state ) { - //fpgaActuatorSetPoints.fpgaPIDControl = bits; + if ( STATE_OPEN == state ) + { + fpgaActuatorSetPoints.VBTControl |= FPGA_VBT_OPEN_BIT_MASK; + } + else + { + fpgaActuatorSetPoints.VBTControl &= ~((U08)FPGA_VBT_OPEN_BIT_MASK); + } } /*********************************************************************//** @@ -637,33 +750,95 @@ /*********************************************************************//** * @brief - * The setVBVPosition function sets the target encoder position of VBV - * in counts + * The setVBAControl function sets the control bits for the venous pinch valve. + * Microstep setting: bits 0..2: + * 0=full step (100% torque) + * 1=1/2 step (100% torque) + * 2=1/16 step + * 3=1/32 step + * 4=full step (modified) + * 5=1/2 step (modified) + * 6=1/4 step + * 7=1/8 step + * Direction: bit 3 + * 0=forward + * 1=reverse + * Enable: bit 4 (active low) + * 0=enabled + * 1=disabled + * Reset: bit 5 (active low) + * 0=reset (set to 1 after power up) + * Sleep: bit 6 (active low) + * 0=sleep mode + * Reserved: bit 7 * @details \b Inputs: none * @details \b Outputs: fpgaActuatorSetPoints + * @param controlBits The control bits to apply to the venous pinch valve. + * @return none + *************************************************************************/ +void setVBVControl( U08 controlBits ) +{ + +} + +/*********************************************************************//** + * @brief + * The getVBVControl function gets the current control bits for the VBV. + * @details \b Inputs: fpgaActuatorSetPoints + * @details \b Outputs: none + * @return fpgaActuatorSetPoints.VBVControl + *************************************************************************/ +U08 getVBVControl( void ) +{ + return fpgaActuatorSetPoints.VBVControl; +} + +/*********************************************************************//** + * @brief + * The setVBVPosition function sets the travel from current position for the + * VBV in counts (or microcounts if microstepping is set in control register). + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints * @param setPoint The target encoder position of the VBV in counts * @return none *************************************************************************/ -void setVBVPosition( S16 setPoint ) +void setVBVPosition( U16 setPoint ) { fpgaActuatorSetPoints.VBVPosition = setPoint; } /*********************************************************************//** * @brief - * The getVBVPosition function returns the current encoder position of - * VBV in counts + * The getVBVEncoderPosition function reads the current encoder position of the + * VBV in counts. + * @note There are 1024 encoder counts per revolution. The encoder position + * register provides the number of steps traveled since last command given. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none * @return The current encoder position of VBV *************************************************************************/ -S16 getVBVPosition( void ) +S16 getVBVEncoderPosition( void ) { - return fpgaSensorReadings.VBVPosition; + return fpgaSensorReadings.VBVEncPosition; } /*********************************************************************//** * @brief + * The getVBVCmdPosition function returns the current amount of travel + * from the pre-command position in steps (or microsteps if microstepping is + * set in control register) for VBV. + * @note There are 200 steps per revolution + * @details \b Inputs: fpgaSensorReadings + * @details \b Outputs: none + * @return The commanded encoder position of VBV + *************************************************************************/ +S16 getVBVCmdPosition( void ) +{ + return fpgaSensorReadings.VBVCmdPosition; +} + +/*********************************************************************//** + * @brief * The getVBVStatus function reads the status of the venous pinch valve. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none @@ -676,67 +851,102 @@ /*********************************************************************//** * @brief - * The getFPGAValveBloodVenousCurrentCounts function returns the current - * of VBV in counts - * @details \b Inputs: fpgaSensorReadings + * The setVBAControl function sets the control bits for the arterial pinch valve. + * Microstep setting: bits 0..2: + * 0=full step (100% torque) + * 1=1/2 step (100% torque) + * 2=1/16 step + * 3=1/32 step + * 4=full step (modified) + * 5=1/2 step (modified) + * 6=1/4 step + * 7=1/8 step + * Direction: bit 3 + * 0=forward + * 1=reverse + * Enable: bit 4 (active low) + * 0=enabled + * 1=disabled + * Reset: bit 5 (active low) + * 0=reset (set to 1 after power up) + * Sleep: bit 6 (active low) + * 0=sleep mode + * Reserved: bit 7 + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints + * @param controlBits The control bits to apply to the arterial pinch valve. + * @return none + *************************************************************************/ +void setVBAControl( U08 controlBits ) +{ + fpgaActuatorSetPoints.VBAControl = controlBits; +} + +/*********************************************************************//** + * @brief + * The getVBAControl function gets the current control bits for the VBA. + * @details \b Inputs: fpgaActuatorSetPoints * @details \b Outputs: none - * @return The latest current of VBV + * @return fpgaActuatorSetPoints.VBAControl *************************************************************************/ -U16 getFPGAValveBloodVenousCurrentCounts( void ) +U08 getVBAControl( void ) { - return 0;//fpgaSensorReadings.VBVCurrent; + return fpgaActuatorSetPoints.VBAControl; } /*********************************************************************//** * @brief - * The setVBAPosition function sets the target encoder position of the VBA - * in counts + * The setVBAPosition function sets the travel from current position for the + * VBA in counts (or microcounts if microstepping is set in control register). * @details \b Inputs: none * @details \b Outputs: fpgaActuatorSetPoints * @param setPoint The target encoder position of the VBA in counts * @return none *************************************************************************/ -void setVBAPosition( S16 setPoint ) +void setVBAPosition( U16 setPoint ) { fpgaActuatorSetPoints.VBAPosition = setPoint; } /*********************************************************************//** * @brief - * The getVBAPosition function reads the current encoder position of the - * VBA in counts + * The getVBAEncoderPosition function reads the current encoder position of the + * VBA in counts. + * @note There are 1024 encoder counts per revolution * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none * @return The latest encoder position of VBA *************************************************************************/ -S16 getVBAPosition( void ) +S16 getVBAEncoderPosition( void ) { - return fpgaSensorReadings.VBAPosition; + return fpgaSensorReadings.VBAEncPosition; } /*********************************************************************//** * @brief - * The getVBAStatus function reads the status of the arterial pinch valve. + * The getVBACmdPosition function returns returns the current amount of travel + * from the pre-command position in steps (or microsteps if microstepping is + * set in control register) for VBA. + * @note There are 200 steps per revolution * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest status of the arterial pinch valve + * @return The commanded encoder position of VBA *************************************************************************/ -U16 getVBAStatus( void ) +S16 getVBACmdPosition( void ) { - return fpgaSensorReadings.VBAStatus; + return fpgaSensorReadings.VBACmdPosition; } /*********************************************************************//** * @brief - * The getFPGAValveBloodArterialCurrentCounts function reads the current - * of VBA in counts + * The getVBAStatus function reads the status of the arterial pinch valve. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return The latest current of VBA + * @return Latest status of the arterial pinch valve *************************************************************************/ -U16 getFPGAValveBloodArterialCurrentCounts( void ) +U16 getVBAStatus( void ) { - return 0;//fpgaSensorReadings.; + return fpgaSensorReadings.VBAStatus; } /*********************************************************************//**