RPICTlib

From lechacal
Jump to navigation Jump to search


Version History

  • V1.5.0
    • Major changes on sensor definition.
    • An object has been created to define sensor arrays. Memory improvement for tall stacks.
    • Phasecal has been modified to be less memory greedy.
    • 3 phase noce now support Phasecal.
  • V1.4.1
    • Added support for model identification in configuration 0xB5.
  • V1.4.0
    • Low pass filter for offset can not be set in sketch.
    • Added adc_definition function to setup ADC from sketch.
    • Frequency is now a computation on its own and no longer part of a power node.
  • V1.3.0
    • Low pass filter for offset is now a parameter.
    • Some minor code optimisation.
    • Support for 3 Phase in 2 and 3 watt meter.
  • V1.2.0
    • Now uses standard SPI library for querying MCP3208.
    • Minor optimisations.
  • V1.1.0
    • Frequency Support.
    • ADC Reference can now be set. (Needed for RPICT7V1 Version 4).
    • Various code optimisation.
    • CurrentNode now called SignalNode (We figured out this can equally measure Voltage as well).
  • V1.0.1
    • Modified timing control. Now uses better sync checks.
    • Added support for computing Irms alone with PowerNode class. Was missing on previous version.
    • mcp3208 now reading a bit faster. Using full bit banging now.
  • V1.0.0
    • Initial version

Download

RPICTlib_v1.1.0.zip

RPICTlib_v1.2.0.zip

RPICTlib_v1.3.0.zip

RPICTlib_v1.4.0.zip

RPICTlib_v1.4.1.zip

RPICTlib_v1.5.0.zip

Usage

Definition and initialisation

Definitions

The library must called in the arduino sketch with the following include.

#include "RPICTlib.h"

Three compiler variables must also be defined.

Before v1.4.0

uint8_t ADC_BITS = 12; 
uint16_t ADC_COUNTS (1 << ADC_BITS);
uint16_t ADC_REF = 4096; 

From v1.4.0

  adc_definition(12, 4096);

ADC_BITS is 10 for the RPICT board with attiny84 and 12 for the RPICT with mcp3208.

ADC_REF is either 3300 or 4096 depending on the board type.

Classes

There are four classes to construct computation nodes. These are

  • SignalNode
  • PowerNode
  • SignalNode_mcp3208
  • PowerNode_mcp3208

An example where CT1 is a simple rms computation node:

SignalNode CT1;

You might take a look into the RPICTlib.h file for more detailed information on these classes.

Initialisation

The begin function is used to initialise the computation node. Usually in the setup section of the Arduino sketch. For example:

CT1.begin(ct1, 83.33);

ct1 being the I/O pin of ct1 and 83.33 the calibration value.

Computation Examples

SignalNode

The SignalNode class is used to compute the RMS value of a signal. It can equally be current or voltage regardless.

Intended for boards that uses the ADC of the MCU directly. In particular all RPICT with attiny84 (RPICT3T1, RPICT3V1, RPIZ_CT3T1, RPIZ_CT3V1, RPICT4T4)

calcRMS is the function to call to run the computation.

CT1.calcRMS(N_SAMPLES, sInterval);

where

  • N_SAMPLES is the number of samples to collect to compute the RMS signal.
  • sInterval is the sampling interval in microseconds. Usual values are 400us for attiny84 and 300us for mcp3208.

See the link below for a working example.

RPICTlib_Example_01.ino

SignalNode_mcp3208

Same as SignalNode above but for RPICT unit using mcp3208 (RPICT7V1, RPICT4V3, RPICT8, RPIZ_CT4V3).

See the link below for a working example.

RPICTlib_Example_02.ino

PowerNode

The PowerNode is a class using 2 signals. One Current and one Voltage to compute AC power. This result in obtaining ActivePower, ApparentPower, ReactivePower, PowerFactor, Irms, Vrms.

Intended for board that uses the ADC of the MCU directly. In particular all RPICT with attiny84 (RPICT3T1, RPICT3V1, RPIZ_CT3T1, RPIZ_CT3V1, RPICT4T4)

Three computation functions can be run.

  • calcVI -> computes Power. Provides ActivePower, Irms, Vrms. (Power Factor, Apparent and Reactive power can be deduce from them).
  • calcIrms -> Computes Irms only. Useful for lightweight operations.
  • calcFreq -> computes frequency of voltage signal.

See the link below for a working example.

RPICTlib_Example_03.ino

PowerNode_mcp3208

Same as PowerNode above but for RPICT unit using mcp3208 (RPICT7V1, RPICT4V3, RPICT8, RPIZ_CT4V3).

See the link below for a working example.

RPICTlib_Example_04.ino

Error management

All the computation function mentioned above return an error number if they fail. For example one could code

CT1.calcRMS(N_SAMPLES, sInterval);
if (CT1.err) {Serial.println(CT1.err);}

Possible error and their meaning is shown below.

Error Number Error Type
0 No error.
1 Timing issue. The computation can not cope with the sampling interval set. Increase sInterval to avoid this.
2 Out of limit. One of the sensor involved in the computation has reached the top of the range.
3 Frequency computation only. Could not find a clear polarity. Signal detection has been waiting for a clear (+) or (-) for more than a period of cycle. Usually happen if sensor is absent.
4 Frequency computation only. Could not find first zero crossing. Timeout after one period of cycle.
5 Frequency computation only. Detected first zero crossing but change of polarity is not clear enough. Timeout after one period of cycle.
6 Frequency computation only. Could not find second zero crossing. Timeout after one period of cycle.