(This is an initial write-up for this project. More description work is still needed.)
I am one of the "fontainier" at l'ASAEP, our local water association. We own and operate our own water sources, pumping stations, distribution network, up to the water meter at the final user's home.
Our network comprises more than 30 miles of underground pipes, and we needed a tool to better understand the demand on the network. We already have water meter equipped with a small magnet which closes a small switch and therefor can be used to generate pulses. This system is specifically used to control the pumps that inject chlorine in the water.
The goal of the project is therefor to collect data about the amount of water that went through a location, for example at ten minutes intervals. The system must have very low power consumption so that it can work unattended for weeks on regular batteries. (The system might be left for example in a meter box in the middle of a field.)
Environnement du projet
Je suis volontaire à l'ASAEP, notre association locale de distribution de l'eau. Nous possédons et opérons nos propres forages et captages, notre réseau de distribution, nous faisons les relevés de compteurs chez les usagers...
Notre réseau a plus de 50 kms de tuyaux enterrés, et nous avions besoin d'avoir un outil qui nous permette de mieux connaître la demande sur le réseau. Nous disposons déjà de compteurs d'eau qui, équipé d'un petit aimant sur une des roues de comptage, et d'un système de détection, permet de délivrer une impulsion (par fermeture d'un contact). Essentiellement, ce compteur amélioré génère une impulsion par litre. Ce système est utilisé en particulier afin d'asservir les pompes qui injecte le chlore dans l'eau.
Le but du projet est alors de collecter les volumes consommés, par exemple en faisant un relevé toutes les dix minutes. La consommation électrique doit être extrèmement basse, afin de faire fonctionner le circuit pendant des semaines sans intervention sur de simples piles. (L'idée de base étant qu'un tel système peut être installé au milieu d'un champ, avec de faibles opportunités de relevé dans certains cas.)
One pulse is received per liter, we use 16 bits counters so up to 65 cubic meters can be measured in one counter.
The amount of data collected is too large to fit comfortably in the RAM or the EEPROM of an AVRtiny, and larger AVRs have too large a power consumption. A DataFlash chip was added to provide data storage. The selected DataFlash offers 264 octets per page (up to 128 measure points, so about 21.5 hours of measuring with a sampling interval of 10 minutes), and 1023 data pages. The first page is used for communication between the USB module and the water-metering module.
The project is split in two parts:
- a module that is connected to the water meter and left on-site to collect data; this module runs at very low frequency (128kHz without external components)
- a module that connects to the first module and to a USB interface in order to retrieve data, and runs at 12MHz
Additionally both modules can be programmed via ISP using the pinout of the STK500 ISP6PIN interface.
I chose the AVRtiny2313A because it is the component used by the usbtiny library, and it offers low-power usage while having a good deal of interfaces. The same AVR is used on both modules.
The Atmel documentation for the DataFlash uses an old layout (especially a RDY/BSY pin that is no longer present on current DataFlash chips); I hope this design will be helpful to people trying to interface and AVR with the current generation of DataFlash.
The first module also hosts the memory chip; the interface between the two modules is designed so that the water-meter module releases the DataFlash bus when the USB module is connected.
This module has a LED used for debugging purposes, a two AA-battery power supply, a connector for the water-meter magnet-activated switch, a connector for the USB module and ISP, the Atmel microcontroller and flash.
The microcontroller is programmed by connecting the STK500 ISP6PIN port to J1 on pin 1-6. The connection with the USB module is done using pin 1-6 and 9-10 (pins 7-8 are left unused to allow for cable orientation).
At startup the LED will flash a couple seconds to indicate startup and detection of the DataFlash module, then go steady off if everything is working. The LED will flash on/off every four seconds if the system is ready but no pulse is received from the metering switch.
The module doesn't have a crystal and uses the (low-power) internal 128kHz clock of the AVR. However the clock is not extremely precise (it runs at roughly 110kHz around 3V) and this has to be compensated for.
The water-meter AVR is taken off the DataFlash bus (DO, DI, SCK, Flash CS) by activating the Flash RESET pin. Once the Flash RESET pin is brought back up, the Flash is available to the USB module. At the end of its use of the Flash, the USB module brings the Flash RESET pin back down (active) to indicates the Flash bus can be taken back by the water-meter AVR.
This module has a LED for debugging purposes (controlled by the PC connected to the USB bus), a 12MHz crystal, a USB connector, and the same J1 connector as the water-meter module. The power supply is local (two AA-batteries).
The microcontroller is programmed through pin 1-6, while the entire connector (pins 1-6 and 9-10) must be connected to the water-module for access to the DataFlash.
The USB bus uses 3V voltages, so no adaptation is needed as long as the battery power supply is used.
All operations are controlled by the host connected on the USB bus: Flash Reset, sending commands and receiving data, etc. Due to limitations in the usbtiny design the data is transferred by blocks of 8 octets at one time.
This module can probably be used as a generic USB-to-DataFlash transfer module.
USB client (on PC host)
The USB software on the PC host is designed for Linux with libusb 1.0.
The software will issue the commands through the USB module in order to take the water-meter module's AVR offline, retrieve data from the DataFlash module, and save new data (especially realtime clock) onto the flash.
git clone git://shimaore.net/git/compteur.git
posted: 2011-05-29 17:38