RPICTlib

From lechacal
Revision as of 17:48, 27 November 2020 by Administrator (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Version History

  • 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

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.

uint8_t ADC_BITS = 10; 
uint16_t ADC_COUNTS (1 << ADC_BITS);
uint16_t ADC_REF = 3300;   

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.