Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
reference:add-ons:dmm-shield:libraryuserguide [2018/06/07 07:03] – [DMMExportCalib] Cristian Fatu | reference:add-ons:dmm-shield:libraryuserguide [2018/06/19 13:35] (current) – removed Bianca Peterlin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== DMM Shield Library User Guide ====== | ||
- | |||
- | Digilent provides a DMMShield MPLAB X library for Digilent uC32 board. Basically, it accesses DMMShield hardware in order to implement DMMShield functionality. The library has multiple modules, corresponding to different hardware modules. | ||
- | |||
- | The library is aimed to run on the Digilent uC32 board, which acts as a carrier for DMMShield. The DMMShield is attached to uC32 carrier board, that is accessing DMMShield using digital pins. | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | == Download This User Guide == | ||
- | * {{ : | ||
- | |||
- | ---- | ||
- | |||
- | |||
- | ====== Overview ====== | ||
- | |||
- | The overview diagram shows the general structure of the DMMShield library, the library modules, and the relations between them. | ||
- | From the perspective of providing to user the access to the hardware, there as three stacked layers. | ||
- | The GPIO, SPI and UART belong to the lowest level, which can be seen as the Data layer. GPIO provides direct connection to the hardware digital pins, while SPI implements the SPI bit-bang protocol over the digital pins. UART provides the communication from the UART interface of the carrier board. | ||
- | The DMM, EPROM and CALIB modules belong to the middle layer, which can be seen as the Business layer. The DMM and EPROM functionality is implemented using the SPI module, while CALIB is using the DBB and EPROM modules. | ||
- | The DMMCMD module belongs to the highest layer, which can be seen as the Presentation layer. It provides a command interpreter that listens to the commands received over UART (from a terminal, for example), while the command output is sent back over UART. | ||
- | |||
- | |||
- | ====== Library overall structure ====== | ||
- | |||
- | ====== Library usage ====== | ||
- | |||
- | The library can be used as a whole or modules can be individually included in the user applications. | ||
- | |||
- | |||
- | ==== Library usage as a whole ==== | ||
- | |||
- | The provided software package can be used to access all the DMMShield functionality. | ||
- | The main program is calling a command interpreter from [[# | ||
- | |||
- | ==== Library usage as modules included in user application ==== | ||
- | |||
- | User may choose to include different modules in specific applications. For example, the user may choose to include [[# | ||
- | |||
- | |||
- | |||
- | ====== Library modules ====== | ||
- | ===== DMMCMD module ===== | ||
- | |||
- | The DMMCMD module implements a command interpreter that basically has these functions: | ||
- | - It listens over UART for individual DMMShield commands. User will have to provide these commands using a terminal connected to the USB port corresponding to the connected uC32 board. | ||
- | - The commands are recognized by DMMCMD module and implemented by calls to needed modules. | ||
- | - The command interpreter will send over UART (see UART module) the commands output messages, which can be seen in the terminal window. | ||
- | It is important to comply with each command expected formalism. | ||
- | Each command is terminated with a ‘\r’, or ‘\n’ or both characters. It might contain one or more arguments, as detailed in the subsequent sections of the document.\\ | ||
- | The following chapters provide details about data formatting: | ||
- | * [[# | ||
- | * [[# | ||
- | The following list enumerates the commands implemented in the DMMCMD module: | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | |||
- | ==== Interpreting values provided as parameter ==== | ||
- | Values formatted in character strings must be provided as parameters for some functions, for example the reference value provided as parameter to calibration functions in [[# | ||
- | Providing a value as a parameter must comply to the following rules: | ||
- | The value is composed by a fractional number followed by the unit. The unit is formed by the base unit (“V”, “A” or “Ohm”), eventually prefixed by multiple / submultiple designators (“u”, “m”, “k” and “M”). It is mandatory that the base unit matches the current selected scale, otherwise the following error is returned: " | ||
- | The function that implements value interpreting is [[# | ||
- | |||
- | Example: “2.456789 mV” is correct for VoltageDC5 scale, and corresponds to the 0.002456789 value. | ||
- | |||
- | ==== Format of values in the answer text ==== | ||
- | Some functions return character strings representing values, for example get value functions of the [[# | ||
- | The values will be formatted as a fractional number (6 decimals), followed by the base unit (“V”, “A” or “Ohm”) corresponding to the current selected scale. No multiple / submultiple designators of the base unit are used. | ||
- | |||
- | Example: 0.002456789 is formatted " | ||
- | |||
- | ==== DMMConfig ==== | ||
- | === Syntax: === | ||
- | “DMMConfig < | ||
- | |||
- | === Example: === | ||
- | “DMMConfig VoltageDC5” | ||
- | |||
- | === Description: | ||
- | The DMMConfig command configures the DMM for a specific scale. | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | The possible values from the < | ||
- | ^No.^ Scale ^ | ||
- | |1| Resistance50M | | ||
- | |2| Resistance5M | | ||
- | |3| Resistance500k | | ||
- | |4| Resistance50k | | ||
- | |5| Resistance5k | | ||
- | |6| Resistance500 | | ||
- | |7| Resistance50 | | ||
- | |8| VoltageDC50 | | ||
- | |9| VoltageDC5 | | ||
- | |10| VoltageDC500m | | ||
- | |11| VoltageDC50m | | ||
- | |12| VoltageAC50 | | ||
- | |13| VoltageAC5 | | ||
- | |14| VoltageAC500m | | ||
- | |15| VoltageAC50m | | ||
- | |16| CurrentDC5 | | ||
- | |17| CurrentAC5 | | ||
- | |18| Continuity | | ||
- | |19| Diode | | ||
- | |20| CurrentDC500m | | ||
- | |21| CurrentDC50m | | ||
- | |22| CurrentDC5m | | ||
- | |23| CurrentDC500u | | ||
- | |24| CurrentAC5 | | ||
- | |25| CurrentAC500m | | ||
- | |26| CurrentAC50m | | ||
- | |27| CurrentAC5m | | ||
- | |28| CurrentAC500u | | ||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | “OK, Selected scale index is: <integer value> | ||
- | | “ERROR, Missing valid configuration: | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMMeasureRep ==== | ||
- | === Syntax: === | ||
- | “DMMMeasureRep” | ||
- | |||
- | |||
- | === Description: | ||
- | This commands initiates a session of repetitive measurements. These repetitive measurements will be performed until the [[# | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Answer: === | ||
- | - After issuing the command: “OK, Measure repeated” | ||
- | - Repeatedly, for each measurement: | ||
- | |||
- | ^ Answer | ||
- | | “Value: <value, 6 decimals followed by unit>” | The value included in the message is formatted as explained in [[# | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMMeasureStop ==== | ||
- | === Syntax: === | ||
- | “DMMMeasureStop” | ||
- | |||
- | |||
- | === Description: | ||
- | This command terminates the repetitive measurements session initiated by [[# | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Answer: === | ||
- | "OK, Measure stop" | ||
- | |||
- | ==== DMMMeasureRaw ==== | ||
- | === Syntax: === | ||
- | “DMMMeasureRaw” | ||
- | |||
- | |||
- | === Description: | ||
- | This commands initiates a session of repetitive measurements of raw values. Raw values are values acquired from DMM, without applying the calibration corrections. These repetitive measurements will be performed until the [[# | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Answer: === | ||
- | - After issuing the command: “OK, Measure raw” | ||
- | - Repeatedly, for each measurement: | ||
- | |||
- | ^ Answer | ||
- | | “Value: <value, 6 decimals followed by unit>” | The value included in the message is formatted as explained in [[# | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMMeasureAvg ==== | ||
- | === Syntax: === | ||
- | “DMMMeasureAvg” | ||
- | |||
- | |||
- | === Description: | ||
- | This commands performs one average measurement (taking the average value of a set of measurements). | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | “Avg. Value: | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMCalib ==== | ||
- | === Syntax: === | ||
- | ““DMMCalib< | ||
- | |||
- | === Example: === | ||
- | “DMMCalibP 5.000115 V”\\ | ||
- | “DMMCalibN -5.001185”\\ | ||
- | “DMMCalibS” | ||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This command performs the positive, negative, or on short calibration, | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | | < | ||
- | |||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | "OK, Calibration on positive done. Reference: < | ||
- | | “OK, Calibration on negative done. Reference: < | ||
- | | “OK, Calibration on short done: Measured Val = <value, 6 decimals>, | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | | “ERROR, Missing valid reference value: \"< | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMMeasureForCalibCalib ==== | ||
- | === Syntax: === | ||
- | “DMMMeasureForCalibCalib< | ||
- | |||
- | === Example: === | ||
- | “DMMMeasureForCalibCalibP”\\ | ||
- | or\\ | ||
- | “DMMMeasureForCalibCalibN”\\ | ||
- | |||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This command initiates the positive or negative (depending on the character following DMMCalib command: ‘P’ or ‘N’) measurement for calibration, | ||
- | - the calibration measurement is launched (using this command) prior declaring the reference value | ||
- | - the reference value is later declared using [[# | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | “OK, Calibration positive measurement done. Measured Value: < | ||
- | | “OK, Calibration negative measurement done. Measured Value: | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMFinalizeCalib ==== | ||
- | === Syntax: === | ||
- | “DMMFinalizeCalib< | ||
- | |||
- | === Example: === | ||
- | “DMMFinalizeCalibP 5.000115 V”\\ | ||
- | or\\ | ||
- | “DMMFinalizeCalibN -5.001185” | ||
- | |||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This command finalizes the positive or negative (depending on the character following DMMCalib command: ‘P’ or ‘N’) calibration process started using DMMeasureForCalib by declaring the reference value. The reference value is saved to be later processed when all the needed data will be present and the calibration will be finalized. Compared to [[# | ||
- | - the calibration measurement is launched (using [[# | ||
- | - the reference value is later declared using this command. | ||
- | |||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | |< | ||
- | |||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | OK, Calibration on positive done. Reference: < | ||
- | | “OK, Calibration on negative done. Reference: < | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | | “ERROR, Missing valid reference value: \"< | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMSaveEPROM ==== | ||
- | === Syntax: === | ||
- | “DMMSaveEPROM” | ||
- | |||
- | |||
- | === Description: | ||
- | This command saves to user EPROM all the calibrations. It is important to save calibration data to EPROM after calibrations are performed, otherwise the calibrations are lost next time the board is powered off. | ||
- | |||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | "OK, <number of saved calibrations> | ||
- | | “ERROR, EPROM write data ready timeout ” | ERROR, the write to EPROM failed. | | ||
- | |||
- | ==== DMMVerifyEPROM ==== | ||
- | === Syntax: === | ||
- | “DMMVerifyEPROM” | ||
- | |||
- | |||
- | === Description: | ||
- | This function verifies the content of the calibration data against the user calibration data stored in EPROM. | ||
- | |||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | "OK, EPROM Calibration data is verified" | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMExportCalib ==== | ||
- | === Syntax: === | ||
- | “DMMExportCalib” | ||
- | |||
- | |||
- | === Description: | ||
- | This command exports the content of the user calibration data as a table, showing for each scale index the additive and multiplicative coefficients. The coefficients are formatted as fractional numbers, with 6 decimals. | ||
- | |||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | "OK, Calibration data is exported | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | |||
- | |||
- | ==== DMMImportCalib ==== | ||
- | === Syntax: === | ||
- | “DMMImportCalib <Scale index>, < | ||
- | |||
- | === Example: === | ||
- | “DMMImportCalib 10, 0.021222, -0.000125” | ||
- | |||
- | === Description: | ||
- | This command imports the calibration data for a specific scale. It does not save calibration the data in EPROM. | ||
- | |||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | |<Scale index> | ||
- | |< | ||
- | |< | ||
- | |||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | “OK, Scale: <scale index>, Calibration coefficients: | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | | " | ||
- | |||
- | ==== DMMRestoreFactCalibs ==== | ||
- | === Syntax: === | ||
- | “DMMRestoreFactCalibs” | ||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This command restores the calibration data with the factory loaded values. It reads data from the factory calibration area of EPROM and saves it to the user calibration area of EPROM. | ||
- | |||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | "OK, Calibration data restored from FACTORY EPROM" | ||
- | | " | ||
- | | " | ||
- | | “ERROR, EPROM write data ready timeout ” | ERROR, the write to EPROM failed.| | ||
- | |||
- | ==== DMMReadSerialNo ==== | ||
- | === Syntax: === | ||
- | “DMMReadSerialNo” | ||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This command retrieves the 12 digits serial number information from EPROM. | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | |||
- | === Answer: === | ||
- | |||
- | ^ Answer | ||
- | | “OK, SerialNo = \"< | ||
- | | " | ||
- | | " | ||
- | |||
- | |||
- | |||
- | ===== DMM module ===== | ||
- | The DMM library module implements DMM (digital multimeter) related functions.\\ | ||
- | Basically, these functions configure the DMM device over the custom SPI in order to set a specific scale. They read over the custom SPI the status / convertor values specific to each scale, thus retrieving measured values.\\ | ||
- | The value retrieval function waits until the converters provide valid values. The values retrieved from DMM device are considered raw values. The DMM module applies (controlled by a flag) calibration coefficients over the raw values, obtaining measured values. See [[# | ||
- | In order to implement the custom SPI communication, | ||
- | The DMM module functions are accessed by [[# | ||
- | See [[# | ||
- | See [[# | ||
- | Read [[# | ||
- | |||
- | The DMM functions can be grouped in the following way: | ||
- | - Initialization: | ||
- | * [[# | ||
- | - Scale functions: | ||
- | * [[# | ||
- | * [[# | ||
- | - Value functions: | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | - Value formatting functions: | ||
- | * [[# | ||
- | * [[# | ||
- | |||
- | |||
- | |||
- | |||
- | ==== DMM_Init ==== | ||
- | === Synopsis: === | ||
- | void DMM_Init(); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Return value: === | ||
- | |||
- | < | ||
- | === Description: | ||
- | This function initializes the DMM module.\\ | ||
- | It calls the SPI_Init() function to initialize the digital pins used by DMMShield. | ||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | DMM_Init(); | ||
- | |||
- | ==== DMM_SetScale ==== | ||
- | === Synopsis: === | ||
- | uint8_t DMM_SetScale(int idxScale); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |int idxScale|the Scale index| | ||
- | |||
- | === Return value: === | ||
- | |||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS| 0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG| 0xFC |wrong scale index| | ||
- | |ERRVAL_DMM_CFGVERIFY| 0xF5|DMM Configuration verify error| | ||
- | |||
- | === Description: | ||
- | This function configures a specific scale as the current scale. | ||
- | According to this scale, it uses data defined in dmmcfg structure to configure the switches and to set the value of the registers (24 registers starting at 0x1F address).\\ | ||
- | It also verifies the configuration setting success status by reading the values of these registers.\\ | ||
- | It returns ERRVAL_SUCCESS if the operation is successful.\\ | ||
- | It returns ERRVAL_DMM_CFGVERIFY if verifying fails.\\ | ||
- | It returns ERRVAL_DMM_IDXCONFIG if the scale index is not valid. | ||
- | |||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = DMM_SetScale(idxCfg); | ||
- | |||
- | ==== DMM_GetCurrentScale ==== | ||
- | === Synopsis: === | ||
- | int DMM_GetCurrentScale(); | ||
- | |||
- | === Parameters: === | ||
- | < | ||
- | |||
- | |||
- | |||
- | === Return value: === | ||
- | int | ||
- | |positive value|current scale index| | ||
- | |-1|if no current scale was selected| | ||
- | |||
- | === Description: | ||
- | This function returns the current scale index. This is the last scale index selected using the DMM_SetScale function.\\ | ||
- | In case no current scale was selected, the function returns -1. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | int idxScale = DMM_GetCurrentScale(); | ||
- | |||
- | |||
- | ==== DMM_DGetValue ==== | ||
- | === Synopsis: === | ||
- | double DMM_DGetValue(uint8_t *pbErr); | ||
- | |||
- | === Parameters: === | ||
- | |uint8_t *pbErr|Pointer to the error parameter| | ||
- | The *pbErr parameter can be set to: | ||
- | |ERRVAL_SUCCESS| 0|success| | ||
- | |ERRVAL_DMM_VALIDDATATIMEOUT| 0xFA|wrong scale index| | ||
- | |ERRVAL_DMM_IDXCONFIG| 0xFC|wrong scale index| | ||
- | |||
- | |||
- | |||
- | === Return value: === | ||
- | double | ||
- | |the measured value (value computed according to the converter / RMS registers values)| | ||
- | |+/- INFINITY if the converter / RMS registers values are outside the expected range. The INFINITY special value is defined as 1e+308| | ||
- | |NAN (not a number) value if ERRVAL_DMM_IDXCONFIG or ERRVAL_DMM_VALIDDATATIMEOUT are set. The NAN special value is defined as 0.0f/0.0f| | ||
- | |||
- | === Description: | ||
- | This function repeatedly retrieves the value from the converter / RMS registers, until a valid value is detected\\ | ||
- | It returns INFINITY when measured values are outside the expected converter range.\\ | ||
- | If there is no valid current scale selected, the function sets the error value to ERRVAL_DMM_IDXCONFIG and NAN value is returned.\\ | ||
- | If there is no valid value retrieved within a specific timeout period, the error is set to ERRVAL_DMM_VALIDDATATIMEOUT and NAN value is returned.\\ | ||
- | When no errors are detected, the error is set to ERRVAL_SUCCESS.\\ | ||
- | The error is copied in the byte pointed by pbErr, if pbErr is not null. | ||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | double dVal = DMM_DGetValue(& | ||
- | |||
- | ==== DMM_DGetAvgValue ==== | ||
- | === Synopsis: === | ||
- | double DMM_DGetAvgValue(uint8_t *pbErr); | ||
- | |||
- | === Parameters: === | ||
- | |int cbSamples|The number of values to be used for the average value| | ||
- | |uint8_t *pbErr|Pointer to the error parameter| | ||
- | The *pbErr parameter can be set to: | ||
- | |ERRVAL_SUCCESS| 0|success| | ||
- | |ERRVAL_DMM_VALIDDATATIMEOUT| 0xFA|wrong scale index| | ||
- | |ERRVAL_DMM_IDXCONFIG| 0xFC|wrong scale index| | ||
- | |||
- | |||
- | |||
- | === Return value: === | ||
- | double | ||
- | |the average of the measured values (values computed according to the converter / RMS registers values)| | ||
- | |+/- INFINITY if the converter / RMS registers values are outside the expected range. The INFINITY special value is defined as 1e+308| | ||
- | |NAN (not a number) value if ERRVAL_DMM_IDXCONFIG or ERRVAL_DMM_VALIDDATATIMEOUT are set. The NAN special value is defined as 0.0f/0.0f| | ||
- | |||
- | === Description: | ||
- | This function computes an average value corresponding to the DMM value returned by DMM_DGetValue, | ||
- | If there is no valid current scale selected, the error is set to ERRVAL_DMM_IDXCONFIG.\\ | ||
- | If there is no valid value retrieved within a specific timeout period, the error is set to ERRVAL_DMM_VALIDDATATIMEOUT.\\ | ||
- | It returns INFINITY when measured values are outside the expected convertor range.\\ | ||
- | When no error is detected, the error is set to ERRVAL_SUCCESS.\\ | ||
- | The error is copied on the byte pointed by pbErr, if pbErr is not null.\\ | ||
- | When errors are detected, the function returns NAN. | ||
- | |||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | double dVal; | ||
- | dVal = DMM_DGetAvgValue(20, | ||
- | |||
- | ==== DMM_SetUseCalib ==== | ||
- | === Synopsis: === | ||
- | void DMM_SetUseCalib(uint8_t f); | ||
- | |||
- | === Parameters: === | ||
- | |uint8_t f|1| if calibrations coefficients should be applied in future DMM_DGetStatus calls| | ||
- | | ::: |0| if calibrations coefficients should not be applied in future DMM_DGetStatus calls| | ||
- | |||
- | === Return value: === | ||
- | < | ||
- | === Description: | ||
- | This function sets the parameter that will determine whether or not the calibration coefficients will be applied when value is computed in subsequent DMM_DGetStatus calls.\\ | ||
- | The default value for this parameter is 1. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | DMM_SetUseCalib(0); | ||
- | |||
- | |||
- | |||
- | |||
- | ==== DMM_CheckAcceptedMeasurementDispersion ==== | ||
- | === Synopsis: === | ||
- | uint8_t DMM_CheckAcceptedMeasurementDispersion(double dMeasuredVal, | ||
- | |||
- | === Parameters: === | ||
- | |double dMeasuredVal|The measured value| | ||
- | |double dRefVal|The reference value| | ||
- | |double *pDispersion|Pointer to receive the measured value dispersion| | ||
- | |||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |ERRVAL_DMM_MEASUREDISPERSION|0xF1|The measurement dispersion exceeds accepted range| | ||
- | |||
- | === Description: | ||
- | This function checks if the measurement dispersion exceeds the accepted range.\\ | ||
- | The dispersion is computed as the difference of the measured and reference values, divided by the scale range.\\ | ||
- | The positive dispersion is checked to be smaller than parameter calibAcceptP of the scale configuration data.\\ | ||
- | The range of accepted values for dispersion is specific to each scale and it's defined in dmmcfg array.\\ | ||
- | The positive values of dispersion are checked to be smaller than field calibAcceptP of dmmcfg.\\ | ||
- | The negative values of dispersion are checked to be smaller than field calibAcceptN of dmmcfg.\\ | ||
- | If dispersion is not in the accepted range then ERRVAL_DMM_MEASUREDISPERSION is returned and the error string is set to last error string in ERRORS module. This string can be later accessed with ERRORS_GetszLastError function.\\ | ||
- | If there is no valid current configuration selected, the function returns ERRVAL_DMM_IDXCONFIG.\\ | ||
- | When dispersion is in the accepted range, the function returns ERRVAL_SUCCESS. | ||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bResult = DMM_CheckAcceptedMeasurementDispersion( *pMeasuredVal, | ||
- | |||
- | |||
- | ==== DMM_FormatValue ==== | ||
- | === Synopsis: === | ||
- | uint8_t DMM_FormatValue(double dVal, char *pString); | ||
- | |||
- | === Parameters: === | ||
- | |double dVal|The value to be formatted| | ||
- | |char *pString|The string to get the formatted value| | ||
- | |uint8_t fUnit|flag to indicate if unit information should be added\\ - not 0 - add unit / subunit\\ - | ||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |||
- | === Description: | ||
- | The function formats a value according to the current selected scale.\\ | ||
- | The parameter value dVal must correspond to the base Unit (V, A or Ohm), mainly a measured value returned by [[# | ||
- | The function multiplies the value according to the scale specific multiple / submultiple.\\ | ||
- | It formats the value with 6 decimals. \\ | ||
- | If fUnit is not 0 it adds the measure unit text (including multiple / submultiple) corresponding to the scale.\\ | ||
- | If dVal is +/- INFINITY (converter values are outside expected range), then " | ||
- | If dVal is +/- INFINITY (converter values are outside expected range), then " | ||
- | The function returns ERRVAL_DMM_IDXCONFIG if the current scale is not valid.\\ | ||
- | For example it formats the value 0.0245678912 into the " | ||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | DMM_FormatValue(dRefVal, | ||
- | |||
- | ==== DMM_InterpretValue ==== | ||
- | === Synopsis: === | ||
- | uint8_t DMM_InterpretValue(char *pString, double *pdVal); | ||
- | |||
- | === Parameters: === | ||
- | |char *pString|the string containing the value to be interpreted| | ||
- | |double *pdVal|pointer to a double variable to get the value| | ||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |ERRVAL_CMD_VALWRONGUNIT|0xF4|The provided value has a wrong measure unit.| | ||
- | |ERRVAL_CMD_VALFORMAT|0xF2|The numeric value cannot be extracted from the provided string.| | ||
- | |||
- | === Description: | ||
- | The function extracts a value from a string containing a value, eventually followed by a Unit.\\ | ||
- | The string Unit must match the current scale base Unit (V, A or Ohm), still different multiples / submultiples can be used.\\ | ||
- | The function returns in the variable pointed by pdVal the extracted value in the base Unit, regardless of the multiple / submultiple used in the input string, or the multiple / submultiple specific to the current scale.\\ | ||
- | If the string is " | ||
- | If the measure unit is missing then the unit (with multiple / submultiple) corresponding to the current scale is used.\\ | ||
- | The function returns ERRVAL_DMM_IDXCONFIG if the current scale is not valid.\\ | ||
- | The function returns ERRVAL_CMD_VALWRONGUNIT if the measure unit does not match the current scale base Unit (V, A or Ohm).\\ | ||
- | The function returns ERRVAL_CMD_VALMISSINGUNIT if the measure unit is missing.\\ | ||
- | The function returns ERRVAL_CMD_VALFORMAT if the numeric value cannot be extracted from the provided string. | ||
- | For example it interprets the string " | ||
- | |||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = DMM_InterpretValue(szVal, | ||
- | |||
- | |||
- | |||
- | ===== CALIB module ===== | ||
- | |||
- | CALIB module groups functions that implement calibration functionality of DMMShield. The functions are implemented in calib.c source file.\\ | ||
- | The DMMShield measuring hardware has errors due to DMM device and DMMShield additional electronics.\\ | ||
- | Calibration is the process of establishing some correction coefficients that, applied to the acquired values, allow more precise measurements. | ||
- | Calibration is done for each scale (see [[# | ||
- | For each scale, calibration is done in multiple points: positive, on short or negative, depending on scale). The positive / negative calibrations are done at a value close to the maximum / minimum scale value. The reference value is measured using a separate measuring device, as accurate as possible.\\ | ||
- | Basically calibration is done by calling calibration functions to inform the system that in a specific moment the reference values are applied to the DMMShield connectors. The library functions initiate a DMMShield measurement and then the measured value and reference value are stored, to be used when all the calibration data exists. | ||
- | |||
- | Basically there are three groups of functions: | ||
- | - Initialization: | ||
- | * [[# | ||
- | - Functions that implement calibration functionality: | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | |||
- | - Main functions that deal with EPROM calibration data: | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | |||
- | - Auxiliary functions that deal with EPROM calibration data:: | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | * [[# | ||
- | |||
- | Read Calibration chapter for more details about calibration.\\ | ||
- | The CALIB module maintains a data structure that stores the partial calibration data, called partCalibData, | ||
- | * double Calib_Ms_Short; | ||
- | * double Calib_Ms_ValP; | ||
- | * double Calib_Ref_ValP; | ||
- | * double Calib_Ms_ValN; | ||
- | * double Calib_Ref_ValN; | ||
- | These fields will be later used in the function description. | ||
- | |||
- | ==== CALIB_Init ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_Init(); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_EPROM_MAGICNO|0xFD|wrong Magic No. when reading data from EPROM| | ||
- | |ERRVAL_EPROM_CRC|0xFE|wrong CRC when reading data from EPROM| | ||
- | |||
- | |||
- | === Description: | ||
- | This function initializes the calibration related data.\\ | ||
- | It initializes the EPROM module, the partial calibration data and reads all the calibration values from user calibration area of EPROM.\\ | ||
- | The return values are related to errors when calibration is read from user calibration area of EPROM.\\ | ||
- | The function returns ERRVAL_SUCCESS when success.\\ | ||
- | The function returns ERRVAL_EPROM_MAGICNO when a wrong magic number was detected in the data read from EPROM.\\ | ||
- | The function returns ERRVAL_EPROM_CRC when the checksum is wrong for the data read from EPROM.\\ | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bResult = CALIB_Init(); | ||
- | |||
- | |||
- | |||
- | ==== CALIB_CalibOnPositive ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_CalibOnPositive(double dRefVal, double *pMeasuredVal, | ||
- | |||
- | === Parameters: === | ||
- | | double dRefVal | ||
- | | double *pMeasuredVal | ||
- | | uint8_t bEarlyMeasurement | ||
- | | double *pDispersion | ||
- | | uint8_t fIgnoreDispersion | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |ERRVAL_DMM_VALIDDATATIMEOUT|0xFA|valid data DMM timeout| | ||
- | |ERRVAL_CMD_VALMISSINGUNIT|0xF3|The provided value does not contain a measure unit.| | ||
- | |ERRVAL_DMM_MEASUREDISPERSION|0xF1|The calibration measurement dispersion exceeds accepted range.| | ||
- | |ERRVAL_CALIB_MISSINGMEASUREMENT|0xF0|A measurement must be performed before calling the finalize calibration function.|\\ | ||
- | === Description: | ||
- | This function implements the calibration on positive value procedure, for the currently selected scale.\\ | ||
- | It is possible that function CALIB_MeasureForCalibPositiveVal was previously called. This is considered early measurement, | ||
- | If no early measurement was performed (bEarlyMeasurement parameter is 0), the function calls CALIB_MeasureForCalibPositiveVal in order to perform the measurement and provide the measured value.\\ | ||
- | If early measurement was performed (bEarlyMeasurement parameter is non 0), the measured value is copied from Calib_Ms_ValP field of partCalibData.\\ | ||
- | If early measurement was performed and Calib_Ms_ValP is not valid (no valid measurement was previously performed), the function returns ERRVAL_CALIB_MISSINGMEASUREMENT.\\ | ||
- | The dispersion is computed as the difference of the measured and reference values, divided by the scale range. The dispersion is checked to be in the accepted range using DMM_CheckAcceptedMeasurementDispersion function.\\ | ||
- | If the parameter fIgnoreDispersion is non 0, the dispersion check is skipped, meaning that all the values are accepted and ERRVAL_DMM_MEASUREDISPERSION error is never returned\\ . | ||
- | Caution when calling the function with fIgnoreDispersion parameter with non 0 values, as calibration data can be seriously altered.\\ | ||
- | If dispersion is not in the accepted range then calibration is not finalized, partial calibration data is initialized and ERRVAL_DMM_MEASUREDISPERSION is returned.\\ | ||
- | When success, the reference value is stored in the Calib_Ref_ValP field of partCalibData.\\ | ||
- | When success, if the calibration process is complete then the calibration coefficients are computed.\\ | ||
- | If there is no valid current configuration selected, the function returns ERRVAL_DMM_IDXCONFIG and the measured value is set to NAN.\\ | ||
- | If a valid measurement cannot be performed, the function returns ERRVAL_DMM_VALIDDATATIMEOUT and the measured value is set to NAN. | ||
- | |||
- | |||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = CALIB_CalibOnPositive(dRefVal, | ||
- | \\ \\ | ||
- | |||
- | ==== CALIB_CalibOnNegative ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_CalibOnNegative(double dRefVal, double *pMeasuredVal, | ||
- | |||
- | === Parameters: === | ||
- | | double dRefVal | ||
- | | double *pMeasuredVal | ||
- | | uint8_t bEarlyMeasurement | ||
- | | double *pDispersion | ||
- | | uint8_t fIgnoreDispersion | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |ERRVAL_DMM_VALIDDATATIMEOUT|0xFA|valid data DMM timeout| | ||
- | |ERRVAL_CMD_VALMISSINGUNIT|0xF3|The provided value does not contain a measure unit.| | ||
- | |ERRVAL_DMM_MEASUREDISPERSION|0xF1|The calibration measurement dispersion exceeds accepted range.| | ||
- | |ERRVAL_CALIB_MISSINGMEASUREMENT|0xF0|A measurement must be performed before calling the finalize calibration function.|\\ | ||
- | === Description: | ||
- | This function implements the calibration on negative value procedure, for the current selected scale.\\ | ||
- | It is possible that function CALIB_MeasureForCalibNegativeVal was previously called. This is considered early measurement, | ||
- | If no early measurement was performed (bEarlyMeasurement parameter is 0), the function calls CALIB_MeasureForCalibNegativeVal in order to perform the measurement and provide the measured value.\\ | ||
- | If early measurement was performed (bEarlyMeasurement parameter is non 0), the measured value is copied from Calib_Ms_ValN field of partCalibData. | ||
- | If early measurement was performed and Calib_Ms_ValP is not valid (no valid measurement was previously performed), the function returns ERRVAL_CALIB_MISSINGMEASUREMENT.\\ | ||
- | The dispersion is computed as the difference of the measured and reference values, divided by the scale range. The dispersion is checked to be in the accepted range using DMM_CheckAcceptedMeasurementDispersion function.\\ | ||
- | If parameter fIgnoreDispersion is non 0, the dispersion check is skipped, meaning that all the values are accepted and ERRVAL_DMM_MEASUREDISPERSION error is never returned.\\ | ||
- | Caution when calling the function with fIgnoreDispersion parameter with non 0 values, as calibration data can be seriously altered.\\ | ||
- | If dispersion is not in the accepted range then calibration is not finalized, partial calibration data is initialized and ERRVAL_DMM_MEASUREDISPERSION is returned.\\ | ||
- | When success, the reference value is stored in the Calib_Ref_ValN field of partCalibData.\\ | ||
- | When success, if the calibration process is complete then the calibration coefficients are computed.\\ | ||
- | If there is no valid current configuration selected, the function returns ERRVAL_DMM_IDXCONFIG and the measured value is set to NAN.\\ | ||
- | If a valid measurement cannot be performed, the function returns ERRVAL_DMM_VALIDDATATIMEOUT and the measured value is set to NAN.\\ | ||
- | \\ | ||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = CALIB_CalibOnNegative(dRefVal, | ||
- | |||
- | \\ \\ | ||
- | |||
- | |||
- | ==== CALIB_CalibOnShort ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_CalibOnShort(double *pMeasuredVal, | ||
- | |||
- | === Parameters: === | ||
- | |||
- | | double *pMeasuredVal | ||
- | | double *pDispersion | ||
- | | uint8_t fIgnoreDispersion | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |ERRVAL_DMM_VALIDDATATIMEOUT|0xFA|valid data DMM timeout| | ||
- | |ERRVAL_DMM_MEASUREDISPERSION|0xF1|The calibration measurement dispersion exceeds accepted range.|\\ | ||
- | === Description: | ||
- | This function implements the calibration on short procedure, for the currently selected scale.\\ | ||
- | The function performs the measurement and then if the calibration process is complete the calibration coefficients are computed.\\ | ||
- | The dispersion is computed as the difference between the measured and reference values, divided by the scale range.\\ | ||
- | The dispersion is checked to be in the accepted range if parameter fIgnoreDispersion 0.\\ | ||
- | If parameter fIgnoreDispersion is non 0, the dispersion check is skipped, meaning that all the values are accepted and ERRVAL_DMM_MEASUREDISPERSION error is never returned. Caution when calling the function with fIgnoreDispersion parameter having values different than 0, as calibration data can be seriously altered.\\ | ||
- | If dispersion is not in the accepted range then calibration is not finalized, and ERRVAL_DMM_MEASUREDISPERSION is returned.\\ | ||
- | If there is no valid current configuration selected, the function returns ERRVAL_DMM_IDXCONFIG and the measured value is set to NAN.\\ | ||
- | If a valid measurement cannot be performed, the function returns ERRVAL_DMM_VALIDDATATIMEOUT and the measured value is set to NAN.\\ | ||
- | \\ | ||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = CALIB_CalibOnShort(& | ||
- | \\ \\ | ||
- | ==== CALIB_MeasureForCalibPositiveVal ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_MeasureForCalibPositiveVal(double *pMeasuredVal); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | | double *pMeasuredVal | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |ERRVAL_DMM_VALIDDATATIMEOUT|0xFA|valid data DMM timeout| | ||
- | \\ | ||
- | === Description: | ||
- | This function performs the measurement for the calibration on positive value procedure, for the currently selected scale.\\ | ||
- | The function calls the DMM_DGetAvgValue function in order to acquire the measured value without the calibration correction being applied. | ||
- | When success, the measured value is stored in the Calib_Ms_ValP field of partCalibData structure, and it's set as measured value.\\ | ||
- | If there is no valid current configuration selected, the function returns ERRVAL_DMM_IDXCONFIG and the measured value is set to NAN.\\ | ||
- | If a valid measurement cannot be performed, the function returns ERRVAL_DMM_VALIDDATATIMEOUT and the measured value is set to NAN.\\ | ||
- | This function can be called by CALIB_CalibOnPositive or can be called directly, before CALIB_CalibOnPositive (this is considered early measurement).\\ | ||
- | | ||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bResult = CALIB_MeasureForCalibPositiveVal(pMeasuredVal); | ||
- | \\ \\ | ||
- | ==== CALIB_MeasureForCalibNegativeVal ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_MeasureForCalibNegativeVal(double *pMeasuredVal); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | | double *pMeasuredVal | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |ERRVAL_DMM_VALIDDATATIMEOUT|0xFA|valid data DMM timeout| | ||
- | \\ | ||
- | === Description: | ||
- | This function performs the measurement for the calibration on negative value procedure, for the currently selected scale.\\ | ||
- | The function calls the DMM_DGetAvgValue function in order to acquire the measured value without the calibration correction being applied. | ||
- | When success, the measured value is stored in the Calib_Ms_ValN field of partCalibData structure, and it's set as measured value.\\ | ||
- | If there is no valid current configuration selected, the function returns ERRVAL_DMM_IDXCONFIG and the measured value is set to NAN.\\ | ||
- | If a valid measurement cannot be performed, the function returns ERRVAL_DMM_VALIDDATATIMEOUT and the measured value is set to NAN.\\ | ||
- | This function can be called by CALIB_CalibOnNegative or can be called directly, before CALIB_CalibOnNegative (this is considered early measurement).\\ | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bResult = CALIB_MeasureForCalibNegativeVal(pMeasuredVal); | ||
- | |||
- | ==== CALIB_WriteAllCalibsToEPROM_User ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_WriteAllCalibsToEPROM_User(); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - Number of modified calibrations or the error code: | ||
- | |Positive value < 27|0|success, | ||
- | |ERRVAL_EPROM_WRTIMEOUT|0xFF|EPROM write data ready timeout| | ||
- | |||
- | \\ | ||
- | === Description: | ||
- | This function writes calibration data in the user calibration area of EPROM.\\ | ||
- | This function should be called after changes are made in calibration data, in order to save them in the non-volatile memory.\\ | ||
- | In case of success the function returns the number of configurations that were modified since last save.\\ | ||
- | It returns ERRVAL_EPROM_WRTIMEOUT when calibration data write in EPROM is not properly performed.\\ | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = CALIB_WriteAllCalibsToEPROM_User(); | ||
- | |||
- | ==== CALIB_ReadAllCalibsFromEPROM_User ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_ReadAllCalibsFromEPROM_User(); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_EPROM_MAGICNO|0xFD|wrong Magic No. when reading data from EPROM| | ||
- | |ERRVAL_EPROM_CRC|0xFE|wrong CRC when reading data from EPROM| | ||
- | |||
- | |||
- | === Description: | ||
- | This function reads the user calibration data from EPROM.\\ | ||
- | It calls the local function CALIB_ReadAllCalibsFromEPROM_Raw function providing the address of user calibration area in EPROM, | ||
- | The function returns ERRVAL_SUCCESS for success.\\ | ||
- | The function returns ERRVAL_EPROM_MAGICNO when a wrong magic number was detected in the data read from EPROM.\\ | ||
- | The function returns ERRVAL_EPROM_CRC when the checksum is wrong for the data read from EPROM.\\ | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bResult = CALIB_ReadAllCalibsFromEPROM_User(); | ||
- | |||
- | ==== CALIB_RestoreAllCalibsFromEPROM_Factory ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_RestoreAllCalibsFromEPROM_Factory(); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_EPROM_MAGICNO|0xFD|wrong Magic No. when reading data from EPROM| | ||
- | |ERRVAL_EPROM_CRC|0xFE|wrong CRC when reading data from EPROM| | ||
- | |ERRVAL_EPROM_WRTIMEOUT|0xFF|EPROM write data ready timeout| | ||
- | |||
- | |||
- | === Description: | ||
- | This function restores the factory calibration data from EPROM.\\ | ||
- | This function reads factory calibration data from EPROM and writes the calibration data into the user calibration area of EPROM.\\ | ||
- | The function returns ERRVAL_SUCCESS for success.\\ | ||
- | It verifies the read factory calibration data from EPROM and detects the following errors: ERRVAL_EPROM_MAGICNO when a wrong magic number was detected, and ERRVAL_EPROM_CRC when the checksum is wrong.\\ | ||
- | It also returns ERRVAL_EPROM_WRTIMEOUT when calibration user data write in EPROM is not properly performed.\\ | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bResult = CALIB_ReadAllCalibsFromEPROM_User(); | ||
- | |||
- | ==== CALIB_VerifyEPROM ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_VerifyEPROM(); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_EPROM_VERIFY|0xF7|EPROM verify error| | ||
- | |ERRVAL_EPROM_MAGICNO|0xFD|wrong Magic No. when reading data from EPROM| | ||
- | |ERRVAL_EPROM_CRC|0xFE|wrong CRC when reading data from EPROM| | ||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This function compares the user calibration data from EPROM with the current calibration data.\\ | ||
- | The function returns ERRVAL_SUCCESS for success, the user calibration data from EPROM is identical to the current calibration data.\\ | ||
- | The function returns ERRVAL_EPROM_VERIFY for mismatch values found when comparing the user calibration data from EPROM with the current calibration data.\\ | ||
- | The function returns ERRVAL_EPROM_MAGICNO when a wrong magic number was detected in the data read from EPROM.\\ | ||
- | The function returns ERRVAL_EPROM_CRC when the checksum is wrong for the data read from EPROM.\\ | ||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = CALIB_VerifyEPROM(); | ||
- | |||
- | ==== CALIB_ExportCalibs_User ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_ExportCalibs_User(char *pSzCalibs); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |char *pSzCalibs|pointer to a character string to hold the exported sequence| | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_EPROM_MAGICNO|0xFD|wrong Magic No. when reading data from EPROM| | ||
- | |ERRVAL_EPROM_CRC|0xFE|wrong CRC when reading data from EPROM| | ||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This function exports user calibration data into a text.\\ | ||
- | The export is performed by formatting the calibration values in a text, copied in pSzCalibs, one row for each Scale index.\\ | ||
- | Therefore is important that the caller of this function allocates enough space in pSzCalibs (750 characters).\\ | ||
- | The function returns ERRVAL_SUCCESS for success.\\ | ||
- | The function returns ERRVAL_EPROM_MAGICNO when a wrong magic number was detected in the data read from EPROM.\\ | ||
- | The function returns ERRVAL_EPROM_CRC when the checksum is wrong for the data read from EPROM.\\ | ||
- | |||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | char calExp[1024]; | ||
- | bErrCode = CALIB_ExportCalibs_User(calExp); | ||
- | |||
- | ==== CALIB_ExportCalibs_Factory ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_ExportCalibs_Factory(char *pSzCalibs); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |char *pSzCalibs|pointer to a character string to hold the exported sequence| | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_EPROM_MAGICNO|0xFD|wrong Magic No. when reading data from EPROM| | ||
- | |ERRVAL_EPROM_CRC|0xFE|wrong CRC when reading data from EPROM| | ||
- | |||
- | |||
- | |||
- | === Description: | ||
- | This function exports factory calibration data into a text.\\ | ||
- | The export is performed by formatting the calibration values in a text, copied in pSzCalibs, one row for each Scale index.\\ | ||
- | Therefore is important that the caller of this function allocates enough space in pSzCalibs (750 characters).\\ | ||
- | The function returns ERRVAL_SUCCESS for success.\\ | ||
- | The function returns ERRVAL_EPROM_MAGICNO when a wrong magic number was detected in the data read from EPROM.\\ | ||
- | The function returns ERRVAL_EPROM_CRC when the checksum is wrong for the data read from EPROM.\\ | ||
- | \\ \\ | ||
- | === Example: === | ||
- | |||
- | #include " | ||
- | char calExp[1024]; | ||
- | bErrCode = CALIB_ExportCalibs_Factory(calExp); | ||
- | |||
- | ==== CALIB_ImportCalibCoefficients ==== | ||
- | === Synopsis: === | ||
- | uint8_t CALIB_ImportCalibCoefficients(int idxScale, float fMult, float fAdd); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |int idxScale|the Scale index| | ||
- | |float fMult|the calibration MULT coefficient| | ||
- | |float fAdd|the calibration ADD coefficient| | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS|0|success| | ||
- | |ERRVAL_DMM_IDXCONFIG|0xFC|wrong scale index| | ||
- | |||
- | === Description: | ||
- | This function imports the MULT and ADD calibration coefficients, | ||
- | On success, the coefficients are copied in the calibration data corresponding to the provided Scale.\\ | ||
- | The function copies the calibration coefficients into the calibration data and marks the calibration for the provided Scale as dirty (needs to be written in EPROM).\\ | ||
- | The function returns ERRVAL_DMM_IDXCONFIG if the provided Scale is not valid.\\ | ||
- | \\ \\ | ||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrCode = CALIB_ImportCalibCoefficients(10, | ||
- | ===== EPROM module ===== | ||
- | The DMMShield provides a non-volatile EEPROM memory 93LC66BT, having 512 bytes (4kbits).\\ | ||
- | It is accessed over a custom SPI protocol, using digital IO pins exposed in the DMMSHield connector: CS_EEPROM (EPROM SPI chip select), DO (SPI MISO), DI (SPI MOSI) and CLK (SPI CLK).\\ | ||
- | While the chip select is specific to EPROM, the SPI lines (data and clock) are shared with DMM device (see [[# | ||
- | The EPROM is used to store the following system information: | ||
- | * Serial number: | ||
- | * 12 bytes payload (see [[# | ||
- | * 2 extra bytes: magic number, checksum | ||
- | * Total 14 bytes, see the address space table below. | ||
- | * User Calibration: | ||
- | * 27*2*4 bytes payload (2 values of 4 byes (float) for 27 scales) | ||
- | * 2 extra bytes: magic number, checksum | ||
- | * Total 218 bytes, see the address space table below. | ||
- | * Factory Calibration: | ||
- | * 27*2*4 bytes payload (2 values of 4 byes (float) for 27 scales) | ||
- | * 2 extra bytes: magic number, checksum | ||
- | * Total 218 bytes, see the address space table below. | ||
- | Note that the structure of User Calibration area is identical to the structure of Factory Calibration area.\\ | ||
- | For more details about Calibration process, read more on [[# | ||
- | Each of the tree above mentioned sections contains, for safety reasons, additional information: | ||
- | * a byte containing a specific number called magic number (0x23) | ||
- | * a byte containing the checksum of all the bytes written in the specific section | ||
- | When reading a section content from EPROM, these two security bytes are checked, returning errors when mismatches are found. \\ | ||
- | The following table details the address space: | ||
- | ^ Addresses (words) ^ Addresses (bytes) | ||
- | | 0x93 – 0xFF | 0x0126 – 0x01FF | 109 words /\\ 218 bytes | Factory calibration data | | ||
- | | 0x8C – 0x92 | 0x0118 – 0x0125 | 7 words /\\ 14 bytes | Serial Number | | ||
- | | 0x1F – 0x8B | 0x003E – 0x0117 | 109 words /\\ 218 bytes | User calibration data | | ||
- | | 0x00 – 0x1E | 0x0000 – 0x003D | 31 words /\\ 62 bytes | Unused Memory | | ||
- | The addressing unit of the memory is 16 bit word. As the memory capacity is 256 words, the word addresses are implemented using 8 bit byte type.\\ | ||
- | Apart from this system information stored in EPROM, applications can be implemented to store specific user data using write functions from EPROM module, to access the unused memory starting a address 0. These functions are protected against writing over the system areas detailed above. | ||
- | |||
- | |||
- | ==== Serial number ==== | ||
- | Each board has a unique SerialNo, built as follows: | ||
- | * 6 characters DMMShield prefix (Digilent ID + Schematic ID): “210356”\\ | ||
- | * 6 characters unique serial of each board (read from the barcode label, after ‘D’): for example “A76C0C”\\ | ||
- | Example of DMM Shield SerialNo: “210356A76C0C”\\ | ||
- | This is written in the EPROM during the manufacturing procedure and shouldn’t be altered by the user. For more details see [[# | ||
- | |||
- | ==== EPROM_Init ==== | ||
- | === Synopsis: === | ||
- | void EPROM_Init(); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | < | ||
- | |||
- | === Return value: === | ||
- | |||
- | < | ||
- | === Description: | ||
- | This function initializes the EPROM module.\\ | ||
- | It calls the SPI_Init() function to initialize the digital pins used by DMMShield.\\ | ||
- | This function is called by CALIB_Init() and SERIALNO_Init().\\ | ||
- | The function guards against multiple calls using a static flag variable. | ||
- | |||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | EPROM_Init(); | ||
- | |||
- | ==== EPROM_ReadWords ==== | ||
- | === Synopsis: === | ||
- | void EPROM_ReadWords(uint8_t bAddress, uint16_t *prgVals, int cwVals) | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |uint8_t bAddress|the word address of the EPROM memory location to be read| | ||
- | |uint16_t *prgVals|pointer to an array of 16 bits values, to store the values read from EPROM| | ||
- | |int cwVals|number of 16 bits values to be read in EPROM| | ||
- | |||
- | |||
- | === Return value: === | ||
- | < | ||
- | |||
- | === Description: | ||
- | This function reads the specified number of words (16 bit values) from the specified EPROM word address into the specified buffer. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | EPROM_ReadWords(0, | ||
- | |||
- | ==== EPROM_WriteWords ==== | ||
- | === Synopsis: === | ||
- | uint8_t EPROM_WriteWords(uint8_t bAddress, uint16_t *prgVals, int cwVals); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |uint8_t bAddress|the word address of the EPROM memory location to be written| | ||
- | |uint16_t *prgVals|pointer to an array of words (16 bits values), to be written in EPROM| | ||
- | |int cwVals|number of words to be written in EPROM| | ||
- | |||
- | |||
- | === Return value: === | ||
- | uint8_t - The error code: | ||
- | |ERRVAL_SUCCESS| 0|success| | ||
- | |ERRVAL_EPROM_ADDR_VIOLATION| 0xF6 |EPROM write address violation: attempt to write over system data| | ||
- | |ERRVAL_EPROM_WRTIMEOUT| 0xFF |EPROM write data ready timeout| | ||
- | |||
- | === Description: | ||
- | This function writes the specified number of words (16-bit values) in EPROM, at the specified word address.\\ | ||
- | It is mandatory to enable the write operation before sending the data to EPROM, by calling the EPROM_WriteEnable() function.\\ | ||
- | The function returns | ||
- | Otherwise, the function returns ERRVAL_SUCCESS for success or ERRVAL_EPROM_WRTIMEOUT when EPROM is not answering with the write successful message. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | bErrorCode = EPROM_WriteWords(0, | ||
- | |||
- | ==== EPROM_WriteEnable ==== | ||
- | === Synopsis: === | ||
- | void EPROM_WriteEnable(); | ||
- | |||
- | === Parameters: === | ||
- | < | ||
- | |||
- | === Return value: === | ||
- | < | ||
- | |||
- | === Description: | ||
- | This function implements the EWEN (Write Enable) EPROM instruction.\\ | ||
- | Call this function before any EPROM write operations. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | EPROM_WriteEnable(); | ||
- | |||
- | ==== EPROM_WriteDisable ==== | ||
- | === Synopsis: === | ||
- | void EPROM_WriteDisable(); | ||
- | |||
- | === Parameters: === | ||
- | < | ||
- | |||
- | === Return value: === | ||
- | < | ||
- | |||
- | === Description: | ||
- | This function implements the EWDS (Write Disable) EPROM instruction.\\ | ||
- | Use this function to protect the values written in EPROM against subsequent writes. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | EPROM_WriteDisable(); | ||
- | |||
- | ==== EPROM_Erase ==== | ||
- | === Synopsis: === | ||
- | void EPROM_Erase(uint8_t bAddress); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |uint8_t bAddress|the word address of the EPROM memory location to be erased| | ||
- | |||
- | |||
- | |||
- | === Return value: === | ||
- | < | ||
- | |||
- | === Description: | ||
- | This function implements the ERASE EPROM instruction that erases one word.\\ | ||
- | Call this function in order to force all 16 bits of the specified address to 1. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | EPROM_Erase(0x10); | ||
- | ===== SPI module ===== | ||
- | The SPI module implements the SPI communication needed for [[# | ||
- | It uses the [[# | ||
- | The functions of this module allow the transfer of any number of bits, needed in order to implement the communication protocols with the above mentioned modules.\\ | ||
- | The module should only be accessed through the functions from upper level modules. | ||
- | |||
- | ===== GPIO module ===== | ||
- | The GPIO module provides the lowest level, the hardware access level to the digital lines. \\ | ||
- | Basically it configures the required digital lines as output or input digital line, provides the possibility to set a specific output digital line to 0 or 1 value, and to read the value of a digital input line.\\ | ||
- | It is accessed by [[# | ||
- | This module is the only module dependent to the hardware.\\ | ||
- | The module should only be accessed through the functions from upper level modules. | ||
- | |||
- | ===== UART module ===== | ||
- | The UART module implements the functionality needed to communicate on UART1 hardware interface of the uC32 board, connected to the USB - UART.\\ | ||
- | For example, using this module, UART communcation between uC32 and PC can be implemented over USB cable. Connecting the uC32 to the PC creates a new COM port which can be used in a simple terminal application.\\ | ||
- | The module initializes the UART to generate interrupt when a character is received. In the interrupt handler, the array of characters are stored as commands, using a circular buffer.\\ | ||
- | This module has no DMM functionality. It is just included to provide communication capabilities. It doesn' | ||
- | The module is only accessed by [[# | ||
- | The module provides: | ||
- | - Initialization function: | ||
- | * [[# | ||
- | - Character string transmit function: | ||
- | * [[# | ||
- | - Character string receive function: | ||
- | * [[# | ||
- | |||
- | ==== UART_Init ==== | ||
- | === Synopsis: === | ||
- | void UART_Init(unsigned int baud); | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |unsigned int baud|UART baud rate\\ for example 9600 corresponds to 9600 baud| | ||
- | |||
- | === Return value: === | ||
- | |||
- | < | ||
- | === Description: | ||
- | This function initializes the UART1 hardware interface involved in the UART module, in the UART receive with interrupt mode.\\ | ||
- | The UART_TX digital pin is configured as digital output.\\ | ||
- | The UART_RX digital pin is configured as digital input.\\ | ||
- | The UART_TX and UART_RX are mapped over the UART1 interface.\\ | ||
- | The UART1 module of PIC32 is configured to work at the specified baud, no parity and 1 stop bit. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | UART_Init(9600); | ||
- | |||
- | ==== UART_PutString ==== | ||
- | === Synopsis: === | ||
- | void UART_PutString(char szData[]) | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |char szData[]|the zero terminated string containing characters to be transmitted over UART| | ||
- | |||
- | === Return value: === | ||
- | |||
- | < | ||
- | === Description: | ||
- | This function transmits all the characters from a zero terminated string over UART1.\\ The terminator character is not sent.\\ | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | UART_PutString(" | ||
- | |||
- | |||
- | |||
- | ==== UART_GetString ==== | ||
- | === Synopsis: === | ||
- | uint8_t UART_GetString(char* pchBuff, int cchBuff) | ||
- | |||
- | === Parameters: === | ||
- | |||
- | |char* pchBuff|pointer to a char buffer to hold the received zero terminated string| | ||
- | |int cchBuff|size of the buffer to hold the zero terminated string| | ||
- | |||
- | |||
- | |||
- | === Return value: === | ||
- | |||
- | < | ||
- | === Description: | ||
- | This function provides a zero terminated string received over UART1 which was placed in the circular buffer by the UART interrupt handler.\\ | ||
- | If a received string is available in the circular buffer, the string is copied in the pchBuff string and its length is returned.\\ | ||
- | Otherwise, the function returns 0. | ||
- | |||
- | === Example: === | ||
- | |||
- | #include " | ||
- | cchi = UART_GetString(uartCmd, | ||
- | |||
- | ===== Appendix: DMM Scales ===== | ||
- | DMMShield allows selecting one from the following set of scales. | ||
- | The following table shows all the scales, together with 2 extra columns: corresponding Base measure unit and the Measure unit used when formatting the value. See [[# | ||
- | ^No.^ Scale ^Formatted values (provided by [[# | ||
- | ^::: | ||
- | |1| Resistance50M |Signed value, 6 decimals|MOhm|" | ||
- | |2| Resistance5M |::: | ||
- | |3| Resistance500k |::: | ||
- | |4| Resistance50k |::: | ||
- | |5| Resistance5k |::: | ||
- | |6| Resistance500 |::: | ||
- | |7| Resistance50 |::: | ||
- | |8| VoltageDC50 |Signed value, 6 decimals|V|" | ||
- | |9| VoltageDC5 |::: | ||
- | |10| VoltageDC500m |::: | ||
- | |11| VoltageDC50m |::: | ||
- | |12| VoltageAC50 |::: | ||
- | |13| VoltageAC5 |::: | ||
- | |14| VoltageAC500m |::: | ||
- | |15| VoltageAC50m |::: | ||
- | |19| Diode |::: | ||
- | |18| Continuity |Signed value, 6 decimals <when contact exists on probes> | ||
- | |16| CurrentDC5 |Signed value, 6 decimals|A|" | ||
- | |17| CurrentAC5 |::: | ||
- | |20| CurrentDC500m |::: | ||
- | |21| CurrentDC50m |::: | ||
- | |22| CurrentDC5m |::: | ||
- | |23| CurrentDC500u |::: | ||
- | |24| CurrentAC5 |::: | ||
- | |25| CurrentAC500m |::: | ||
- | |26| CurrentAC50m |::: | ||
- | |27| CurrentAC5m |::: | ||
- | |28| CurrentAC500u |::: | ||
- | |||
- | |||
- | |||
- | |||
- | |||