PIC32 DMM Shield Library User Guide

Digilent provides a DMM Shield MPLAB X library for Digilent uC32 board.
It accesses DMM Shield hardware in order to implement DMM Shield functionality. The library has multiple modules, corresponding to different hardware modules.
The library is designed to run on the Digilent uC32 board, which acts as a system board for DMM Shield. The DMM Shield is attached to uC32, that accesses the DMM Shield using digital pins.

Overview

Prerequisites

Hardware

  • uC32 board
  • Mini-USB cable
  • DMM Shield
  • Microchip programmer ex. PICkit™ 3 In-Circuit Debugger
  • 100 mils pitch 6 pin header to connect Microchip programmer to the stagger wholes programming connector JP3.

Software

  • MPLAB X IDE

Downloads

PIC32 DMM Shield Project Repository – Git Repo


Library Overall Structure

The following image shows the library modules and the links between them.

Description

The diagram from Library Overall Structure shows the general structure of the DMM Shield library, the library modules, and the relations between them.
The diagram is using green arrows for the calls from outside (calls to library functions provided as a public interface) and blue arrows for the inside calls (function calls between different modules).
From the perspective of providing to the user the access to the hardware, there as three stacked layers.
The GPIO module, SPI module and UART module belong to the lowest level, which can be seen as the Data layer. The GPIO module provides a direct connection to the hardware digital pins, while the SPI module implements the SPI bit-bang protocol over the digital pins. The UART module provides the communication from the UART interface of the system board.
The DMM module, EPROM module, CALIB module and SERIALNO module belong to the middle layer, which can be seen as the Business layer.
The DMM module and EPROM module functionality is implemented using the SPI module.
The CALIB module functionality is implemented using the DMM module and EPROM module.
The SERIALNO module functionality is implemented using the EPROM module.

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 DMM Shield functionality. The main program calls a command interpreter from DMMCMD module, that provides access to all DMM Shield functionality.

Library Usage as Modules Included in User Application

The user may choose to include different modules in specific applications. For example, the user may choose to include DMM module in order to perform DMM configuration and measurements, CALIB module to perform user calibration operations, or EPROM module in order to perform EPROM operations.

Library Modules

DMMCMD Module

The DMMCMD module implements a command interpreter that has these functions:

  1. It listens over UART for individual DMM Shield commands. The user will have to provide these commands using a terminal connected to the USB port corresponding to the connected uC32 board.
  2. The commands are recognized by DMMCMD module and implemented by calls to needed modules.
  3. 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 DMMCMD module, see DMMCalib.
Providing a value as a parameter must comply with 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 currently selected scale, otherwise the following error is returned: “ERROR, The provided value <value string> has a wrong measure unit”.
The function that implements value interpreting is DMM_InterpretValue.

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 DMMCMD module, see DMMMeasureRep.
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 “0.002456 V” for all of the voltage scales.

DMMConfig

Syntax:

“DMMConfig <Scale>”

Example:

“DMMConfig VoltageDC5”

Description:

The DMMConfig command configures the DMM for a specific scale.

Parameters:

The possible values from the <Scale> are shown in the Scale column of the following table:

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 VoltageAC30
13 VoltageAC5
14 VoltageAC500m
15 VoltageAC50m
16 CurrentDC5
17 CurrentAC5
18 Continuity
19 Diode
20 CurrentDC500m
21 CurrentDC50m
22 CurrentDC5m
23 CurrentDC500u
24 CurrentAC500m
25 CurrentAC50m
26 CurrentAC5m
27 CurrentAC500u

Answer:

Answer Meaning
“OK, Selected scale index is: <integer value>”
Example:
“OK, Selected scale index is: 8”
Success.
The provided value is the scale index .
“ERROR, Missing valid configuration: \“<provided value>\”” ERROR, the provided configuration is not valid.
The faulty string is provided between “”.
“ERROR, Invalid scale index” ERROR, invalid selected scale index.
“ERROR, DMM Configuration verify error” ERROR, the configuration verification failed.

DMMMeasureRep

Syntax:

“DMMMeasureRep”

Description:

This commands initiates a session of repetitive measurements. These repetitive measurements will be performed until the DMMMeasureStop command is issued.

Parameters:

<none>

Answer:

  1. After issuing the command: “OK, Measure repeated”
  2. Repeatedly, for each measurement:
Answer Meaning
“Value: <value, 6 decimals followed by unit>” The value included in the message is formatted as explained in Interpreting values provided as parameter chapter.
“ERROR, Invalid scale index” ERROR, invalid selected scale index.
“ERROR, Valid DMM data timeout” ERROR, a valid data was not received within the expected time.

DMMMeasureStop

Syntax:

“DMMMeasureStop”

Description:

This command terminates the repetitive measurements session initiated by DMMMeasureRep or DMMMeasureRaw commands.

Parameters:

<none>

Answer:

“OK, Measure stop”

DMMMeasureRaw

Syntax:

“DMMMeasureRaw”

Description:

This command 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 DMMMeasureStop command is issued.

Parameters:

<none>

Answer:

> - After issuing the command: “OK, Measure raw” > - Repeatedly, for each measurement:

Answer Meaning
“Value: <value, 6 decimals followed by unit>” The value included in the message is formatted as explained in Interpreting values provided as parameter chapter.
“ERROR, Invalid scale index” ERROR, invalid selected scale index.
“ERROR, Valid DMM data timeout” ERROR, valid data was not received within the expected time.

DMMMeasureAvg

Syntax:

“DMMMeasureAvg”

Description:

This commands performs one average measurement (taking the average value of a set of measurements).

Parameters:

<none>

Answer:

Answer Meaning
“Avg. Value: <value, 6 decimals followed by unit>” The value included in the message is formatted as explained in Interpreting values provided as parameter chapter.
“ERROR, Invalid scale index” ERROR, invalid selected scale index.
“ERROR, Valid DMM data timeout” ERROR, valid data was not received within the expected time.

DMMCalib

Syntax:

“DMMCalib<P, N or S> <reference value>”

Example:

“DMMCalibP 5.000115 V”

“DMMCalibN -5.001185”

“DMMCalibZ”

Description:

This command performs the positive, negative, or on zero calibration, depending on the character following DMMCalib command (‘P’, ‘N’ or ‘Z’). This is performed by initiating a measurement and then saving the measured value to be later processed when all the needed data will be present and the calibration will be finalized. For positive and negative calibration, a reference value is provided as a parameter, which is also saved together with the measured value.

Parameters:

<reference value, 6 decimals, followed by Unit> This parameter is only for positive and negative calibrations.
This is a character string containing a formatted value. For more details see Format of values provided as parameter chapter.

Answer:

Answer Meaning
“OK, Calibration on positive done. Reference: <reference value, 6 decimals, followed by Unit>, Measured: <measured value, 6 decimals, followed by Unit>, Dispersion: <dispersion, 2 decimals>%[Coeff: <Mult calibration coefficient, 6 decimals>, <Add calibration coefficient, 6 decimals>]“
Example:
“OK, Calibration on positive done. Reference: 5.000115 V, Measured: 5.108844 V, Dispersion: 0.02% Coeff: -0.067295, 0.043947”
Success.
<The message is dependent to the calibration type (positive, negative or on zero)>

The dispersion is computed as the difference between the measured and the reference values, divided by the scale range.


The calibration coefficients are appended at the end of the message only if this calibration finalizes a calibration process.

The values included in the message are formatted as explained in the Interpreting values provided as parameter chapter.
“OK, Calibration on negative done. Reference: <reference value, 6 decimals, followed by Unit>, Measured: <measured value, 6 decimals, followed by Unit>, Dispersion: <dispersion, 2 decimals>%[Coeff: <Mult calibration coefficient, 6 decimals>, <Add calibration coefficient, 6 decimals>]“
Example:
“OK, Calibration on negative done. Reference: -5.001185 V, Measured: -5.109310 V, Dispersion: 0.02%”
“OK, Calibration on zero done: Measured Val = <value, 6 decimals>, Dispersion <dispersion, 2 decimals>%[Coeff: <Mult calibration coefficient, 6 decimals>, <Add calibration coefficient, 6 decimals>]“
Example:
“OK, Calibration on zero done. Measured Value: - 0.000028 V, Dispersion: 0.00%”
“ERROR, Invalid scale index” ERROR, invalid selected scale index.
“ERROR, Valid DMM data timeout” ERROR, valid data was not received within the expected time.
“ERROR, The provided value \”<provided value string>\” has a wrong measure unit.“ <This message may occur just for positive and negative calibration>
ERROR, the measure unit does not match the scale unit. This shouldn’t occur if the reference value is correctly provided.
“ERROR, The provided value \”<provided value string>\” must have a measure unit.“ <This message may occur just for positive and negative calibration>
ERROR, the value must be followed by an Unit. This shouldn’t occur if the reference value is correctly provided.
“ERROR, Missing valid reference value: \”<provided value string>\“” <This message may occur just for positive and negative calibration>
ERROR, the provided reference value is not valid. This shouldn’t occur if the reference value is correctly provided.
“ERROR: Calibration measure dispersion error: Measured <measured value, 6 decimals, followed by Unit>, Reference: <reference value, 6 decimals, followed by Unit>, Dispersion: <Dispersion, 2 decimals>%, Max. dispersion: <Max Dispersion, 2 decimals>%” ERROR, the measurement dispersion is outside the expected limits.
The values are just for information, no need to be extracted.

DMMMeasureForCalib

Syntax:

“DMMMeasureForCalib<P or N>”

Example:

“DMMMeasureForCalibP”

or

“DMMMeasureForCalibN”

Description:

This command initiates the positive or negative (depending on the character following DMMCalib command: ‘P’ or ‘N’) measurement for calibration, depending on the character following DMMCalib command (‘P’ or ‘N’). This is performed by initiating a measurement and then saving the measured value to be later processed when all the needed data will be present and the calibration will be finalized. Compared to DMMCalib function, the calibration process is split into two steps:
- the calibration measurement is launched (using this command) prior declaring the reference value
- the reference value is later declared using DMMFinalizeCalib command.

Parameters:

<none>

Answer:

Answer Meaning
“OK, Calibration positive measurement done. Measured Value: <measured value, 6 decimals, followed by Unit>“
Example:
“Calibration positive measurement done. Measured Value: 5.108844 V”
Success.
<The message is dependent to the calibration type (positive or negative)>

The values included in the message are formatted as explained in the Interpreting values provided as parameter chapter.
“OK, Calibration negative measurement done. Measured Value: <measured value, 6 decimals, followed by Unit>“
Example:
“Calibration negative measurement done. Measured Value: -5.109310 V”
“ERROR, Invalid scale index” ERROR, invalid selected scale index.
“ERROR, Valid DMM data timeout” ERROR, a valid data was not received within the expected time.

DMMFinalizeCalib

Syntax:

“DMMFinalizeCalib<P or N> <reference value>”

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 DMMCalib function, the calibration process is split into two steps:
- the calibration measurement is launched (using DMMeasureForCalib command) prior declaring the reference value
- the reference value is later declared using this command.

Parameters:

<reference value, 6 decimals, followed by Unit> This parameter is only for positive and negative calibrations.
This is a character string containing a formatted value. For more details see Interpreting values provided as parameter chapter.

Answer:

Answer Meaning
OK, Calibration on positive done. Reference: <reference value, 6 decimals, followed by Unit>, Measured: <measured value, 6 decimals, followed by Unit>, Dispersion: <dispersion, 2 decimals>%[Coeff: <Mult calibration coefficient, 6 decimals>, <Add calibration coefficient, 6 decimals>]“
Example:
“OK, Calibration on positive done. Reference: 5.000115 V, Measured: 5.108844 V, Dispersion: 0.02% Coeff: -0.067295, 0.043947”
Success.
<The message is dependent to the calibration type (positive or negative)>
\\The calibration coefficients are appended at the end of the message only if this calibration finalizes a calibration process.

The dispersion is computed as the difference between the measured and the reference values, divided by the scale range.

The values included in the message are formatted as explained in the Interpreting values provided as parameter chapter.
“OK, Calibration on negative done. Reference: <reference value, 6 decimals, followed by Unit>, Measured: <measured value, 6 decimals, followed by Unit>, Dispersion: <dispersion, 2 decimals>%[Coeff: <Mult calibration coefficient, 6 decimals>, <Add calibration coefficient, 6 decimals>]“\\Example:
“OK, Calibration on negative done. Reference: -5.001185 V, Measured: -5.109310 V, Dispersion: 0.02%”
“ERROR, Invalid scale index” ERROR, invalid selected scale index.
“ERROR, The provided value \”<provided value string>\” has a wrong measure unit.“ <This message may occur just for positive and negative calibration>
ERROR, the measure unit does not match the scale unit. This shouldn’t occur if the reference value is correctly provided.
“ERROR, The provided value \”<provided value string>\” must have a measure unit.“ <This message may occur just for positive and negative calibration>
ERROR, the value must be followed by an Unit. This shouldn’t occur if the reference value is correctly provided.
“ERROR, Missing valid reference value: \”<provided value string>\“” <This message may occur just for positive and negative calibration>
ERROR, the provided reference value is not valid. This shouldn’t occur if the reference value is correctly provided.
“ERROR: Calibration measure dispersion error: Measured <measured value, 6 decimals, followed by Unit>, Reference: <reference value, 6 decimals, followed by Unit>, Dispersion: <Dispersion, 2 decimals>%, Max. dispersion: <Max Dispersion, 2 decimals>%” ERROR, the measurement dispersion is outside the expected limits.
The values are just for information, no need to be extracted.

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:

<none>

Answer:

Answer Meaning
“OK, <number of saved calibrations> calibrations written to EPROM”
Example:
“OK, 4 calibrations written to EPROM”
Success.
The message also communicates the number of calibrations performed since the last power-up and not saved to EPROM.
“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:

<none>

Answer:

Answer Meaning
“OK, EPROM Calibration data is verified” Success, the calibration data is identical with the user calibration data stored in EPROM.
“ERROR, EPROM Calibration data mismatch values found” ERROR, the calibration data is different than the user calibration data stored in EPROM.
“ERROR, EPROM write data ready timeout ” ERROR, the write to EPROM failed.
“ERROR, Invalid EPROM magic number” ERROR, the magic number was not properly retrieved.
“ERROR, Invalid EPROM checksum” ERROR, the checksum does not match the content.

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:

<none>

Answer:

Answer Meaning
“OK, Calibration data is exported <one line for each scale, showing “<Scale index>, <Multiplicative calibration coefficient>, <Additive calibration coefficient>”>
Example:
OK, Calibration data is exported
00, 0.000000, 0.000000
01, 0.000000, 0.000000
02, 0.000000, 0.000000
03, 0.000000, 0.000000
04, 0.000000, 0.000000
05, 0.000000, 0.000000
06, 0.000000, 0.000000
07, 0.000000, 0.000000
08, -0.021222, -0.000072
09, -0.032600, 0.000125
10, 0.000000, 0.000000
11, 0.000000, 0.000000
12, -0.062725, 0.004843
13, 0.000000, 0.000000
14, 0.000000, 0.000000
15, 0.000000, 0.000000
16, 0.000000, 0.000000
17, 0.000000, 0.000000
18, 0.000000, 0.000000
19, 0.000000, 0.000000
20, 0.000000, 0.000000
21, 0.000000, 0.000000
22, 0.000000, 0.000000
23, 0.000000, 0.000000
24, 0.000000, 0.000000
25, 0.000000, 0.000000
26, 0.000000, 0.000000
Success, the tabular data shows signed values, 6 digits for calibration coefficients.
“ERROR, EPROM Calibration data mismatch values found” ERROR, the calibration data is different than the user calibration data stored in EPROM.
“ERROR, Invalid EPROM magic number” ERROR, the magic number was not properly retrieved when reading from EPROM.
“ERROR, Invalid EPROM checksum” ERROR, the checksum does not match the content when reading from EPROM.

DMMImportCalib

Syntax:

“DMMImportCalib <Scale index>, <Multiplicative calibration coefficient>, <Additive calibration coefficient>”

Example:

“DMMImportCalib 10, 0.021222, -0.000125”

Description:

This command imports the calibration data for a specific scale. It does not save the calibration data in EPROM.

Parameters:

<Scale index>the index of the scale whose coefficients are imported (integer number)
<Multiplicative calibration coefficient>the multiplicative coefficient to be imported (signed float value)
<Additive calibration coefficient>the additive coefficient to be imported (signed float value)

Answer:

Answer Meaning
“OK, Scale: <scale index>, Calibration coefficients: Mult = <Multiplicative calibration coefficient>, Add = <Additive calibration coefficient>”
Example:
“OK, Scale: 10, Calibration coefficients: Mult = 0.021222, Add = -0.000125”
Success, the calibration data is imported, the message communicates the scale index (integer value), the calibration multiplicative coefficient (6 decimals signed value) and the calibration additive coefficient (signed float value)
“ERROR, Invalid value, provide an integer number for the first token, corresponding to scale index”The integer number corresponding to the scale index was not properly provided
“ERROR, Invalid value, provide a float number for the second token, corresponding to Mult. coefficient”The float number corresponding to the Mult. coefficient was not properly provided
“ERROR, Invalid value, provide a float number for the third token, corresponding to Add. coefficient”The float number corresponding to the Add. coefficient was not properly provided
“ERROR, The expected parameters were not provided on the UART command” ERROR, the three expected parameters were not provided.

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:

<none>

Answer:

Answer Meaning
“OK, Calibration data restored from FACTORY EPROM” Success, the calibration data is restored from the Factory Calibration area of EPROM.
“ERROR, Invalid EPROM magic number” ERROR, the magic number was not properly retrieved.
“ERROR, Invalid EPROM checksum” ERROR, the checksum does not match the content.
“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:

<none>

Answer:

Answer Meaning
“OK, SerialNo = \”<12 characters serial number>\””
Example:
“OK, SerialNo = “210356A76C0C”“
Success, the message contains serial number information.
“ERROR, Invalid EPROM magic number” ERROR, the magic number was not properly retrieved.
“ERROR, Invalid EPROM checksum” ERROR, the checksum does not match the content.

DMM Module

The DMM library module implements DMM (digital multimeter) related functions.
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 Calibration Procedure for more details.
In order to implement the custom SPI communication, the DMM module accesses functions implemented in SPI Module. It uses digital IO pins exposed in the DMM Shield connector: CS_DMM (SPI chip select), DO (SPI MISO), DI (SPI MOSI) and CLK (SPI CLK). While the chip select is specific to DMM, the SPI lines (data and clock) are shared with EPROM Device.
The DMM module functions are accessed by CALIB Module and DMMCMD module functions. See Library overall structure for more details about the interaction between modules.
See DMM device for more details about DMM functionality.
See DMM Measured Values for more information regarding the values retrieved from DMM.
Read DMM_DGetValue for more details about the measured values.

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:

<none>

Return Value:

<none>

Description:

This function initializes the DMM module.

It calls the SPI_Init() function to initialize the digital pins used by DMM Shield.

Example:

#include “dmm.h”

DMM_Init();

DMM_SetScale

Synopsis:

uint8_t DMM_SetScale(int idxScale);

Parameters:

int idxScalethe Scale index

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS 0success
ERRVAL_DMM_IDXCONFIG 0xFC wrong scale index
ERRVAL_DMM_CFGVERIFY 0xF5DMM 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 “dmm.h”

bErrCode = DMM_SetScale(idxCfg);

DMM_GetCurrentScale

Synopsis:

int DMM_GetCurrentScale();

Parameters:

<none>

Return Value:

int

positive valuecurrent scale index
-1if 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 “dmm.h”

int idxScale = DMM_GetCurrentScale();

DMM_DGetValue

Synopsis:

double DMM_DGetValue(uint8_t *pbErr);

Parameters:

uint8_t *pbErrPointer to the error parameter

The *pbErr parameter can be set to:

ERRVAL_SUCCESS 0success
ERRVAL_DMM_VALIDDATATIMEOUT 0xFAwrong scale index
ERRVAL_DMM_IDXCONFIG 0xFCwrong 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.

This function compensates the not linear behavior of VoltageDC50 scale.

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 “dmm.h”

double dVal = DMM_DGetValue(&bErr);

DMM_DGetAvgValue

Synopsis:

double DMM_DGetAvgValue(uint8_t *pbErr);

Parameters:

int cbSamplesThe number of values to be used for the average value
uint8_t *pbErrPointer to the error parameter

The *pbErr parameter can be set to:

ERRVAL_SUCCESS 0success
ERRVAL_DMM_VALIDDATATIMEOUT 0xFAwrong scale index
ERRVAL_DMM_IDXCONFIG 0xFCwrong 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, for the specified number of samples.

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 converter 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 “dmm.h”

double dVal;

dVal = DMM_DGetAvgValue(20, &bResult);

DMM_SetUseCalib

Synopsis:

void DMM_SetUseCalib(uint8_t f);

Parameters:

uint8_t f1 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:

<none>

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.h”

DMM_SetUseCalib(0);

DMM_CheckAcceptedMeasurementDispersion

Synopsis:

uint8_t DMM_CheckAcceptedMeasurementDispersion(double dMeasuredVal, double dRefVal, double *pDispersion);

Parameters:

double dMeasuredValThe measured value
double dRefValThe reference value
double *pDispersionPointer to receive the measured value dispersion

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index
ERRVAL_DMM_MEASUREDISPERSION0xF1The measurement dispersion exceeds accepted range

Description:

This function checks if the measurement dispersion exceeds the accepted range.

The dispersion is computed as the difference between 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 the dispersion is in the accepted range, the function returns ERRVAL_SUCCESS.

Example:

#include “dmm.h”

bResult = DMM_CheckAcceptedMeasurementDispersion( *pMeasuredVal, dRefVal, pDispersion);

DMM_FormatValue

Synopsis:

uint8_t DMM_FormatValue(double dVal, char *pString);

Parameters:

double dValThe value to be formatted
char *pStringThe string to get the formatted value
uint8_t fUnitflag to indicate if unit information should be added
- not 0 - add unit / subunit
- 0 - do not add unit

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong 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 DMM_DGetValue.

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 “OVERLOAD” string is used for all scales except Continuity.

If dVal is +/- INFINITY (converter values are outside expected range), then “OPEN” string is used for Continuity scale.

The function returns ERRVAL_DMM_IDXCONFIG if the current scale is not valid.

For example it formats the value 0.0245678912 into the “24.678912 mV” if the current scale is VoltageDC50m.

Example:

#include “dmm.h”

DMM_FormatValue(dRefVal, szRefVal);

DMM_InterpretValue

Synopsis:

uint8_t DMM_InterpretValue(char *pString, double *pdVal);

Parameters:

char *pStringthe string containing the value to be interpreted
double *pdValpointer to a double variable to get the value

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index
ERRVAL_CMD_VALWRONGUNIT0xF4The provided value has a wrong measure unit.
ERRVAL_CMD_VALFORMAT0xF2The 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 “OVERLOAD” or “OPEN”, then INFINITY value is returned.

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 “24.678912 mV” and returns the value 0.0245678912 if the current scale is any of the Voltage scales.

Example:

#include “dmm.h”

bErrCode = DMM_InterpretValue(szVal, &dRefVal);

CALIB module

CALIB module groups functions that implement calibration functionality of DMM Shield. The functions are implemented in calib.c source file.
The DMM Shield measuring hardware has errors due to DMM device and DMM Shield additional components.
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 DMM module).
For each scale, calibration is done in multiple points: positive, on zero 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.
Calibration is done by calling calibration functions to inform the system that in a specific moment the reference values are applied to the DMM Shield connectors. The library functions initiate a DMM Shield measurement and then the measured value and reference value are stored, to be used when all the calibration data exists.

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, collecting (as a result of calls to calibration functions) all the necessary data until a calibration is complete. This has the following fields:

  • double Calib_Ms_Zero;
  • 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:

<none>

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_EPROM_MAGICNO0xFDwrong Magic No. when reading data from EPROM
ERRVAL_EPROM_CRC0xFEwrong 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 “calib.h”

bResult = CALIB_Init();

CALIB_CalibOnPositive

Synopsis:

uint8_t CALIB_CalibOnPositive(double dRefVal, double *pMeasuredVal, uint8_t bEarlyMeasurement, double *pDispersion, uint8_t fIgnoreDispersion);

Parameters:

double dRefVal The reference value, to be used in the calibration procedure
double *pMeasuredVal Pointer to a double variable that will store the measured value
uint8_t bEarlyMeasurement Parameter indicating if an early measurement was performed:
- non 0 - An early measurement was performed.
- 0 - An early measurement was not performed.
double *pDispersion Pointer to a double variable that will store the measured value dispersion
uint8_t fIgnoreDispersion Flag used to request the dispersion check to be ignored:
- non 0 - Skip the dispersion check.
- 0 - Perform the dispersion check.

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index
ERRVAL_DMM_VALIDDATATIMEOUT0xFAvalid data DMM timeout
ERRVAL_CMD_VALMISSINGUNIT0xF3The provided value does not contain a measure unit.
ERRVAL_DMM_MEASUREDISPERSION0xF1The calibration measurement dispersion exceeds accepted range.
ERRVAL_CALIB_MISSINGMEASUREMENT0xF0A 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, and in this case parameter bEarlyMeasurement must be set to a non 0 value.

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 “calib.h”

bErrCode = CALIB_CalibOnPositive(dRefVal, &dMeasuredVal, 0, &dispersion, 0);



CALIB_CalibOnNegative

Synopsis:

uint8_t CALIB_CalibOnNegative(double dRefVal, double *pMeasuredVal, uint8_t bEarlyMeasurement, double *pDispersion, uint8_t fIgnoreDispersion);

Parameters:

double dRefVal The reference value, to be used in the calibration procedure
double *pMeasuredVal Pointer to a double variable that will store the measured value
uint8_t bEarlyMeasurement Parameter indicating if an early measurement was performed:
- non 0 - An early measurement was performed.
- 0 - An early measurement was not performed.
double *pDispersion Pointer to a double variable that will store the measured value dispersion
uint8_t fIgnoreDispersion Flag used to request the dispersion check to be ignored:
- non 0 - Skip the dispersion check.
- 0 - Perform the dispersion check.

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index
ERRVAL_DMM_VALIDDATATIMEOUT0xFAvalid data DMM timeout
ERRVAL_CMD_VALMISSINGUNIT0xF3The provided value does not contain a measure unit.
ERRVAL_DMM_MEASUREDISPERSION0xF1The calibration measurement dispersion exceeds accepted range.
ERRVAL_CALIB_MISSINGMEASUREMENT0xF0A 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, and in this case parameter bEarlyMeasurement must be set to any non 0 value.

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 “calib.h”

bErrCode = CALIB_CalibOnNegative(dRefVal, &dMeasuredVal, 0, &dispersion, 0);



CALIB_CalibOnZero

Synopsis:

uint8_t CALIB_CalibOnZero(double *pMeasuredVal, double *pDispersion, uint8_t fIgnoreDispersion);

Parameters:

double *pMeasuredVal Pointer to a double variable that will store the measured value
double *pDispersion Pointer to a double variable that will store the measured value dispersion
uint8_t fIgnoreDispersion Flag used to request the dispersion check to be ignored:
- non 0 - Skip the dispersion check.
- 0 - Perform the dispersion check.

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index
ERRVAL_DMM_VALIDDATATIMEOUT0xFAvalid data DMM timeout
ERRVAL_DMM_MEASUREDISPERSION0xF1The calibration measurement dispersion exceeds accepted range.

Description:

This function implements the calibration on zero 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 “calib.h”

bErrCode = CALIB_CalibOnZero(&dMeasuredVal, &dispersion, 0);



CALIB_MeasureForCalibPositiveVal

Synopsis:

uint8_t CALIB_MeasureForCalibPositiveVal(double *pMeasuredVal);

Parameters:

double *pMeasuredVal Pointer to a double variable that will store the measured value

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index
ERRVAL_DMM_VALIDDATATIMEOUT0xFAvalid 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 “calib.h”

bResult = CALIB_MeasureForCalibPositiveVal(pMeasuredVal);



CALIB_MeasureForCalibNegativeVal

Synopsis:

uint8_t CALIB_MeasureForCalibNegativeVal(double *pMeasuredVal);

Parameters:

double *pMeasuredVal Pointer to a double variable that will store the measured value

Return Value:

uint8_t

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index
ERRVAL_DMM_VALIDDATATIMEOUT0xFAvalid 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 “calib.h”

bResult = CALIB_MeasureForCalibNegativeVal(pMeasuredVal);

CALIB_WriteAllCalibsToEPROM_User

Synopsis:

uint8_t CALIB_WriteAllCalibsToEPROM_User();

Parameters:

<none>

Return Value:

uint8_t - Number of modified calibrations or the error code:

Positive value < 270success, number of modified calibration since last save
ERRVAL_EPROM_WRTIMEOUT0xFFEPROM 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 “calib.h”

bErrCode = CALIB_WriteAllCalibsToEPROM_User();

CALIB_ReadAllCalibsFromEPROM_User

Synopsis:

uint8_t CALIB_ReadAllCalibsFromEPROM_User();

Parameters:

<none>

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_EPROM_MAGICNO0xFDwrong Magic No. when reading data from EPROM
ERRVAL_EPROM_CRC0xFEwrong 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 “calib.h”

bResult = CALIB_ReadAllCalibsFromEPROM_User();

CALIB_RestoreAllCalibsFromEPROM_Factory

Synopsis:

uint8_t CALIB_RestoreAllCalibsFromEPROM_Factory();

Parameters:

<none>

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_EPROM_MAGICNO0xFDwrong Magic No. when reading data from EPROM
ERRVAL_EPROM_CRC0xFEwrong CRC when reading data from EPROM
ERRVAL_EPROM_WRTIMEOUT0xFFEPROM 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 “calib.h”

bResult = CALIB_ReadAllCalibsFromEPROM_User();

CALIB_VerifyEPROM

Synopsis:

uint8_t CALIB_VerifyEPROM();

Parameters:

<none>

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_EPROM_VERIFY0xF7EPROM verify error
ERRVAL_EPROM_MAGICNO0xFDwrong Magic No. when reading data from EPROM
ERRVAL_EPROM_CRC0xFEwrong 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 “calib.h”

bErrCode = CALIB_VerifyEPROM();

CALIB_ExportCalibs_User

Synopsis:

uint8_t CALIB_ExportCalibs_User(char *pSzCalibs);

Parameters:

char *pSzCalibspointer to a character string to hold the exported sequence

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_EPROM_MAGICNO0xFDwrong Magic No. when reading data from EPROM
ERRVAL_EPROM_CRC0xFEwrong 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 “calib.h”

char calExp[1024];

bErrCode = CALIB_ExportCalibs_User(calExp);

CALIB_ExportCalibs_Factory

Synopsis:

uint8_t CALIB_ExportCalibs_Factory(char *pSzCalibs);

Parameters:

char *pSzCalibspointer to a character string to hold the exported sequence

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_EPROM_MAGICNO0xFDwrong Magic No. when reading data from EPROM
ERRVAL_EPROM_CRC0xFEwrong 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 “calib.h”

char calExp[1024];

bErrCode = CALIB_ExportCalibs_Factory(calExp);

CALIB_ImportCalibCoefficients

Synopsis:

uint8_t CALIB_ImportCalibCoefficients(int idxScale, float fMult, float fAdd);

Parameters:

int idxScalethe Scale index
float fMultthe calibration MULT coefficient
float fAddthe calibration ADD coefficient

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_DMM_IDXCONFIG0xFCwrong scale index

Description:

This function imports the MULT and ADD calibration coefficients, for the provided Scale.

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 “calib.h”

bErrCode = CALIB_ImportCalibCoefficients(10, 0.021222, -0.000125);

EPROM module

The DMM Shield 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 DMM Shield 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 DMM module). The EPROM is used to store the following system information:

  • Serial number:
    • 12 bytes payload (see Serial Number)
    • 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 CALIB module.
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) Size Content
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 at address 0. These functions are protected against writing over the system areas detailed above.

EPROM_Init

Synopsis:

void EPROM_Init();

Parameters:

<none>

Return Value:

<none>

Description:

This function initializes the EPROM module.

It calls the SPI_Init() function to initialize the digital pins used by DMM Shield.

This function is called by CALIB_Init() and SERIALNO_Init().

The function guards against multiple calls using a static flag variable.

Example:

#include “eprom.h”

EPROM_Init();

EPROM_ReadWords

Synopsis:

void EPROM_ReadWords(uint8_t bAddress, uint16_t *prgVals, int cwVals)

Parameters:

uint8_t bAddressthe word address of the EPROM memory location to be read
uint16_t *prgValspointer to an array of 16 bits values, to store the values read from EPROM
int cwValsnumber of 16 bits values to be read in EPROM

Return Value:

<none>

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.h”

EPROM_ReadWords(0, (uint16_t *)&pUserData, 31);

EPROM_WriteWords

Synopsis:

uint8_t EPROM_WriteWords(uint8_t bAddress, uint16_t *prgVals, int cwVals);

Parameters:

uint8_t bAddressthe word address of the EPROM memory location to be written
uint16_t *prgValspointer to an array of words (16 bits values), to be written in EPROM
int cwValsnumber of words to be written in EPROM

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS 0success
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 ERRVAL_EPROM_ADDR_VIOLATION if write is attempted over the system reserved areas of EPROM.

Otherwise, the function returns ERRVAL_SUCCESS for success or ERRVAL_EPROM_WRTIMEOUT when EPROM is not answering with the write successful message.

Example:

#include “eprom.h”

bErrorCode = EPROM_WriteWords(0, (uint16_t *)&pUserData, 31);

EPROM_WriteEnable

Synopsis:

void EPROM_WriteEnable();

Parameters:

<none>

Return Value:

<none>

Description:

This function implements the EWEN (Write Enable) EPROM instruction.

Call this function before any EPROM write operations.

Example:

#include “eprom.h”

EPROM_WriteEnable();

EPROM_WriteDisable

Synopsis:

void EPROM_WriteDisable();

Parameters:

<none>

Return Value:

<none>

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.h”

EPROM_WriteDisable();

EPROM_Erase

Synopsis:

void EPROM_Erase(uint8_t bAddress);

Parameters:

uint8_t bAddressthe word address of the EPROM memory location to be erased

Return Value:

<none>

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.h”

EPROM_Erase(0x10);

SERIALNO Module

The SERIALNO module implements the functions related to Serial Number data (stored during factory process into the EPROM memory). See Serial Number for more details about the information contained in the Serial Number. The module provides an initialization function (SERIALNO_Init) and a data retrieving function SERIALNO_ReadSerialNoFromEPROM. It uses the EPROM module in order to access EPROM memory.

Serial Number

Each board has a unique serial number information (called SerialNo), built as follows:

  • 6 characters DMM Shield 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 SERIALNO module and EPROM module.

SERIALNO_Init

Synopsis:

void SERIALNO_Init();

Parameters:

<none>

Return Value:

<none>

Description:

This function initializes the SERIALNO module.

It calls the initialization function for the EPROM module.

Example:

#include “SERIALNO.h”

SERIALNO_Init();

SERIALNO_ReadSerialNoFromEPROM

Synopsis:

uint8_t SERIALNO_ReadSerialNoFromEPROM(char *pSzSerialNo);
char *pSzSerialNopointer to a character string to hold the serial number sequence

Return Value:

uint8_t - The error code:

ERRVAL_SUCCESS0success
ERRVAL_EPROM_MAGICNO0xFDwrong Magic No. when reading data from EPROM
ERRVAL_EPROM_CRC0xFEwrong CRC when reading data from EPROM

Description:

This function retrieves the Serial Number information (12 characters) from EPROM .

Therefore is important that the caller of this function allocates enough space in pSzSerialNo.

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 “SERIALNO.h”

char szSerialNo[13];
bResult = SERIALNO_ReadSerialNoFromEPROM(szSerialNo);

SPI Module

The SPI module implements the SPI communication needed for DMMCMD module and EPROM module.
It uses the GPIO module for configuring and accessing the output digital lines SPI clock and SPI data out, and the input digital line SPI data in.
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.
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 SPI module in order to implement the custom SPI access, by DMM module that accesses DMM SPI chip select and relays digital lines and by EPROM module that accesses EPROM SPI chip select digital line.
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 communication 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 an 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't have to be included in an application that doesn't need communication (for example an application that uses an LCD connected to the uC32 board using the shield connector). We recommend initializing the module at 9600 baud rate for a basic application.
The module is only accessed by DMMCMD module.
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 baudUART baud rate
for example 9600 corresponds to 9600 baud

Return Value:

<none>

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 a digital output.

The UART_RX digital pin is configured as a 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.h”

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:

<none>

Description:

This function transmits all the characters from a zero terminated string over UART1.
The terminator character is not sent.

Example:

#include “uart.h”

UART_PutString(“Hello World\r\n”);

UART_GetString

Synopsis:

uint8_t UART_GetString(char* pchBuff, int cchBuff)

Parameters:

char* pchBuffpointer to a char buffer to hold the received zero terminated string
int cchBuffsize of the buffer to hold the zero terminated string

Return Value:

<none>

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 “uart.h”

cchi = UART_GetString(uartCmd, 0x40);

Appendix: DMM Scales

DMM Shield 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 DMM Measured Values for these columns.

No. Scale Formatted values (provided by DMM_FormatValue function) Values provided by DMM_DGetValue function
Valid valuesUnitOut of scale
1 Resistance50M Signed value, 6 decimalsMOhm“OVERLOAD”Valid values: corresponding to the Ohm unit
Out of scale values: INFINITY
2 Resistance5M MOhm
3 Resistance500k kOhm
4 Resistance50k kOhm
5 Resistance5k kOhm
6 Resistance500 Ohm
7 Resistance50 Ohm
8 VoltageDC50 Signed value, 6 decimalsV“OVERLOAD”Valid values: corresponding to the V unit
Out of scale values: INFINITY
9 VoltageDC5 V
10 VoltageDC500m mV
11 VoltageDC50m mV
12 VoltageAC30 V
13 VoltageAC5 V
14 VoltageAC500m mV
15 VoltageAC50m mV
19 Diode V
18 Continuity Signed value, 6 decimals <when contact exists on probes>
This is similar to a resistance scale.
Ohm“OPEN” <when no contact on probes>Valid values (contact on probes): corresponding to the Ohm unit
Out of scale values (no contact on probes): INFINITY
16 CurrentDC5 Signed value, 6 decimalsA“OVERLOAD”Valid values: corresponding to the A unit
Out of scale values: INFINITY
17 CurrentAC5 A
20 CurrentDC500m mA
21 CurrentDC50m mA
22 CurrentDC5m mA
23 CurrentDC500u uA
24 CurrentAC5 A
25 CurrentAC500m mA
26 CurrentAC50m mA
27 CurrentAC5m mA
28 CurrentAC500u uA

Additional Resources