• Afterthoughts…

    Scott02/06/2017 at 08:57 0 comments

    With the testing of the AVR Data Recorder completed and a few sample test runs, I was fairly satisfied with the performance and features I was able to pack into this little device. The flexibility, hardware support and program-ability of using AttoBASIC as the underlying “operating system” allowed me a level of features that I have not seen in other data recorders on the market.

    In using the AVR Data Recorder, I found that there were two features that I wanted to add.

    • Low battery detector
    • Temperature and humidity measurement

    Low Battery Detector: In hindsight, I realized that I had not included a means to measure battery level, report and act upon a low battery condition. The AVR series of micro-controllers supports a “brown out detector” but all it really does is set a flag in the MCU status register that a power supply voltage less that a preset value occurred. The AVR can then respond to that condition. However, in the case of the AVR Data Recorder, there wasn’t much I could do since AttoBASIC does not process nor respond to “brown out” conditions. I also did not have any extra analog channels (nor pins) available to monitor the battery, which could easily have been accomplished using AttoBASIC. I began looking for an external “low-battery” detector circuit. I found a few designs in applications notes from MICROCHIP, LINEAR TECH and TEXAS INSTRUMENTS using their very-low power op-amps but in investigating their actual run current, I found that they would just add to the battery drain more than I wanted.

    Not being satisfied with those solutions, I decided to investigate the power requirements of using an 8-pin TinyAVR. I had a tube of ATtiny13A’s available as well as some ATtiny25’s, 45’s, and 85’s but those would be an overkill in terms of available FLASH memory. The ATtiny13 looked like the right choice. It has an internal 1.2 MHz oscillator, an ADC and a few I/O pins. It would have to run off the 3 volt supply of the AVR Data Recorder but the Li-Ion cell could attain a charged voltage of 4.2 volts, too high for a direct ADC input. A simple solution was to add a resistor network voltage divider before the ADC pin but I wanted to conserve power and using the ADC would use extra power. The analog comparator uses very little power, so it was a good choice. I figured I could set a threshold for the analog comparator “AIN1” reference input by using one of the PWM channels to create a “poor-man’s” DAC, which requires only a resistor and capacitor and the original voltage divider method works with the analog comparator as well. Using the PWM to set the reference voltage allowed me to implement a sort-of hysteresis along with a voltage averaging to minimize variation in the battery voltage readings.

    To warn the user that the battery is low, I decided to add an LED that I could “blink” every few seconds. In testing, I settled on a 64 mS “blink” time and a low-current red LED.

    Like all AVR’s the ATtiny13A could enter a low-power sleep mode and I could use the watch-dog timer to wake it with a “system reset” every 8 seconds, which is the longest timeout available for the watch-dog timer. Essentially, I would just run through the program sequentially from RESET to END with each timed “wake-up”.

    The program sequence is as follows:

    1 RESET
    2 load preset AComp reference value
    3 set I/O ports
    4 set PWM to reference voltage
    5 wait for PWM to settle
    6 check analog comp
    7 if low-battery detected
       a) set LED on
       b) set WDT for IRQ @ 64ms
       c) sleep till WDT IRQ
       d) set LED off
    8 reset I/O ports
    9 sleep inpower-down” till WD reset
    
    The power consumption measurements were as such:
    1. AVR in powerdown = 4 uA
    2. AVR executing code for 64ms (setup and measure) = 160 uA
    3. AVR + LED “on” for 64ms = 1300 uA

    The average power consumption = 125 uA with LED on, 42 uA with the LED off. It
    beat the micro-power comparator...

    Read more »

  • Initial testing the hardware

    Scott02/06/2017 at 08:54 0 comments

    Once the PCB’s arrived and were assembled, I set out to test the individual components on the AVR Data Recorder. Once again, AttoBASIC was indispensable for this purpose. As of this post, the newest version of AttoBASIC (V2.34) is now available and adds support for several more AVR’s, including the ATtiny84 and ATtiny85.

    Testing was easy and all the functional blocks worked as expected. I had to build a separate precision 1.000 volt reference to calibrate the analog front end but that was a fairly easy project.

    One of the tests I ran was using the digital output to short a large capacitor then using the analog comparator with the Vref set to 66% of the charge voltage, wait for the charging voltage to reach the analog comparator’s trigger threshold. The data was stored in the “data file” (off-chip EEPROM), later retrieved and imported into a spreadsheet so the data could be graphed.

    The program used is shown below:

    5 EMI $0C #CLEAR SCREEN
    10 DFI 0 8; DFF 2; DFX # INIT 8 PAGES, 2 FIELDS PER RECORD, RESET ADRESS POINTER
    15 DIG 1; ADG 0 2      # INSURE CAP IS SHORTED AND SET CH 0 GAIN TO 1X
    20 R:= 16              # 2V ACO REF (0.1X ON ACO)
    25 ACR R; SLP 5        # SET ACO REF AND DELAY 500MS
    30 PRINT "TESTING ACO TRIGGER LEVEL...~" 
    35 FOR N= 1 10         # LOOP TEST 10 TIMES
    40 PRINT "RUNNING TEST   # "; PRINT N; PRINT "~" # PRINT TEST #
    45 DFL ADC 0; DFL ACO
    50 DIG 0               # RELEASE CLAMP ON CAPACITOR
    55 SLP 5; DFL ADC 0; DFL ACO   # SLEEP 500MS, TAKE AND STORE READING
    60 PRINT "SAMPLING ...~"
    65 IF ACO = 0 THE 
    70 GOTO 55                   # KEEP TAKING READINGS TILL ACO TRIGGERED
    75 PRI "~ACO TRIGGERED AT "; PRI ADC 0        # PRINT THE VALUE
    80 DIG 1                                      # CLAMP THE CAPACITOR
    85 NEXT

    The image below is the resulting data is presented as a charge voltage vs. time graph. The magenta line shows the state of the digital output, which was used to discharge the capacitor. The blue line shows the charge and discharge voltage across the capacitor.

    aco_dig_testAnalog Comparator Test

    The following program shows a typical usage for recording the 32-bit RTC value and all four channels of the ADC; Analog Channel 0, Analog Channel 1, TRMS Channel and the current reading channel. The RTC value is used as a “time-stamp”. Once the data is captured, it can be dumped from the AVR Data Recorder’s “data file” and imported into a spreadsheet for analysis.

    5 DFI 0 1 ; DFX # init the 1st page as we need only 80 bytes and reset pointer
    10 RTI 2; RTR   # set to 100mS update interval and reset RTC count
    15 FOR N=1 10   # contain to 10 iterations
    20 PRINT "N= "; PRINT N; RTP            # optional - print RTC on console
    25 A:=PEEK $5 $65; B:=PEEK $5 $64   # RTC registers at 0x0562 {MSB} to 0x0565 {LSB}
    30 C:=PEEK $5 $63; D:=PEEK $5 $62   # "$" means hexadecimal value follows
    35 DFL D; DFL C; DFL B; DFL A       # log all 32 bits to data file MSB to LSB
    40 DFL ADC 0; DFL ADC 1             # log Ch 0, 1 to data file
    45 DFL ADC 2; DFL ADC 3      # log TRMS and Current sense to data file
    50 FOR T=1 30                # SET UP 30 SECOND WAIT PERIOD 
    55 SLP 6                     # SLEEP FOR 1 SECOND
    60 NEXT T                    # CONTINUE LOOPING
    65 NEXT                           # loop to sample and record 
    70 DFF 8                    # set data format to 8 fields per record
    75 # once finished, use "DFD 0 1" to capture the data
    

    I later went on to monitor the dwelling’s water heater usage. It was a modified form of the above program. I had to design a Rogowski Coil and a front-end circuit to measure the water heater’s A/C current. I documented the construction technique in a PDF file here.

    The image below shows the water heater “on” time over a 7 day period. Though, the actual time is difficult to see in the graph.

    waterheater_test

    I spent a considerable amount of time creating a user manual and application note for this project. It contains information on the use of the AVR Data Recorder, specifications and programming techniques. The PDF file is here.

  • Designing the front and back panels for the enclosure

    Scott02/06/2017 at 08:53 0 comments


    With the PCB’s on order and the mechanical dimensions taken, I was able to start on laying out the front and back panels for my design.

    I used an old version of AutoCAD, which I had learned back in the mid-80’s. I don’t use it much these days but sometimes it comes in handy.

    The original front panel was used and all I added were the holes for the “ON/OFF switch”, Channel 0 and Channel 1 inputs. The square hole was just the right size to fit a USB mini-B plug through and was used to access the USB mini-B jack located right behind it on the PCB. Also present on the original front panel was a small whole, which had an LED behind it on the original device’s PCB. I used that as well by placing an LED behind it.

    The back panel was cut from a larger sheet of plastic that I had acquired at the local “surplus electronics” store. It was a soft plastic that had a smooth side and an “orange peel” side. It took no effort to drill the holes using my drill press and the 1:1 alignment guides I printed. Below is the JPEG image of the front and back panels after I decided what mechanical components to put where.

    _faceplate

    I also used the annotated 1:1 drawing printed on a full-sheet label, which I applied to each of the faces once the holes were drilled. This made a nice legend for each of the two panels.

    Since the AVR is using OptiBoot (part of the ARDUINO IDE support files) for it’s boot-loader, I added a switch to enable switching in and out the DTR signal from the USB-to-Serial bridge. The DTR signal is used to pulse the RESET line of the AVR to initiate the boot-loader for programming. However, in debugging, the ATmega328P uses ATMEL’s DEBUG-WIRE® protocol and having the DTR signal connected causes DEBUG-WIRE® not to function.

    The 2nd switch is used to tell AttoBASIC, which the AVR Data Recorder is using as it’s “operating system”, whether or not to auto-load and run the 1st program saved in EEPROM. Using this method, the AVR Data Recorder can be used as a “stand-alone” device or in “interactive mode”.

    Below is the JPEG image of the legend text.

    _faceplate_text

  • Designing the PCB

    Scott02/06/2017 at 08:48 0 comments

    With all the features I could think to add into the AVR Data Recorder and having taken the available PCB dimensions, it was time to set out laying out the PCB. I won’t spend a lot of time on this subject but suffice it to say, I ordered 5 PCB’s from PCB Fab Express (http://pcbfabexpress.com).

    WORDPRESS does not allow TXT and ZIP file uploads, so in my opinion, WORDPRESS is great if you are posting multimedia content but inflexible when it comes to posting project files. Thus, I have set up a PUBLIC link to the ZIP file with the GERBER files here. JPEG images of the GERBER layers are below.

    _datarecorderv100_gerber-1

    _datarecorderv100_gerber-2

    _datarecorderv100_gerber-3

    _datarecorderv100_gerber-4

    _datarecorderv100_gerber-5

    _datarecorderv100_gerber-6

    _datarecorderv100_gerber-7

    Once the PCB’s arrived, they assembled without any issues.

  • Hardware Features

    Scott02/06/2017 at 08:47 0 comments

    While thinking about the features I wanted for my AVR Data Recorder, since it will be AVR based, I wanted to use as many feature of the on-chip peripherals as possible, so I came up with a preliminary list;

    • 2 analog channels with programmable gain and attenuation
      • bipolar inputs
      • true RMS reading for complex A/C waveforms
    • a means to accurately measure current through a device
    • an analog comparator to detect “events” to start and/or stop data capture
    • a high-current digital output for switching loads, perhaps driven by a low-frequency source
    • a means to record data and “time stamps” to EEPROM
    • a means to replay or dump the captured data
    • a means to “set and forget” with a single push-button to start the data capture
    • run on a rechargeable power source
    • programability
    • nice plastic enclosure with a front and back panel
    • above all, use components that I already have in stock

    To that avail, here are the parts I selected to accomplish those hardware requirements:

    Enclosure: I happened to run across some nice “used” plastic enclosures at the local surplus electronics store. Some of them had existing PCB’s in them, which meant that there was internal mounting posts for those PCB’s. Since this was intended to be a “one off” project, I settled on a nice plastic enclosure measuring 5 x 5 inches with a removable aluminum front and back panel. I could make use of the front panel but the back panel was not going to suit my purposes. I did however, have some soft plastic sheeting that I could easily and accurately cut with a utility knife. With an enclosure decided upon, I removed it’s PCB and took some dimensional measurements to determine how much PCB area I would have available for components and off-board connectors.

    AVR Data RecorderAVR Data Recorder

    AVR Data Recorder - front panel

    AVR Data Recorder – front panel

    AVR Data Recorder - back panel

    AVR Data Recorder – back panel

    The enclosure is shown in the left photo above. I am getting a little ahead of my build here but the middle and right photos show the final front and back panels.

    _datarecorder_1v00aAVR Data Recorder Schematic V1.00A

    The above schematic is available as a PDF file here.

    2 analog channels: The ATmega328P (U13) contains a 10-bit ADC and can sample 9 channels plus “ground” (0.0 volts), the internal 1.10 volt reference and the on-chip temperature sensor. I would only be using 2 of the analog channels for the variable-range analog inputs because adding more would mean adding more gain and attenuation circuitry. Note that although the two analog inputs are “bipolar”, the ATmega328P is not. Meaning that the ATmega328P can only measure voltages between o.0 and “Vref” volts. In hindsight, I would have been better to select the ATmega32U4 because it does support “bipolar inputs” and has a built-in USB hardware interface.

    Programmable gain and attenuation: The AVR’s input range is limited to it’s (internal or external) Vref, which means it’s input range would be only 1.10 volts. To gain a broader range, I elected use a 2.50 volt reference to extend the range between 0 to 2.50 volts. 2.50 volts maximum on the input is just not enough, so I would need an input attenuation circuit to measure higher voltages and an input gain circuit to accurately measure voltages that could be under 0.5 volts.

    I already knew how to use operational amplifiers to create gain and attenuation circuits but what I needed was a way to program the gain. Decades ago, I had designed an ADA compliant PUBLIC telephone handset for the “hearing impaired”. In that circuit, I used a series of two MOSFET’s to switch different gain setting resistors (R7, R8, R9 and R10). I did not wish to use any discrete MOSFET’s if I could, so I decided to look into the 4000 series of CMOS logic. From what I recalled, there was the CD4066 and CD4052 analog switches, which I had used on other analog circuit designs years ago. I settled on the 74HC4052 (U3), which is a “Dual 4-channel Analog Multiplexer/Demultiplexer“....

    Read more »

  • A Versatile AVR-based Data Recorder

    Scott02/06/2017 at 08:46 0 comments

    Once upon a time, I became interested in monitoring power usage of certain appliances and devices in my dwelling. In particular, the water heater and refrigerator. I wanted to be able to monitor their power consumption over a duration of time and knew I needed some sort of data recorder. I could purchase one but the better ones with 10 or 12 bit ADC accuracy were expensive. The lower priced ones seemed a bit underwhelming in feature as they were very basic. And yes, there were a few projects on “the net” at that time, even more nowadays. However, there was one thing they lacked and that was some sort of programmability.

    Since I was very heavy into further enhancing AttoBASIC, I decided that it would be very easy to modify AttoBASIC by adding specific commands to support a data recording device. After all, I had recently added a real-time counter and “data recording to external EEPROM” features that would suit this project’s purpose very well.

    What I came up with is the AVR Data Recorder, which is a versatile programmable device that can, among other things, be used to capture and store analog data for retrieval at a later date.

    The programmability of this device is due to the AttoBASIC V2.xx interpreter with specific language extensions for use with the AVR Data Recorder. The interactive ability of AttoBASICmakes it easy to set up individual channel gain and attenuation levels, print measured ADC values when writing, debugging, data capture and recording programs.

    20170124_092924AVR Data Recorder

    Although this project was completed mid-August of 2012, I have decided to post it in a more accessible location. The project can be found hereon AVRfreaks.net as well. Note that AVRfreaksrequires a free account to access its content.

    I will post a series of blog entries to document the design and fabrication starting with it’s features.

    Features at a glance
    • Processing core is an ATMEL ATmega328p running at 8MHz.
    • Versatile; can be used as a stand-alone data capture and recording device or connected to a USB serial console for real-time display and capture of data.
    • Portable; Internal Li-Ion rechargeable battery runs up to 14 days on a single charge.
    • Two (2) channels of analog input;
    • 8-bit analog resolution (9.8 mV / bit @ 1x gain, post-attenuation).
    • Each channel is bipolar (+/-) with respect to ground, reading is positive only.
    • Software selectable input attenuation for a range of 2.5volts, 25 volts and 250 volts.
    • Software selectable input amplifier extends sensitivity to 250 millivolts per channel.
    • One (1) channel of True-RMS reading, software selectable between either analog channel (post-attenuation).
    • Current sensing input with a range of 0 to 250ma, 0.5Ω series resistance, externally extensible.
    • Analog comparator input;
      • Comparator source is software selectable between dedicated input with fixed 0 to 25 volt input range or either analog channel (post-attenuation).
      • 8-bit programmable reference.
    • Digital output for control of external devices;
      • Open-drain “low-side” N-MOSFET solid-state switch with 175 mΩ “on” resistance can switch up to 60 volt loads with 1.5 amps of continuous current.
      • DDS (direct digital synthesis) for toggling at a specific frequency (1 Hz resolution, 1 Hz minimum frequency).
    • Digital temperature and humidity sensor
    • 64K bytes of internal data storage capability in non-volatile memory.
    • Pre-programmed “out of the box” to record a 24-bit time stamp and both analog channels every 60 seconds for data recording up to 218 hours.
    • “Data” LED indicates data file access.
    • Programmable;
      • Uses AttoBASIC programming language, a Tiny-BASIC with an enhanced hardware-orientated command set.
      • Programs can be saved in internal non-volatile memory for execution.
      • Switch-selectable “self-start” feature enables immediate user program execution upon power-up or an interactive (command prompt) mode for test, measurement and programming.
      • Programmability creates a stand-alone intelligent...
    Read more »