View Single Post
  #16  
Old June 19th 04, 02:21 PM
Ian Smith
external usenet poster
 
Posts: n/a
Default Aquarium Lighting

On Fri, 18 Jun 2004 08:51:14 +0000 (UTC), david wrote:

"Ian Smith" wrote in message
...

On topic, it's a PIC that monitors and switches my tank heating (I
have three heaters and a particular sequence I want them to swicth in
, for various reasons). Although they have a useful current drive
it's obviously not uop to heating purposes, so the PIC drives a
transistor drives a mains relay.


is there a web page showing your pic stuff ??


Well, I'm nearing teh end of a four-channel on-board mixer for a
multi-engine radio control hovercraft that mixes speed, lift, steering
(via on-board gyro) and and idle setting from teh receiver, and
controls two three motors (lift and two thrust) and three servos (one
rudder and two proportional thrust reversers), but I guess it was teh
fish PIC stuff you wanted to hear about...

No, there's nothing about it on my web pages, though I keep vaguely
meaning to put it on.

The PIC heater controller is a long-running work-in-progress. Teh
head of the asm file is fairly informative:

; Ian's astounding digital thermometer system
;
; uses 16F877 pic
;
; The system has seven temperature sensors on AN0 - AN6,
; It averages AN0 and AN1 to give a virtual sensor on AN7
; All inputs are scaled so that 0 degC = 0V, 102.4 degC = Vdd
; Thus, can direct read ANx value as tenths of deg C
;
; AN7 is actually a control knob, which is read only in config
; mode, during which time temperature readings are suspended
;
; Control switches are on port B upper nybble
; RB7 on-board config switch (not currently used)
; RB6 'mode' switch
; RB5 +, yes, increment
; RB4 -, no, decrement
;
; Four outputs are on portb lower nybble, these are shuffled
; for ease of board layout
; RB3 output 4
; RB2 output 1
; RB1 output 2
; RB0 output 3
;
; Visual output is on port D, including an LCD in 4 bit mode
; RD7 heartbeat LED, on when processing
; RD6 LCD_E LCD Enable control line
; RD5 LCD_RW LCD Read/Write control line
; RD4 LCD_RS LCD Register-Select control line
; data bits are connected on low nybble:
; RD3 DB7 on LCD
; RD2 DB6
; RD1 DB5
; RD0 DB4

I've forgotten what teh sensors are - I'd need to dig my notes out,
but they look like standard small plastic transistors. They give an
output voltage that's linear with temperature over the range 0-120 deg
C, and I feed that through an op-amp to the analogue inputs of the PIC
to make interpretation easy (as described above). I solder them onto
the wires and encase teh ends (sensor and a little along teh
insulation of teh wire) in epoxy.

The sensors are two in teh tank, one in the sump, one in teh
room air, one internal in teh unit (near the voltage regulator
heat-sink). The room air and unit internal are just becaue I could -
the unit doesn't do anything with the values.

There are four mains relays, driven via a transistor driven by teh PIC
output. They switch mains power to sockets on teh back of teh unit
case.

The circuit is built on veroboard, so is physically larger than it
needs to be, but everything (including transformer and power supply)
fits in a nice case 205x180x70mm with aluminium front panel.

The front panel has a 16 character x 2 line LCD, three press-buttons
(mode, up-or-yes, down-or-no) and a knob to twiddle. There is an LED
for unit on, an LED heartbeat (so you can see it's working properly),
and LEDs fro each of teh switched outputs.

In normal operation the LCD shows the name of a sensor, teh current
temperature and on teh second line the max and min since last reset.
Pressing + or - steps through teh sensors.

Pressing mode for a couple of seconds goes to config mode where you
can clear max and min, and set the criteria for switching on outputs.
Also, there's a smoothing algorithm written in for teh temperature
sensors so a single bad reading doesn't switch teh heaters wrongly,
and in config mode you can switch that on or off. (I've never
detected a bad reading, but it seemed like a good idea so I wrote it
in).

Max, min and settings are all written to eeprom, so are not lost if
the power goes.

The criteria is the bit that's work-in-progress. At the moment it
just switches the three outputs on teh basis of a simple coded-in
criterion (two are on when teh average of the two tank sensors is
below 24 deg C, teh third when it's below 27 deg C). The code will
eventually let you set a criterion which works by switching on each
output when sensor 1 is above a set value and below another set value,
and sensor 2 is above one and below another and sensor 3 is above one
and below another and ... sensor 8. This lets you switch on
more-or-less anything, because if you don't want a sensor to
contribute you set it to 0 and 99.9 (on when above 0 and below 99.9 =
always on), if you want an output on below 24 you set on when above
0.0 and below 24.0, if you want on when above 27 (say, to swich on
cooling) you set on on when above 27.0 and below 99.9.

This will let me set things like heaters on when tank is below 24 and
sump is below 28 - teh heaters are in teh sump, and I wouldn't want to
boil teh sump if teh circulation pumps were off.

The 16F877 is probably overkill, but I did want more than four 10 bit
adc, plus 8 bits to control LCD, plus at least 4 outputs and 4 inputs,
plus a moderate amount of eeprom data, and decided that I'd get the
one with the maximum amount of program space that met those criteria -
hence 16F877. There's also a USART in there, and the pins for that
are currently unused, so I could have teh output on a serial port to a
PC, when I get round to it.

I'm not really sure why I haven't finished it off - it was more an
exercise to see if I could than to fulfill a need. When I started I
knew next to nothing about electronics (I did some in physics at
school over 15 years ago) and had never touched a microcontroller, but
I bought an electronics text-book by Horowitz & Hill and downloaded
masses of gumpf from Microchip's website and started reading. My
first PIC program and circuit switched a LED on when you pressed a
button, then switched it off four seconds after you released teh
switch. My second program and circuit was the temperature controller
- I favour the in-at-the-deep-end approach to learning!

Is there anything specific you wanted to know?

regards, Ian SMith
--
|\ /| no .sig
|o o|
|/ \|