Axino Test Bench
Electronics snippets and schematics from Axino-Tech
These are circuits, ideas and sub-systems that I have developed. They are intended to be both educational and to stimulate ideas and interest. They are not fully evolved projects with complete constructional details. Where AC mains wiring is involved, proper safety precautions must be observed if one is reproducing the design. All Axino-Tech articles, including reviews and tests may be accessed from the Articles tab on the home page.
Battery powered light flicker meter
LED lighting fixtures, as well as fluorescent lights can flicker, usually imperceptibly, but may, even so, result in physiological effects on a human, especially if the light is bright and the exposure time long. If you are interested, you can read my article on the subject, accessed from the Axino-Tech articles page. This project is an attempt to build a simple flicker meter which reads out both the IEEE Percent Flicker and Flicker Index. Since recommended exposure limits vary with the flicker frequency, the limit is calculated and displayed for the detected frequency as well.
As usual with my projects, scope usually adjusts upward during development, so this unit reads out the visible lux levels, and estimates the percentage of UV and IR light present at the same time. Finally a six-channel visible light spectrum display shows the ratios of the six colours present. The display is a small Nextion touch screen and the microcontroller is a Teensy 3.2. The whole device is operated from a 9V alkaline battery with a 3 minute auto-off feature included.
The block diagram follows. I was not intending to describe the entire project in great detail, but are willing to fill in the gaps if anyone enquires.
The Teensy is fed 5V, and the pcb link to the USB 5V line is cut. 5V also drives the Nextion which draws around 85mA even when backed off to 80% brightness. This is responsible for most of the current drain. The Teensy running at 76MHz takes about 35mA which includes the 8mA for the breakouts and AFE sections, which all operate off the Teensy 3.3V output.
You can see the three sensor breakout modules at left while the opto-transistor for the actual flicker detection is on the right. The main parts I wanted to describe are the flicker detector AFE and the regulator/auto-off board.
Flicker detector AFE
The phototransistor used here is a Vishay TEPT4400, chosen because it has some IR rejection built-in. Any flicker produced at infra-red wavelengths is irrelevant to the result because it cannot be detected by the human eye. This detector has some, but not complete, rejection of IR, but is as good as could be found for an inexpensive solution. The typical photo-diode used in most light meter applications is not nearly as effective in this application and will produce only limited dynamic range.
The primary function of this AFE is to reproduce the lamp AC flicker voltage superimposed on the dc output, which is continuously normalised to exactly half-rail. This must be achieved over a wide range of light level. U1a, a rail-to-rail op-amp, amplifies the photo-transistor output using the common current to voltage converter topology. The transconductance gain of this stage is relatively low, for two reasons. First, the photo-transistor output levels are greater than the more common photo-diode circuit. Secondly, in normal usage, one has to gather the light from only the singular lamp source to be tested. For this, the detector is best held close to the light source, to minimise stray light from other sources. In order to ensure the dc output is at half rail (1.65V), a servo loop using op-amp U2 is included. U2 is a single rail-to rail op-amp with the added feature of having a precise half-rail divider appearing on pin 5. This becomes the integrator reference voltage. U2 will change the offset on U1a until U1a output voltage is exactly 1.65V and it will have any AC flicker from the light source superimposed. From this, the microcontroller can calculate the percent flicker and flicker index.
Additionally, the integrator output voltage at pin 6 is also fed to the microcontroller, which senses when U2 is near 0V (meaning the light is too strong) or near 3.3V, meaning the light is too weak. In practice, the circuit works over a fairly wide dynamic range of light levels.
Lastly, the other half of op-amp U1 is used as a squarer, to produce a square wave at the fundamental flicker frequency. The Teensy will measure the period of this square wave to calculate the IEEE percent flicker limit applicable to that frequency. There is no attempt in this project to include the relative levels of harmonics of the fundamental flicker in any calculation.
Power supply and auto-off
The 9V battery feeds the 5V low dropout regulator via an FET switch. The 5V regulator feeds both the Teensy Vin and the Nextion display. This regulator copes with battery voltage down to below 6.5V. An auto-off feature is very desirable here, because the loading on the battery is around 120mA; most of which is for the display.
The operator presses the start button, which pulls down the gate of the P-channel FET, switching it on. The RC network R2-C1 ensures that the FET remains on for about 3 seconds to ensure that the microcontroller has time to boot. In fact, the Teensy boots in less than a second, so the RC values could be reduced. Once the microcontroller has booted, it holds the base of transistor T2 high for 3 minutes, so that the FET switch remains on for that length of time. Once the transistor is turned off by the microcontroller, C1 discharges and the FET is turned off. This simple arrangement does have a transition through the FET linear region, but that transition time is only about 1 second and with 120mA load, there is no discernable heating of the FET device. Anyone wanting to control higher load currents in this way may need to heatsink the FET or add a schmitt-trigger arrangement to turn the FET off quickly. There is a voltage monitor (R5/R6) that the Teensy uses to make a battery monitor display on the Nextion. It also allows for a low voltage cutout, which turns off the FET switch if the battery is below 6.5V.
There are three screens on the Nextion for this project. They are selected by the operator by touch buttons on the screen itself. The home screen (which the system initialises to) is for light levels. The values are derived from the TSL2561 module and the UVM30a UV sensor module. Screen 2 is the flicker screen, derived from the flicker AFE. Finally the six-colour bar graph is displayed on Screen 3 along with the battery monitor. The numbers associated with each colour are simple percentages of the total of all six channels. These numbers have no particular units but do indicate whether a light source has a predominant colour.
Light levels Screen
Light spectra screen
The display update rate is a bit different on each screen. Slowest is the colour bar display which is due to the reading rate of the AS7262 sensor unit. It is set to 250ms update. Each of the sensors and the flicker calculation routine work quite well individually but there was some difficulty integrating them to work together. Like my previous Nextion project, it was not easy to signal to the Teensy which page was selected by the user, so that only the appropriate parts of the sketch were running at one time. Again the Nextion IO was used to pull down one line at a time, then used by the Teensy to tell which page was selected.
The lux readings correlate well with a commercial lux meter. The IR value relies on the TSL2561 module, which produces this from a separate IR sensitive photodiode and I had no way to verify that. Similarly, the analogue output of the UVM30a sensor is calibrated by the manufacturer and could not be verified by me. The flicker percentage readout agrees with my measurements of the analogue output with an oscilloscope. The frequency detector routine does get confused with multiple frequencies (such as from several light sources) but as long as a singular source is present, that reads correctly. It will read flicker frequencies up to at least 3kHz such as might occur in a PWM LED driver. Finally the colour levels are not in any way calibrated and simply indicate relative light output from the six light channels each having a 40nm bandwidth.
Project to build a DIY PAT unit
It started out as wanting to build a tester for RCD's (residual current devices). This would engage an unbalance load and measure the time it took for an RCD to trip. Then I decided to get a little ambitious and make the RCD test function as just one module of a complete appliance test unit. This turned out to be quite an undertaking for me but it is all but complete now and performs well. The tester comprises a number of analogue front-end (AFE) modules all interacting with an Arduino Mega 2560 micro controller, which operates a Nextion touch-screen display. Learning to program the Nextion and have it interact with the Arduino has been a challenge but much has been learned along the journey. This is a hobbyist project and I have no intention of promoting it further or even describing the entire unit in detail. It is hard to imagine anyone else wanting to build one anyway. However, the individual front-ends are described along with descriptions of what did and did not work adequately in case the methods prove to be of interest.
The block diagram follows. I expect it will be hard to read on some displays so a link to the pdf is included.
Link to the block diagram pdf
One of the design criteria that I use now is to make use of what I have around the workshop first. This helps to manage the budget. This will also be the answer to questions like 'why did he use one of those?' or 'why did he do it like that?'. So, with that in mind, here are the major subsections of the PAT.
This is a 3.2" TFT touch screen with 400 pixels x 240 pixels. There are a variety of models available and this is an 'enhanced' version having 8 I/O ports plus real-time-clock.
Itead Nextion home page. The displays are relatively cheap; this model goes for US$27. Apart from having a hobbyist-friendly price, the displays have on-board flash to hold the user program and all graphics, thus relieving the microcontroller of the job of transferring all that information. A simple 2 wire serial UART connection operating at up to 115200 baud is the only interconnection to the controller other than a 5V supply. The Nextion Editor running under Windows is available free via the same link. Although the documentation for the editor has improved considerably in recent times, there remains a learning curve for beginners. I do not claim to know everything about the display, but have gradually build up enough knowledge to make this project work.
The Nextion is capable of multi-pages. These may be selected directly from a button placed on a page, or called from the uC if necessary. In this project, the unit boots up on a 'home page' which then allows one to select any of six test function pages. The six buttons on the home page call up one of the other pages. Here are shots of each page.
Earth loop resistance page
Power measurement page
RCD test page
Leakage current page
Insulation test page
The Polarity module has a simple statement of the status of the AC input, so the screen for that is not shown. Of course the first things you notice are that the pages are all rather colourful and also that there is no consistent style across the pages. This is mostly because I wanted to experiment with various methods of displaying the data and the functions provided by the Nextion. Most of these buttons and text panels are made externally and imported to the editor. Although the Nextion editor provides for making buttons, text fields and other components, they are quite clunky and limited. Some of the rendering of built-in Nextion fonts can be seen on the 'Power measurement' page. All my page headers are created with an external graphics app, as are the buttons. I didn't spend a lot of time with making things look pretty but those created outside the Nextion editor look much better.
If a button has a 'not pressed' and a 'pressed' state, you have to create a separate graphic for each state. The Nextion will make the second graphic apply while the button is pressed, or you control the 'pressed' pic from the uC. Note on the home page a readout of the real-time clock is presented. Time is not really needed in the project since I do not log the test results (yet), however getting the RTC running was all part of the Nextion learn experience.
The power supply for my appliance tester is a small-ish salvaged ATX PSU. The reason for this (other than because I had one) is that the earth loop test ideally needs a high current of around 10 amps. I removed most of the paralleled cabling from each dc bus and brought out the few wires that were required to a small fuse panel. This ATX supply could supply 25 amps on the 5V rail and nearly as much on the 12V bus and having this much capacity un-fused is an potential accident. So, on one +12V rail, we have a 10A fuse. On another +12V bus, the +5V bus and the -12V bus I put 750mA resettable polyswitches. In the end, there was too much noise on the +5V bus, which was affecting analogue readings, so the +12V and -12V bus are both fed to a separate +5V and -5V linear regulators. The 5V bus on the ATX now runs only the panel LED! The only other down-side to using an ATX power supply is that the dc common is firmly tied to earth, which is not ideal but in this case worked satisfactorily.
Earth Loop resistance
The AFE schematic is below:
Earth loop resistance AFE
After protoyping several ideas, a simple low-dropout 3-terminal regulator configured as a constant current source was used. I settled for 3 amps which is lower than recommended, however it is well above that produced by a normal multimeter. The electrical regulations require appliance earth loop resistance to be 1 ohm or lower. This regulator will supply 3A into loads from 0 to 2.8 ohms, above which the current reduces due to headroom limitations. There is a 0.33 ohm sense resistor in line. The uC calculates the current by measuring across this resistor. The earth probe has a sense wire, to eliminate errors due to the probe wiring. Potential dividers drop the sensed voltages to be under 5V to suit the Arduino. Both the current and the terminal voltage are displayed on the Nextion along with the calculated resistance. The operator connects the probe to earthed metal of the appliance and presses 'START'. The current is applied for 10 seconds. Although I would prefer an independent 'enable' for the current generator, at this stage, the relay is switching the current. Prior to this arrangement I had tried one of those cheap switching modules which could operate as constant current up to 5 amps. This was inconsistent and noisy such that stable readings could not be achieved. At some stage, the smoke got out and that was when the linear version was born.
The AFE schematic is below:
Voltage and current monitors
This board produces isolated voltage and current samples to the uC in order to calculate power consumption. It also includes an opto-isolated 50Hz sync source and 'mains present' indicator. These are not used on the power consumption page, but are used for the RCD test. The uC does provide a panel indicator to be lit when mains is present.
This voltage monitor is actually my 3rd attempt. Initially, the Block 0.5VA transformer was directly across the AC mains. The secondary was tapped down to the uC. This was working but transformer heating was a factor such that the secondary voltage changed over 20% from cold to hot. I calibrated the coupling factor when hot, but the readings were always too high at first switch-on and at least half an hour passed before the readings were stable. My second attempt at a voltage monitor was a bit more radical. Having seen how well the current monitor worked I tried using a current transformer with 10 turns through the core feeding a resistance of 44Kohms. (actually 2 x 22Kohm 5 watt resistors in series). The AC voltage was dropped across the 44Kohms producing a current of 5.3mA. With 10 turns, this was effectively 53mA in the primary. At 2000 turns on the secondary, the secondary current was 26.5microamps and a current to voltage converter circuit produced a usable sample. The problem with this arrangement was that the output current was very microphonic. A tap on the current transformer produced sharp changes in reading and just general vibration was causing jittery readings. I was unable to stabilise this even after silasticing the turns in the coil.
Then the circuit you see above was evolved. An isolated current source was created by using high value resistors to the transformer primary. The secondary is then a small current which is amplified to around a volt by the op-amp shown. This proved to be low noise and stable. The current sample is created by passing the appliance load current through a Talema AP-2500 current transformer. The secondary feeds another current to voltage converter as shown. This provides a low noise sample for even very low currents. The Talema is rated to be linear up to 15 amps. The output of the op-amp provides about 2.4V peak at 15A peak. The output sits at 2.5V with no current and will swing to near 0V and 5V for plus and minus 15A in the primary.
An attempt was made to use one of those Allegro ACS712 hall sensors, however that proved to be noisy at low currents. In addition the cheap breakout board that was bought from an local on-line source had several issues. Here is a shot of the pcb in question.
Although the chip was rated for 20A, the spidery thin tracks from the terminals to the chip would not have handled that current for long. Secondly, the chip itself is mains rated for isolation but the earthed mounting holes for the board would allow metal screws to pass within microns of the tracks carrying 230Vac mains potential. Finally and this board shares this problem with other small sensor boards that you can buy cheaply just about anywhere and that is the mounting holes are so close to physical components that a screw head or a nut cannot be used to mount the board. In this case, I had to use nylon washers under the board for mains isolation and put spacers on top so that a bolt head had clearance around the chip. A plea to board makers: It does not have to be that tiny. Make room for mounting hardware! So, for these reasons and the fact of excess noise levels at low currents, I DID NOT USE this board and went with the current transformer method in the schematic above.
The current and voltage samples feed analogue inputs on the Arduino Mega; the sketch includes the EmonLib library which calculates rms values of voltage and current, producing readings of watts, VA, and power factor. In addition a peak current reading is available by feeding the analogue current sample to a hardware peak detector. The dc level produced by that feeds another input of the Mega and is scaled to calculate peak current and from that, display the crest factor of the current . Crest factor is the ratio of peak current to rms current. A nice resistive load will have a crest factor of 1.41 more or less. Horrible spiky loads such as from CFL and LED lamps, as well as many IT devices will have crest factors of 5 or even greater and this is an indication that there will be high harmonic content of the current drawn from the appliance under test.
I had already built a resistive test load which draws 28 watts and which can have a known capacitor switched across, so that power factor readings can be checked. A Yokogawa WT210 meter was also used to validate the power readings. All readings of voltage, current, and power are within 1%.
My peak detector plus some other interface sub-sections were built on to an auxiliary board with schematic shown below:
The upper part of this schematic shows the NAND schmitt gates that interface the two optocouplers to the Mega. The AC on signal from the MID400 is inverted and squared up for the uC such that a high level represents 'mains present'. The second gate inverts, tidies up and gates the 50Hz square wave from the H11G3 optocoupler. The rising edge of the square wave now coincides with the positive going zero crossing of the AC voltage waveform. The lower part of this diagram is the dual rail-to-rail op-amp used as a peak detector. Actually it produces the peak-to-peak value. One input of the first op-amp references to common via the 33k resistor so scaling in the uC represents the peak value. Note a reference to 0V can be used only if one uses a rail to rail op-amp and which common mode range includes ground.
The RCD test
The idea for this test is that you feed your 230Vac in to the instrument via an RCD to be tested. The operator presses the GO button and a load is switched in between live and ground. The RCD detects this unbalance current and breaks the circuit. If we start a timer when the load is switched in and stop the timer when the AC stops, that time represents the trip time of the RCD. One complication is that the standard suggests testing with the load switched in at the rising zero-cross point (0 degrees) and again with the load switched in at the falling zero-cross point (180 degrees). In this project, I have a button on the Nextion that is pushed to pre-select 0, 90, 180 and 270 degrees, so that both zero crosses, the positive peak and the negative peak can be tested. In addition, various ratings for trip current exist and the standard also requires a test at 5X the rated current. Most domestic RCD's are 30mA although sensitive 10mA types are available. In this project, a physical rotary switch on the front panel will set the current to either 10mA, 30mA, 50mA or 150mA. Then, an SSR driven from the microcontroller switches the pre-selected load to ground.
Here we have the four way switch and SSR board:
The second pole of the switch indicates to the uC which load is selected and this is shown on the Nextion.
Clearly, a more sophisticated arrangement would be possible with say a bank of solid-state relays switching in combinations of resistance directly controlled by the uC, however this board was originally built for a stand-alone hardware-only RCD tester so it was re-used in this instrument.
The programming of the Mega to do this test was challenging for me. I can call myself just about Arduino intermediate level now but there is a lot of 'under the hood' guru techniques that are still mysterious such as port manipulation and a whole bunch of stuff. Arduino seem quite easy to get running for relatively simple tasks or slowly changing data, but when timing is involved, one has to take a lot of care to not block the loop at any point.
The process for this part of the sketch is that the operator first chooses the current with the rotary switch, selects the starting phase by repeated pushes of the 'phase' button on the display, then presses 'START'. At that point, the 50Hz gate is enabled and the pulses are fed to a pin of the Mega. An interrupt is triggered on the first rising edge detected. The uC adds a specific delay as set by the selected phase, then starts the timer and enables the SSR drive pin. The SSR switches the load to earth. When the AC stops, as signalled by the MID400, the timer is also stopped and the time is displayed on the Nextion. Should the AC not stop after one second, the test stops anyway as a fail-safe and '999' appears on the display. There, how simple is that? Well it took me a few months to get it working properly. Part of the difficulty was interfacing to the Nextion display. It communicates by ascii text and has only limited buffering. So the Arduino loop is blocked for quite a few milliseconds whenever a button is pushed and whenever text or numbers are sent to the display. Although the baud rate was set to 115200, this didn't speed things up enough. In the end I set up a non-blocking display timer routine that only polls or sends display items every 200ms which is fast enough an update rate for a readout but which does not block the sketch on every loop.
Some evaluation of the accuracy of the timer was undertaken. Measurements were made of the delay in registering the zero crossing points and some errors were estimated only. Here is a timing diagram for the errors in starting the timer and engaging the unbalance load.
The blue waveform is an 50Hz AC cycle taking 20ms. The overlay red squarewave is the output of the schmitt NAND gate fed by the H11G3 optocoupler. The rising edge is 0.3ms delayed while the falling edge actually leads by 0.2ms. Only the rising edge matters in this case. The micro then produces a 2ms gate pulse at either 0ms, 5ms, 10ms or 15ms after the first detected rising edge. There was no measurable unwanted delay in that part of the process. The SSR is commanded ON at the rising edge of that gate pulse by writing the SSR drive pin high. The timer is also started at that point. I have been unable to measure exactly when the SSR switches ON but the datasheet says the worst case delay is 1ms. So, in the worst case, the timer starts 0.3ms after the zero crossing and the unbalance load is engaged 1.3ms after the zero cross (or the assigned phase). On average I expect the SSR switching delay is lower than 1ms. The SSR remains commanded on until the AC fails due to the RCD tripping. It has not been possible to reliably measure the switch-off time for the MID400 opto-coupler detector. The datasheet states 1ms. So, in fact the timer starts up to 1ms prior to the load being engaged and stops 1ms after the mains fails, making it potentially running for 2ms too long. In addition the switch point is delayed from the nominal 0, 90, 180, 270 degree points by up to 1.3ms, but typically 0.8ms. I have not attempted to add offsets into the timing calcs since the errors are within the 5% accuracy required by the electrical regulations. Regulations require trip time to be less than 300ms at rated current and 40ms at 5x rated current. The portable RCD I used for testing tripped in 22ms at rated current and 16ms at 5x rated using my tester, so is well under the requirements.
For this test, AC is applied to the IEC input and an appliance is connected to the load socket. The load socket is activated when the leakage page is selected. If the appliance is Class 1 (that is it has an earth wire) then any leakage current is immediately displayed. For a Class 2 appliance (double-insulated -not earthed) the earth probe should be used to attach to any exposed metal, or for example to the dc output plug of a wall-wart. The regulations require less than 1mA leakage for a Class 2 appliance or less than 5mA if a Class 1 appliance.
The leakage current detector schematic:
To measure leakage, both active and neutral wires pass through a Talema AP-2000 core. Any imbalance of current will be amplified. Assuming the current in one wire is 5mA greater (or lesser) than the current in the other wire, the secondary current will be 2.5 microamps. In this case, a transformation ratio of 100mV per mA is the target and so for 5mA primary leakage current, 500mVrms output voltage is desired. Therefore the feedback resistance becomes 200Kohm. The actual value will be slightly higher due to the effect of the 1Mohm feedback loop protection. The trimmer resistor allows for precise calibration. I have used balanced 5V rails in this case both for the op-amp and rms-dc converter. The ac from the op-amp passes to an AD736 rms to dc converter. The output of that feeds the uC. Using a chip rms converter is very accurate and ensures that a true rms value will be captured, since unbalance currents are likely to be anything but sinusoidal. The diodes at the op-amp input may conduct to protect the op-amp in the case of a short circuited load but otherwise play no part. Offset and offset drift is important in a high gain stage as this. An op-amp such as the OPA277 should be chosen with this in mind. Failing that, an capacitor may be used at the output of the op-amp to ensure that zero current produces zero output. If you choose to capacitively couple, the capacitor should be around 4.7uF non-polarised.
The test procedure requires that 500Vdc be applied between the appliance active and neutral wires (tied together) and earth. Any resistance must be greater than 1Mohm. Since some appliances contain MOV's and other surge arresting components, provision is also made to test at 250Vdc. The HV generator and current measurement is done in a front-end board as shown below. Actually this is based on a 'Silicon Chip' design of a few years back. They made a stand alone portable instrument running off a battery supply. This version runs from 12Vdc, and the calculations plus readout is via the Mega uC and Nextion display. So from the original circuit, reverse polarity protection is omitted, the LED display is omitted and the crowbar part is omitted as the HV bleeds off very quickly. My transformer ratio is lower as well due to the higher rail voltage. The Mega now performs the window comparator function. The schematic is below:
The MC34063 is a dedicated flywheel converter chip with feedback. The output of this feeds a 7555 acting as a schmitt trigger squarer. This drives a FET feeding a DIY ferrite transformer. The secondary voltage is rectified and filtered. A sample of the output is dropped with a high value resistor divider using a 22kohm to ground back to the MC34063 feedback pin. The reference voltage is required to be 1.25V at pin 5. Assuming the 2N7000 FET switch is off, the generator produces 250Vdc. When the FET switch is on, controlled by the uC, the dc output becomes 500V. The feedback voltage is monitored by the uC so that an out of limits flag will be set if the generator fails to work normally. HV dc is enabled by setting pin 4 of the 7555 high. The uC supplies 5V but this is more than sufficient to enable the 7555, even while operating from a 12V rail. Finally, resistors in the common leg monitor the current drawn by the load. Monitoring on the low side like this is convenient but does require that the negative terminal remain isolated from ground. So, for this test, the uC activates a relay which disconnects the appliance earth wire from earth, so that load current can be measured across the monitor resistors. If the earth probe is used on a Class 2 appliance, this too will allow for measurement across the same resistors. The uC has a shutdown routine and displays an over-current warning if the current drawn is greater than 2mA. To be in specification any current drawn by the appliance must be less than 500 microamps at 500V or 250 microamps at 250V.
This page provides a simple text statement about the polarity of the AC that is fed to the tester. There is already an 'AC present' signal derived from a MID400 optocoupler connected between phase and neutral. My simple polarity check utilized two more MID400 chips; one connected between phase and earth and the other connected between neutral and earth. There are now three logic signals available, which together, can have eight possible variations. The Arduino Mega reads these, then following a series of 'and' functions, sends a textual statement to the Nextion polarity screen. The messages simply say "Polarity correct" or "Phase/Neutral cross" or similar depending on which combination of three logic signals are present. Of course, the result depends both on your cable from the wall outlet and the polarity at the wall outlet itself, but any error shown should be enough to warrant an investigation.
These displays have a lot to commend them (price, ease of connection, on-board flash memory, free editor) but the editor itself is a work in progress as are the instructions. However, the instructions have improved and are better presented now than when this project was started.
For this project I have made use of the Itead Arduino library 0.7.0. Itead have at this time also published 0.9.0 but note that it is unstable and the recommended library is the one I have used. It took a long time to understand the terminology and just how the library worked and I still don't get it all. Within the library there are various .h files and in the config.h I have commented out softwareSerial and set it to use Serial3 of the Mega. At the end of development the debugSerial was removed as well. As was mentioned above, sending text and numbers or commands to the display takes too long so that the Arduino loop is blocked. It is necessary to contrive some timer arrangement to update values only periodically. If one needs to send a value with decimal points, it has to be sent as text. This means a lot of mucking around converting values to text, putting this in a buffer and then recalling the buffer. It's a bit of effort. One thing I never got to work was the signalling of which page was being displayed. The Nextion has a command "sendme" which can be sent as soon as a page is opened. I could not get the sketch to recognise this. I did want to run certain parts of the sketch and trigger certain events depending on which page was selected by the operator. In the end I cheated. There are 8 GPIO pins available. I configured 5 of these to be open-collector outputs and pull down one on each page (except the home page). So 6 extra wires (including a common) were run from the Nextion to the Mega for which pins were configured for input_pull-up. That worked, but one word of caution. If you plan to use the GPIO on the enhanced Nextions, do buy the special GPIO breakout adaptor. The tiny flat ribbon connector is virtually unusable without it. I persevered and actually soldered very tiny wires to the board but it was a mission. Even with my 4 diopter hobby glasses and super magnifier gadget it was hard. My small tip soldering iron looked like a railway line. One other trap and that is if you plan to use the Nextion sleep function. It is easy to configure the Nextion for sleep after a pre-determined time of no activity. This blanks the screen and sleeps the Nextion, but it will wake on a touch again. The trap is to set the timeout too short. The default is 30 seconds and if, like me, you want to test the function, you might leave it at 30 seconds. Upload it and all is good. The display blanks after 30 seconds and can be woken with a touch on the screen. Then you want to change the timeout to say, 5 minutes. Upload commences, but stalls because the Nextion goes to sleep after 30 seconds. What you have to do to break out of that trap, is to restart the upload after manually waking the Nextion, then continually touch the screen within 30 seconds to keep it awake until the upload is finished. My uploads took about 3 minutes so a 5 minute timeout is OK.
Configuring the Nextion with the editor was time-consuming. The instructions assume a level of knowledge that is above raw user level. Yes, I see the system command, but where do I put it? What are it's parameters. Just about every programming goal required trawling the Internet forums for guidance, which eventually does help, but much reading is required. There is an debugger in the editor and it is useful for checking that commands work. That is also how the RTC is initialized as well. Every object you place on every page is uniquely identified automatically, (page, ID, name) but I chose to make all objects on each page start with a unique group identifier (100-group, 200-group etc). This is more for my benefit than the system. Would I use these displays again? Yes, probably. Especially now that I have some experience of use.
Reducing the lamp flicker in the Jaycar QM3548 magnifier
A recent article about specifications for LED lamp flicker highlighted the poor result for this Jaycar LED desk magnifier. Read that article here.
I decided to check out why the flicker from the lamp was so high. Below is the schematic of the power supply in the lamp housing.
The circuit is a simple full wave rectifier direct from the AC mains, using a 1.8uF/250V class X2 capacitor as a dropper. There is an R-C filter at the rectifier output. The 6.8uF capacitor has a rating of 250V. The dc voltage fed to the chains of LEDs measured 76V, however the superimposed AC was 26V peak to peak. This AC voltage accounts for the high level of 100Hz flicker from the lamp.
This scope shot shows the levels fed to the LEDs.
The scope is at 20V/division with zero ref at the bottom. Timebase is 2ms/division.
Improving the circuit
I added a 47uF/250V capacitor across the 6.8uF. While this did not fit on the small circuit board, it could be wired off the side with sufficient room in the housing. Also added was a 33k resistor across the capacitors to bleed off the voltage when the AC is switched off. This minor modification left the dc unchanged but reduced the ripple to 6Vpp. Following reassembly the flicker percentage was rechecked and it had been reduced from 84% to 30%. Still well above IEEE1789 recommendations, but now in the same ballpark as some other LED lamps that I had measured.
There is not much further scope for simple improvements to this circuit. A larger capacitor would not fit physically. If I was still concerned about the lamp flicker, the way forward would be either to try a get a small switching SMPS to fit in the housing, however 76Vdc models are not common. Failing that I would be inclined to remove the PSU, bring out the dc wiring from the lamp and use an external brick type PSU.
Only an experienced technician should contemplate a modification as presented. The dc output of the PSU is NOT isolated from mains and could be lethal. Safety relies on complete physical isolation from wiring and metal parts. It is very simple and other than an on-board fuse has no circuit protection. In fact, as it stands, if the LED's failed open circuit or the wiring to the LEDs was disconnected, the dc voltage on the filter capacitor would rise to around 340V and since the cap is rated at 250V, the smoke installed inside the capacitor will likely escape.
Low pass filters for FM
Using the high order LTC1569 and MAX295 filters
For my recent attempt to make a simple low power FM transmitter, an Aareff stereo coder was used. Shortcomings of this coder included the fact that it included no audio low pass filters and in addition, the MPX baseband filter had considerable attenuation of the upper end of the baseband up to 53kHz. Audio low pass filters are required to pass audio to 15kHz without loss and then attenuate 19kHz in order to protect the pilot signal as well as have considerable loss at 23kHz and up in order to avoid aliasing with the sub-band from 23kHz to 53kHz. These demands typically require high order low pass and/or notch filters comprising a large number of op-amp active filter stages. Two such filters with matched characteristics are needed. Similarly, following the composition of the baseband signal, however that is done, a single low-pass filter is usually required to pass from 20Hz to 53kHz and attenuate harmonics of 38kHz (typically the odd-orders such as 114kHz and 190kHz). This filter needs good flatness and low group delay in order to avoid compromising stereo separation. The Aareff filter had 2.4dB loss and 23 degrees of phase shift at 53kHz while attenuating 114kHz by only 10dB. At that time I was keen to find a low parts count option to make suitable filters.
The Maxim MAX295 chip is an 8th-order lowpass Butterworth switched-capacitor filter with corner frequency to 50kHz. This is a candidate for the audio low pass function. The Linear-Technology LTC1569-6 is a linear phase, 10th-order low pass switched-capacitor filter with up to 64kHz cut-off frequency, so is viable for the baseband filter.
For years, I had misgivings about the use of switched-capacitor filters for audio use, however this generation have low distortion along with clock to corner frequency ratios of at least 50:1 and with low clock breakthrough, the time has come to reassess. Both these manufacturers insist on manufacturing their products into such tiny packages that you can be mistaken into thinking that there is a small insect on the bench. However, after investing in a small scanning electron microscope I soldered the SO-8 chips to adaptor boards that bring pins out to 0.1" spacings, in the time honoured fashion.
MAX295 15kHz audio low pass filter
A pair of these filters were assembled in order to see how well matched they could be made. The schematic is below. For this trial I simply used the internal oscillator, although in a production version you might prefer a crystal derived external oscillator, despite the increased complexity of the sub-system.
Schematic stereo MAX295 15kHz low pass filter
A single supply of 9.6V is used, and a mid-rail bias point established as shown. There is nothing particular about this method; it uses parts that were available. Both chips share the same dc voltages. The oscillator frequency and hence cut-off for the filter is determined by a capacitor at pin 1. This is the only critical component. For a cutoff around 16kHz, the oscillator cap is a rather low value, such that parasitic capacitance is significant, meaning that the cap value needs to be corrected empirically. That is why you see 3 capacitors in parallel. Both pin 1's were connected together. In doing this, the capacitor needed is half the value determined from the data sheet, but means that cutoff frequency drift will be the same for both channels. Drift due to temperature changes will be largely dependent on the temperature coefficient of the capacitor. NPO or zero ppm capacitors should be used, but even these can be plus or minus zero. One can optimise the capacitor by using combinations of positive and negative coefficient capacitors so that drift is minimised. The MAX295 includes an free op-amp stage which may be used as an inverting buffer before the filter as shown, or post-filter to reduce clock breakthrough.
These are the response and distortion plots. THD is very low with 1 volt rms applied. Even at 1.8V rms, harmonics are better than 70dB down.
Response at 15kHz is -1.3dB
One has to compromise the cutoff frequency. A little higher will reduce loss at 15kHz , however then the loss at 19kHz and 23kHz is also reduced. This seems a fair compromise for such a low parts count filter. Is this enough loss at 19kHz? I have seen some publications quote 19kHz rejection required of 40dB , however is this much necessary? The pilot is transmitted at 10% modulation; thus 20dB down. With some margin for receiver implementation and allowing for pre-emphasis then perhaps 40dB is required to assure safety. There is, however, very little 19kHz content in the spectrum of music, such that one could sensibly expect such content to rarely exceed 30dB below peak audio level. It is still pre-emphasised, so rejection of 25dB might reasonably be required. Therefore, this MAX295 filter falls short of ideal; having only 10dB of rejection, however it is better than none at all. Best practice means that a supplemental 19kHz notch would need to be included.
Baseband low pass filter using LTC1569-6
This chip is quite versatile and with one resistor may be set to a variety of cut off frequencies, or used with an external clock at 64x cutoff. In addition there is an internal clock divider being either divide by 1, 4 or 16 making three cutoff frequencies available by setting of a single pin. For this application, the frequencies from 20Hz to 53kHz should be passed with minimal loss and 114kHz should have a lot of attenuation.
Schematic LTC1569-6 baseband low pass filter
The LTC1569-6 will operate from 3V to 5V single supply. It became clear that the dc rail is quite critical. For this filter, 3V gave better distortion but the maximum level was only 820mV peak. In the end, it was determined that 3.6Vdc was the best compromise, however that will depend on your exact design. The nominal value for R1 is 10Kohms for 64kHz cutoff, however I lowered this value just slightly to move the cutoff frequency a little higher. The filter response droops slightly from 10kHz up, so that 53kHz was 0.7dB down. This is the reason that a MCP602 buffer was added. The network around the buffer boosts the top end just slightly to improve the upper end response. This addition may not be essential since the error without the added network is relatively small, although it will compromise stereo separation a little.
Above is the response at 1dB per division for the overall circuit, including correction network, up to 48kHz; the limit of my Praxis system.
Note also the very good phase response.
Below is a response out to 100kHz made with an spectrum analyser.
For this plot, the marker is at 53kHz and vertical scale is 5dB/division. Ignore the start of the sweep; the analyser RBW is not low enough to resolve the start of sweep from the dc point. 100kHz is 37dB down. Response at 114kHz (3*38kHz) was -47dB and at 190kHz (5*38kHz) the filter had 60dB rejection. More than enough to clean up residual 38kHz square waves from a stereo coder and a much better proposition than the filter on the Aareff board.
At 1Vrms signal input, harmonics were better than 60dB down when Vcc was 5V, however best distortion was obtained at 3.6Vdc and less than 820mV rms drive. There was no visible sign of the internal clock oscillator feeding through to the filter output. This filter is a very good option for an FM baseband filter.
Alternative 15kHz filter with the LTC1569-6
By leaving pin 5 of the chip open (actually with 100pF bypass capacitor), the divide by 4 option is enabled so that the cutoff frequency becomes one quarter of that previously set. So in this case, the filter cutoff became about 16.5kHz. This was tried simply to see if the LTC made a significantly better audio LPF than did the MAX295. As it turned out, the LTC1569, while leaving the resistor R1 at 9K4, had 1.33dB loss at 15kHz, 7dB loss at 19kHz and 25dB loss at 23kHz, so was similar but slightly inferior to the MAX295.
Door intercom remote sounder
Hacking an Aiphone C-123L/A and using a small Class D amp
We have an Aiphone C-123L/A front door intercom. The master station is in the kitchen. It has served us well but the call chime sometimes cannot be heard down in the office or studio. This short article describes a remote chime repeater including interfacing to the Aiphone, the wiring and programming of an Arduino Uno to generate the melody and the use of a tiny 3 watt Class D amplifier to drive a 27mm mylar cone speaker.
Master and door units are interconnected by a single cable pair. Power for the system is by four C-batteries within the master. Having few callers, these batteries have lasted for more than 5 years. The signals on the cable pair were monitored to work out how to trigger the remote sounder. When there is no activity, there is 6Vdc across the wires. If the door button is pressed, the voltage drops to around 0.7Vdc and may have superimposed audio if the caller also speaks. At this time the chime sounds in the master unit. While the button in the master unit is pressed, the homeowner may speak to the door caller. Voltage on the pair then also drops to around 0.7V with audio signal. Once the master button is released, voice from the door unit can be heard at the master station for about 15 seconds. All rather clever and elegant. There is no replaceable battery in the door unit.
A remote sounder could therefore be triggered when the voltage drops from 6V down to 0.7V. To avoid any loading, the trigger circuitry should be high impedance. A separate power source is also required, since any load on the master battery supply would decrease battery life.
I picked up a Uno clone for under $10. A tiny 3W stereo class-D amp was $6.95 at Jaycar and a 27mm mylar cone speaker was $3.95. These were the significant material costs for the whole project. Some people treat the Uno boards as development boards only and then make their own board using just the peripherals required for their project. I don't. At under $10 for a board, it is not worth making anything; for a one-off anyway. The Arduino board becomes just one component of the whole.
When the trigger line goes low, the Uno first puts pin D12 high, enabling the power amp. The trigger pull-up resistor is deliberately high (220kohm) so that no loading of the intercom pair occurs. After a short delay, the programmed tune plays. It runs for about 3 seconds. The tone squarewaves at D8 are filtered by a 2 stage RC filter, which also attenuates the level to be suitable for the amp board. There is no variable gain control in the system. Thats it. My 12V supply is tapped off an existing system. You will see a low value resistor (6.8 ohms) in series with the Uno "Vin" pin. That is to relieve the dissipation of the Uno regulator while the chime is playing. The PA draws some current and although it is within the current rating of the Uno regulator to supply it, prudence dictates a simple mitigation strategy. In quiescent state the 12V drain is 47mA, and while sounding, the system draws 330mA. That resistor then drops 2.25V so dissipation of the Uno regulator is reduced.
The sketch is here. It is a slightly modified version of the "toneMelody" example by Tom Igoe supplied with the Arduino IDE and described in the referenced tutorial.
The Class D amplifier XC-4448 module uses a PAM8403 chip
This tiny module was purchased at Jaycar. It is similar to several versions available on ebay and other sources. They all use the PAM8403 3W stereo Class D amplifier chip made by Diodes.com located in Texas. This Jaycar version is only 23mm x 16mm with a single row of 11 pinout holes down one long side. Unfortunately the holes are not at a standard 0.1" spacing. Some are, but most are at smaller spacings. The board operates with a single supply of between 2.5V and 5V, however you will only get the full 3 watts output per channel by using 5.5V and 4 ohm speakers. Outputs are balanced (internal bridge mode), so speakers may not be commoned, or connected to circuit ground. There is a paucity of data available in the so-called 'data sheet' and that issue seems par for the course regarding all these cheap modules coming out of China. Jaycar is not alone there. Accordingly, some notes and test results appear below. Although the PAM8403 chip data sheet is available, the figures given there are not all relevant to results achievable on any particular module.
Switching frequency and RF interference
The measured switching frequency of my board was 213kHz at 2.5Vdc running into a 6 ohm resistive load, but increased to 230kHz with the supply rail at 5.0Vdc. These vary also with load impedance. These amps are likely to cause RF interference; particularly to AM services. The fundamental switching frequency will cause the most interference, but so will odd multiples; so in my case, 690kHz and 1150kHz, both within the AM band would potentially be affected. I didn't do any further study on interference actually caused, but if you were to have problems, there are a couple of options. First, minimise the length of your speaker wires. Then make your wires a twisted pair, such as could be found within a Cat5 cable for example. Shield the wires, if necessary. If this proves insufficient, or is impracticable, add RF filters to the amp outputs. Four small RF chokes hardwired close to the board will be worth trying, but ensure the chokes have adequate current rating, or the cores will saturate when audio is passed through them. That will reduce your ouput power and cause distortion. Finally, since the interference frequency is supply-dependent, alter the dc supply a little to move the interference away from your favourite AM channel.
At left, the 230kHz 10Vpp squarewave output into 6 ohm resistive load.
The theoretical maximum power output using a 5Vdc rail and 4 ohm load is 3.12W. That will be fully clipped and sensible power limits are somewhat lower. For 8 ohm loads the maximum is 1.56 watts. So, the maximum current drain, if you were to apply a continuous sine wave to both channels at 3 watts output into 4 ohms, would be around 1.33 amps. This assumes the efficiency is 90% as claimed. In practice, you don't get the full efficiency. It varies with power output and load anyway, but will be maximum at full power into 4 ohm loads. Normally for music, one does not encounter continuous sine waves so the average dc consumption will be considerably less, although it could momentarily reach the maximum. The point here is that your 5V supply needs to be able to supply up to 1.33 amps, if you have 4 ohm speakers, but does not need heatsinking based on that, because average current, with music, is a lot lower.
Into a 4 ohm resistive load, with no audio output, module current was 190mA at 5V. One channel at full power, current was 700mA and both channels at full power, current was 1000mA. Now, I couldn't quite reach 3 watts with both channels driven (see next paragraph). In addition, I rated full power at the point where distortion just exceeded 1% and not 10% as per the chip data.
If you measure using resistive loads, you would not get the rated full power, nor would you get the rated efficiency. In the case above, the efficiency works out to be only about 63%. There is a reason for this and which will apply to all Class D amps that have no RF filter at the output. The amp is actually continuously putting out a 10Vpp square wave (assuming 5V supply) at 230kHz and this appears across the load. If the load is resistive then the amp is delivering power already into the load. You won't be able to hear it, but it will reduce power capacity and increase the current drain. In practice, even a 'resistive' load will have some reactance at that frequency as will the connecting wires. A speaker has a rising impedance due to its coil inductance, so will present a high impedance load at 230kHz, and not pull much current from the supply. DC supply currents, when operating into a speaker, are less than those into a resistor, for the same audio power output.
In my case, I used only one channel and the speaker was nominally 8 ohms with a further 4 ohms in series to lower the output. Into that load, the current drain of the amp without audio, reduced to 20mA and when operating near full output, was only 280mA. Including the 47mA of the Uno itself, total current is well within the ratings of the Uno regulator.
Frequency response, gain and distortion
It would be helpful if the suppliers of the modules would provide this information, however it looks like a vain hope. You could assume the chip datasheet would assist but overall performance depends on the peripherals around the chip.
For reference, the gain of this XC-4448 module is 18dB. Therefore, full power requires 440mV rms drive. The audio input resistance is 20Kohms. Although it wasn't an issue in this project, the frequency response of the module is poor at the low end. See plot. You can see both 4 ohm and 8 ohm plots here. The distortion (THD) up to and including the 9th harmonics, was 0.12% at 400Hz and 0.9% at 5kHz. This was taken at a power output just prior to the onset of clipping and was for only one channel driven.
Again, there is nothing on the module datasheet to indicate the working of the mute function. You have to pull the SW pin low (below 0.7V) to mute the amp. For normal operation, take the pin high. The amp draws negligible current while muted as it shuts off the HF switch generator. I noted that it takes around 220ms to enable, which is why there is a delay between enabling and start of tones in the melody generator sketch.
dual MCP3201 12 bit ADC's
Using Arduino Uno
The MCP3201 is a 12 bit ADC in an 8 pin DIL package. It uses SPI to communicate and can operate at up to 100kHz sampling speed. I built a small breakout board including two MCP3201 chips along with low noise 5V regulator, precision 4.096V shunt reference, analog buffers and comparators; the latter might be useful to extract zero-crossing information.
The impetus behind this experiment was to trial the ADC's for sampling voltage and current for appliance power measurement. The Arduino is natively only 10 bit, and while this is perfectly adequate resolution for the voltage measurement, it is not really sufficient for the current range, since a mains appliance might draw as little as 1 watt and up to 2300 watts; which means rms current ranging from 4mA to 10A (on 230V/50Hz mains). That is a 2300:1 ratio, requiring a minimum of 12 bits quantizing. An alternative method might be to employ an PGA (programmable gain amplifier) for the current range.
Referring to the breakout schematic, you will see that the two analog buffers are not quite identical. I designated channel 1 for voltage sampling, and this AC sample would be derived from a transformer scaled down to provide 1V peak approximately centred around 0V, so the buffer is AC coupled to the MCP602 R2R op-amp with a mid-rail offset (2.5V). The offset is necessary since the ADC analog inputs only function between 0V and the reference voltage, so may not go negative. I intended the current sample to be derived from an ACS712/20 current sensor chip, which has 100mV/A sensitivity centred on mid-rail. Since the ACS712 devices provide the bias, channel 2 input is direct-coupled.
An accurate and low noise reference for the ADC's is essential. I have used an LM4040A shunt reference which provides 4.096V within 0.1%. Using the configuration in the schematic, the total noise on the reference rail from 5Hz to 48kHz was measured at -72dBV, with no individual product above -90dBV. Once the system was running with the Arduino, and with zero input applied to the ADC, the noise jitter on the reading was only 1 count (1 part in 4096). Early tests using the Arduino 5V reference (from USB), gave a jitter of up to a count of 8, which effectively nullifies at least 2-3 bits of quantizing. The ADC count returned from a 12 bit converter ranges from 0 to 4096. With a reference of 4.096V, each ADC value represents exactly 1mV.
Since my ADC reference is 4.096V and the midpoint bias is 2.5V, the maximum peak input that may be applied is 1.596V. So, the volt sample peak must be below this, and this is also the highest value that can come from the ACS712 current sensor chip. At 100mV/A, this means I can measure appliances of up to 15.96A peak current. This is fine on 230V systems but may be inadequate for 110V appliances. The ACS712 series comes in higher current versions.
The comparator sections are entirely optional. These produce a square wave with transitions at the AC zero-crossings. It had occurred that it might be useful to sync the ADC samples or try and measure phase difference, however my initial Arduino sketch does neither.
This is for a basic Uno. The sketch is below: It gets the raw ADC values from ADC1, followed immediately by ADC2.
With no serial port running, there is a delay of abt 4us between completion of ADC1 read and
start of ADC2 read. Conversion time depends on the ADC clock divider. If DIV=4, conversion time is 18us.
Time between successive reads depends on all the stuff in loop, but without serial printing,and DIV=4, time is 48us with 6us timing jitter. Samples from each ADC are not strictly synchronous, however for the purposes of calculating AC power of an appliance, the error will be small. I measured 22us in total with the settings in the sketch, meaning a phase error difference of 0.4 degrees. Serial printing is enabled in the sketch, mainly for diagnostic reasons, but these may be commented out to keep the time between successive reads as low as possible. Ultimately, the results would be displayed on an LCD or TFT display, once the system was refined.
The sketch returns the sample instantaneous values with the offset removed, so the numbers returned are equal to millivolts. This, it does for both channels. Then there is a routine for the max and min value within a rolling 15 cycle window on the ADC2 channel (for current) only. Most analog implementations of this would then have the values exponentially decay to the next cycle, but here, the decay is linear, just to keep the calculation simpler and faster on the Arduino. Then, there is a smoothing routine on ADC2 only. I have averaged 40 samples for this value. It may be of use for low values of current, or to establish the zero point, although with this breakout, the zero point is stable and can legitimately be hard-coded. Since this is experimental so far, there is no scaling applied to the returned values. I have had this sketch running with test signals and the returned values are accurate. The "Serial Plot" app is very useful to visualize the serial port outputs in cases like this.
Next step is for me to work out a way to calculate rms values from the external ADC instantaneous values. My attempts to date have not been succeeding which is not a surprise, since my hardware skills far exceed my programming skills. I have noted that many methods seen on the web to calculate rms in software rely on the AC waveform being sinusoidal. Yes, it is relatively easy to scale for a known signal like a sine and that might just be sufficient for the (usually slightly distorted) voltage waveform, however the current waveform from mains appliances (apart from heaters) is far from sinusoidal and so a sampling, squaring, averaging of aggregates method is required. That will be in the future.
House AC power remote monitor
Using Arduino and Nextion display
Many years back, before the 'OpenEnergyProject', I built a monitor unit to measure house power consumption. It used purely analog techniques, with hardware rms detectors and included local readouts for voltage and power consumption. Data was obtained using a clamp current transformer situated around the incoming neutral of the switchboard. A small 1.5VA transformer was used to produce a sample of the mains voltage. This unit was situated out in the garage, adjacent to the switchboard. The unit was accurate and stable but wandering into the garage to see the power consumption became a bit tedious after a while.
On reading of the HopeRF RFM69HCW integrated packet tranceivers and having discovered their ready availability, this project to send the data via wireless to my office was born.
The sending end
The HopeRF modules run from 3.3V, so I used an Arduino Pro Mini 3.3V to drive it. I made up a small sub-board to go inside my original monitor unit. This board has the Arduino, the RFM69HCW-433 board, a 3.3V PSU and a dual op-amp rail2rail buffer section. The only external change to my monitor unit was the 6" antenna wire and a blinkin' LED which flashes every 15 seconds when a data packet is sent, or gives long flash if my 3.3V PSU becomes out of limits. The Arduino sketch includes both the LowPowerLabs RFM69 Library and the emonLib library. Thanks to both Felix Rusu of LowPowerLab.com and the OpenEnergyProject.
I implemented the NetworkID, NodeID and encryption features, but not 'acknowledge' since the transmit and receive ends are in fixed locations and if a rare packet was missed, there is no consequence. This is the 433MHz flavour of radio, they also come in a 915MHz variant. The -HCW models produce up to +20dBm. This is a bit high to be legal here, with +14dBm maximum EIRP allowed, so a line in the sketch reduces the radio power to under 0dBm. This proved to be more than enough for the system- the RSSI result on the receiver varies between -60dBm and -70dBm.
The emonLib does the calculations for the electrical parameters. One sets a scaling factor for voltage and current. The library produces values for realPower, apparentPower, powerFactor, supplyVoltage, Irms from the voltage and current AC samples fed into the Arduino. These five parameters were assembled into 'csv' format and sent as a single packet. Scaling factors were set by comparison with a Yokogawa WT210 precision power meter.
The receiver end
An identical RFM69HCW board is used as the receiver. I wired this up to a Arduino 'Metro' because I had one lying around. These are a Uno style board from Adafruit Industries. In addition, to time stamp the data, there is a DS3231 RTC module. For the remote local readout I purchased a Nextion color TFT display of 320x240 pixels. These are really cheap and they have onboard memory so once the display module is programmed, the Arduino need only supply the textual data values. Of course there is a learning curve for the Nextion Editor, but for this simple application it isn't too long. The Nextion is touch screen and can have multiple pages; neither feature is used here.
Power supply requirements slightly complicate the receiver end. The Metro is 5V, as is the DS3231 and the Nextion. The RFM69HCW is 3.3V, and when transmitting, it draws 130mA; a bit more than is desirable to try and get from the Arduino. Although this board is strictly a receiver I didn't want to take the chance it might transmit (such as when acknowledging a packet). As it happens, the Nextion module has a 3.3V regulator on board. I tested it's capacity and it would supply 130mA without trouble. So I hard wired out the 3.3V from the Nextion to run the RFM69HCW board. As another complication, logic-level conversion is necessary. There are five data lines to and from the radio. One can buy cheap logic level converters which are bi-directional; four to a board. Sigh, so two of these became necessary. Cost isn't the problem, but mounting and wiring out is, especially for elderly eyesight.
The DS3231 RTC module (aka ZS-042) may need a modification. If you either don't run a backup button battery, or use the rechargeable lithium such as the LIR2032 type, then no modification is necessary. However, if you use the common non-rechargeable lithium CR2032 type and this is what it may even come with, then you need to cut a track to avoid the system trying to recharge the battery. There have been instances of the lithium non-rechargeables bulging and getting hot, so this process is advised. Instead, you could either remove the 200 ohm resistor or diode connected in series from the 5V bus to the battery, but cutting the track allows for simple restoration if you decide to go rechargeable later. The CR2032 only powers the essential timekeeping part of the chip while 5V is removed and will last a very long time. I did build in a battery monitor to the sketch, which will show 'Batt Low' if the button battery goes below 2.4V. The DS3231 will keep time on battery down to 2V. I have seen ads for these lithium batteries from many web suppliers where they either don't state that the CR2032 is non-rechargeable, or have them in the rechargeable battery section.
Always thinking to the future, I brought out the 32768Hz from the RTC to a panel connector for no particular reason other than it might be useful. It is reasonably accurate; of the order of 2ppm. I also wired out the SQW pin of the module to a LED so I can see time passing in 1 second increments. This pin will supply only 3mA but is sufficient for a LED.
The Nextion communication with an Arduino is via a Serial UART. The Uno has only one serial port and that is used for programming and to Serial.print the electrical data to the outside world for logging and analysis. So it is necessary to use the SoftwareSerial library, which adds a virtual serial port. This enables the Uno to send data to the Nextion independently of the hardware serial port. I could not, however, establish a way of linking serial data from the hardware port to the virtual port in order to upload firmware to the Nextion. So, as you will see from the schematic, there is an 6 pin header on the back of my unit with a 2 way switch so that the Nextion can be programmed by use of an FTDI cable when required.
This Nextion display has a visible display area of 60mm x 45mm. Every 15 seconds, the data fields update as a packet is received. In addition, the signal strength from the receiver is displayed, plus the RTC battery status. Finally, along the bottom is the RTC time.
The USB output of the Arduino can be connected to a pc and with the use of a serial monitor (Arduino IDE, or PuTTY, or Eltima Software RS232 Data Logger) can be visualised directly or logged to a file. I simply configured the serial output as a single line: "Date,Time,realPower, apparentPower, powerFactor, Vrms, Irms, RXlevel, BattFlag". Such a CSV file may be easily opened with Excel or similar for analysis. In future, I may want to develop a simple web page displaying the essential data, but have not yet connected all the process and programming dots from the point of saving a csv file to my Winampserver to a working web page.
Links and project files
Line voltage monitoring
with small transformers
For domestic AC line monitoring purposes, there is a requirement to measure the voltage. Most of those commercial power monitors simply assume a line voltage in order to calculate power, but if the line voltage varies then their power calculations will be wrong. Where I live, the voltage can vary from 215V to 255V; a range of -6.5% to +11% from the nominal 230V. I advocate using low power step-down transformers. While I have seen designs for isolated high side monitors, these are inevitably more complex, needing an isolated dc rail and complex electronics. The power grid is an electrically hostile place and too many things can go wrong.
What is wrong with using the humble transformer? Again, on browsing web articles on the matter, most objections seem to be related to distortion. I have to question this, since if the only requirement is to obtain a voltage sample, then some distortion will not matter. In any case the voltage and phase relationship is a constant and the scaling factor can be established easily enough. If one wants to measure the AC voltage distortion, this is another matter. Power consumption can be of concern, but with careful design, this can be reduced to less than a couple of watts. Size is immaterial since encapsulated transformers under say 2VA, with the proper isolation specifications are neither large, nor expensive. Persevere with transformers because this is the safest and most reliable method for the hobbyist/TestBench.
To try and quantify transformer distortion, I performed a couple of simple experiments.
A small encapsulated transformer (Block VB 1,0/2/24) which is 230V to (24+24V) at 1VA , is connected through a variac and the distortion measured at various voltages and load factors. Because power consumption should be minimised, the first test is with no secondary load (actually about 68Kohm). The two 24V windings were wired in series and a potential divider used to feed the THD analyser. Result is plotted at right. Distortion starts to increase above about 175Vac input. (75% of nominal voltage). Distortion is significant by 250Vac. I know from previous measurements at these premises that the AC line voltage here has between 3.5% and 4% distortion, so it is a reasonable conclusion to say the transformer is not distorting below 75% of nominal primary voltage.
So, if the waveshape were of importance, then this would be of concern. This test was repeated with an 8VA transformer from the same manufacturer. The same basic trend was apparent but to a much reduced extent. In that case, THD reached just over 4.5% at 260Vac. The power rating of the transformer is relevant to the result, however an 8VA model is becoming impractically large for the application. I should add that a transformer used as a voltage monitor should not also be used as a power supply for other parts of the circuit, unless one is very careful to keep the loading constant.
Back to the 1VA version, the test was repeated with a 1500 ohm resistive load on the secondary. Remembering that in this case, the secondary is rated 48V at 1VA, making this load slightly exceed the rating of the transformer for primary voltages over 200V. But now the distortion vs voltage curve is completely different. So this suggests that with heavy loading, a given transformer has relatively insignificant THD, while at no load, the THD increases rapidly above a certain primary voltage, meaning that core saturation due to exceeding a threshold flux density is the culprit. Different makes of transformer are likely to produce different results; they are made for differing purposes, with variations of core materials, but the general principle and trend will remain.
The answer seems apparent; that to maintain the waveshape, which is to say minimise the harmonic distortion, then the transformer should be operated with a heavy (relative to the rating) load on the secondary and to be a stable voltage monitor, that load should be constant. However, we also want to minimise the power drawn by the monitoring circuit. A heavy load is then contra-indicated. Therefore, use the smallest transformer possible; Block have a 0.35VA rating variant with all the safety and isolation standards necessary. The other way is to use a transformer designed for a higher primary voltage, if possible. You 110V people have the option to buy a 230V transformer, or possibly series up two primary windings to get the same result. A transformer running at around half rated voltage will have minimal distortion, even with a light secondary load. Here in 230V-land, there are no such transformers suitable off the shelf. Looking for 460V transformers produced no useable result; these start at about 500VA.
The next best option for a AC voltage monitor which minimises distortion, while keeping power consumption low, is to reduce the voltage applied to the primary. A resistor seems the obvious answer. Keep the voltage applied to the primary under half the rated input voltage and there should be no problem with distortion. What value of resistor? For my 1VA transformer, primary resistance was 3850 ohms. For the inductance, I measured 35H, by using the resonance method in conjunction with a known capacitor across a signal generator. The reactance of a 35H inductor at 50Hz is 10996 ohms. Therefore the primary impedance at 50Hz is 11650 ohms (square-root of sum of squares). 60Hz people need to recalculate. So, a 12Kohm resistor would be about right. That needs to be rated for at least 2 watts in this case, and it is always best to put two equal resistors in series anyway, for voltage handling reasons.
This was wired up on the bench and the voltage across the primary was indeed about half, however the distortion was worse! The reason for this was immediately clear and that is that we now have a RL high-pass filter. Inductive reactance increases with frequency and so the transformer was now more receptive to coupling harmonics of 50Hz, making THD worse. Increasing the value of series resistor worsened this effect further still. The next step was to try and flatten the rising impedance with an RC network across the primary of the transformer. If the values are chosen correctly, the RC network will be a 'mirror-image' impedance, making the whole look resistive. Choose a resistor more or less equal to the resistance of the primary winding, so in this case about 3.9kohm. The capacitor value is best empirically determined and this is what i have done, ending up with 2.2uF in series with the 3k9 resistor. That network further increases the gross voltage transformation ratio, so the output voltage is lower, but the distortion is now minimal. In fact, you could choose any suitable value of dropping resistor (the 12kohm calculated above) so that your secondary voltage is in the range of your analog to digital converter, which might be only 1.65V peak. I ended up with the network below:
The 1.4V peak ac output is about right for an ADC running 3.3V reference and with a half-rail offset. In fact the half rail voltage divider could be applied to the centre-tap of the transformer and each end fed to the differential inputs of a suitable ADC. The two 27k resistors now dissipate only 0.87 watts between them and the primary transformer voltage is around 12Vrms. Distortion is minimal. Transformers are complex beasts and there is no such thing as a perfect version, outside of a textbook. Inter-winding capacitance and leakage reactance make even modelling them a time-consuming process. There is one further advantage of a network like this used as an AC voltage monitor and that is to correct the phase shift. The unobtainable perfect transformer will have zero phase shift with a resistive load. My tests of various models reveal they typically have between 7 degrees and 10 degrees of phase shift between input and output. The 2.2uF capacitor partly corrects this, and by varying the value a little, it could be corrected to zero, for a given transformer. Alternatively, leave the 2.2uF cap alone and add a small value cap across the secondary. Of course, you will need some means of checking the phase shift while benching all this up, in a safe manner of course. There is some danger of 'improving' the distortion of the mains by doing this. By adding capacitors one is adding low pass filters that can reduce the higher harmonics. To preserve the original AC waveshape one must maintain the original ratio of harmonics, so reducing harmonics is as bad as increasing them. Fortunately you only need to have a flat frequency response to the 7th harmonic, or 350Hz. (420Hz for 60Hz countries). Above that, the harmonics of the grid AC line voltage drop away quickly. This is not true for harmonics of current waveforms, for which I have seen some nasty loads that produce harmonics out to the 49th at least.
The Axino mini-FM transmitter
Up to 1 watt RF output
This small project arose from my earlier (2014) attempt at making an FM transmitter and which, for the reasons of expediency, was based around a MAXPRO3000+ transmitter board from pcs-electronics. You may read the full technical description of that exercise via this link.
The MAXPRO3000 had some issues; namely RF harmonic levels too high, deviation sensitivity varied considerably with RF frequency and the modulator became unstable with low audio frequencies. The current project is an exercise to see if a simple transmitter could be built without having similar problems.
The synthesizer and modulator techniques are hardly ground-breaking and are entirely conventional. A modern approach would most likely comprise a DDS and a lot of programming, but I considered that too steep a learning curve at this stage, so stayed with the simple VCO and single loop synthesizer approach.
mini-FM transmitter article
RF controller experiments using ASK/OOK 433MHz modules
no microcontroller needed
Simple RF controllers may easily be built using readily available and inexpensive RF modules which operate within the 433MHz band allocated to such devices. In New Zealand, this band extends from 433.05MHz to 434.79MHz having a nominal centre of 433.92MHz. Maximum permitted power level is -16dBW (25 milliwatts) EIRP. An example pair of these was bought on ebay for testing.
RF controllers article
An improved mini-oven temperature controller
Better temperature control
I recently bought an inexpensive mini-oven (benchtop oven). I will always be amazed at just how little one has to pay for simple appliances.
Part of the answer is of course, that these are unsophisticated in design and construction. You will have seen similar in appliance stores. Controls on this one include a temperature dial, an element selector for top, bottom, both or none and a clockwork timer (-it is the 21st century) that goes ding when time has expired. It also turns off the heating elements when it hits zero.
You know, it does work. One cannot argue about the functionality for the price paid. However, the temperature control was not good. When set to say around 150 degrees (celsius) or above, the elements would never turn off and there was a suspicion of the smell of overheating plastic. It would cycle on and off if the set temperature was below around 120 degrees, but the whole temperature control was unsatisfactory.
The temperature dial was actually a simmerstat and the temperature of the oven is effectively only guessed, since there is no actual temperature measurement or feedback. Simmerstats are appropriate for hot plates, but ovens? I tried to readjust the simmerstat but this was difficult, and I only succeeded in making it switch on and off at too low a temperature even with the control at maximum. It did seem impossible to get just right. So, it was time for improved temperature control.
Temperature Controller article
The Axino-tech appliance power meter
Checking appliance power consumption
This article presents the design of an 230V appliance power meter. The meter not only reads out the real time rms voltage and current values, but has isolated sample outputs of both voltage and current for viewing on an oscilloscope or measurement via any sound card based system.
Appliance meter article
An AC auto-boost unit
Steps up low AC line voltage
Our Hoover washing machine stopped operating if our AC line fell below 234V. This unit provides for just 12V boost, which kicks in if the input side goes below 234V. Once the AC input reaches 241V, the unit switches back to bypass. I used a toroidal 12V+12V transformer, rated at 160VA; wired the secondaries in parallel and connected one side of the secondary winding(s) to the incoming mains in the sense that provided boost. The parallel connection means this transformer can deliver 13A, so is larger than is needed, but the next size down (80VA) I regarded as marginal for this application. Usually I prefer not to wire secondaries in parallel because a slight difference in voltage between secondaries causes additional transformer heating, however a well made toroidal type can be relied on to minimise this problem.
Auto-boost unit article
Build a microphone preamplifier
Using a THAT1512
Data sheet for the THAT1512 can be found here. This IC is designed from the ground up to improve on existing integrated microphone preamps by offering lower noise at low gains, wider bandwidth, higher slew rate, lower distortion, and lower supply current. The IC includes ESD overload protection on all critical pins.
My design evolved a little (some call it scope creep) to include some high-pass filtering, low pass filtering and a simple bar-graph level indicator. I decided to run the unit from +12V and so the design includes a 48V converter for the phantom power and balanced 15V rails for the audio stages. Most of the sub-sections are based on manufacturer data sheets or are off the shelf boards. This is however, not a step-by-step constructional project although experienced constructors should have no problem replicating the final design.
Mic preamp article
Axino-Tech Consulting & Services 2009-2017