This was my first 1-wire mini project. Because I had ‘home’ server in bedroom, silence was important:-) So, I made simple fan control using DS2413 1-wire switch. With temperature sensors (DS18x20), owfs and bash script it makes a really nice toy. It supports 3 fan states: full (12V), half (7V) and stop. There are configurable temperature thresholds for each state, hysteresis and threshold shift based on the time of the day. It allows server to be cool during a day, but during a night silence is priority, so scripts allow higher cpu temperature. This script monitors two temperature sensors, because I had 2 CPU PC. If you want to use this with only one CPU, you can configure the same sensor addresses for both CPUs in script. This shouldn’t affect performance because of caching feature of owfs. Script also have ‘spin-up’ feature – because not all fans can start at 7V, but all works fine after spin-up, so if script wants to turn on fan at half speed, first turn it on at full speed for 3 seconds and then slow down to half. This guarantee that fan is working.
Script is working in background and make some logs…
This is my second 1-wire project. This is ‘simple’ charger/discharger based on LM317T chip, with typical application with current limit, controlled and monitored by 1-wire chips. Basic assumption was to have charger, so relays are configured in the way, that even without computer connection, it charges batteries. There are two 1-wire chips:
- DS2413 – switch: it is used to control two relays. Possible combinations are:
- and fourth, not used: charge with load attached
- DS2450 – ADC: it is used to monitor:
- total voltage on battery (+)
- voltage of first ground resistor (to calculate charge current)
- voltage of second ground resistor (to calculate discharge current)
Two resistors are necessary because DS2450 can’t measure negative voltage. Battery voltage are calculated depending on mode (charge/discharge/off) from measured values.
There are external connectors to connect:
- load (I’m using 1 Ohm resistor with 1 Li-Ion battery)
- power supply
- 1-wire bus
There are also two jumpers to allow set voltage (from 1 to 4 cells) and divider for voltage measurement (1/1, 1/2, 1/4) to allow monitor higher voltages than DS2450 can support.
- JP2 – voltage divider for ADC
- 2-3: 1/1
- off: 1/2
- 1-2: 1/4
- JP1 – voltage preset
- 1-2: you can set voltage for 1 cell with R5
- 2-3: you can set voltage for 2 cells with R5
- off: you can set voltage for 4 cells with R13. If you have trimmed voltage for 2 cells, you can quickly switch between charging 2 and 4 cells.
This is controlled by ‘simple’ bash script which uses owfs. This script growed up to program which even make corrections to ADC errors, make cycles of charge/discharge with configured delay between charge and discharge, and of course: it counts battery capacity (mAh). You can also configure thresholds to stop discharge (battery voltage) and stop charge (minimum current). There is additional script to make ADC calibration file from simple file with pairs: real voltage and ADC measured voltage. This should be done to minimize error when measuring low voltages to calculate charge current. Script also generate log, which can be used to draw charge/discharge diagrams.
Scripts with sample calibration data you can download here: ladowarka.tgz
Why this chips? Because I have it:-) Next version will be based on better chip DS2438 instead of DS2450. Stay tuned!
Update @23 August 2012
- This is a copy&paste of my old page almost without changes into blog. Publish date is set to original date when this page was last updated
- Scripts could work or not as I haven’t used it for years and I couldn’t test it right now.
- Really use DS2438 or similar chip for voltage monitoring as DS2450 is very unreliable in my opinion. I changed circuit many times, changed DS2450 for another piece (of shit) and it never works as it should. I also found somewhere similar opinions, so be warned. I made this charger using DS2438 chip later and it works just fine. Sorry, no schematic with it but it should be easy to replace DS2450 with DS2438.
- My good advice: this charger should be used for educational purposed only. I found 1-wire/Owfs too unreliable to rely on it during discharge of cells. I had few occurences of bus or owfs hangs during charging/discharging and I lost few cells – they discharged to 0 and were dead after that. Charging is safe as curcuit based on LM317 is designed that way, so no explosions and other overcharge special effects are expected 🙂
- And one remark/warning to electronic guys: owfs is made by programmers, so study carefully man pages because some chips have negated logic: you set 1 on output and it gives you 0 because 1 appears to mean ‘short’ on open collector/drain output (to them). Yes, I know, this is *** but it can’t be helped. I tried to fix/explain it somewhere in 2005 but without success (reason: backward compatibility).
Have fun, but don’t trust 1-wire.