Regarding the discussion about Picaxe or AVR I also read a comment about the speed of the picaxe controllers.
I wonder why it should be slower since itīs also running at 4 Mhz. It canīt be only the compilation since C-compiled code is not much smaller than basic compile code.
What I experience is, that clever assembler program code is much smaller than both of them.
Anyways,
I added the code for the described functions and deleted the readout of the reciever channel, I hope this helps a little bit ;-)
It was a little bit more work than I thought, and the size of the code increased to 2,1kb.
So NOW you have to go with AVR
It can be optimized by defining the variables different, but I think you will always scratch the maximum of the picaxe, which is not a good idea.
I really tried to make it understandable, but Iīm open to questions.
Maybe you also add your description on the functions here, that might help others.
If you want to change the pin configuration on the attiny due to your circuit layout, you just have to change the ALIAS functions and input/output settings. Just be careful with the ADC numbers, since these are fixed to a certain pin.
You canīt work with Aliases here.
TO compile the code you need BASCOM (free version up to 4kb code is enough).
Itīs probably still full of errors but I did not find the time to simulate or test it in reality.
I have to finish my 16 channel universal multi switch for 2,4 GHz radios and will be on short vacation for the next 3 days.
Just a few additional questions:
Is the feed tank sensor also giving an analogue output or is it "digital" low/high, I guessed the sensors a comparable and both need calibration?
And both level sensors work on the same valve/servo? Thatīs how it is programmed right now.
What should happen if both water levels are low at the same time? Bypass Valve opened and Warning LED lit I guessed? What about the gas valve?
One thing Iīm a little curious about. Do you want a 2 point regulation for the gas or or proportional regulation.
Does the pressure sensor have an linear voltage output according to pressure? If yes a proportional regulation of the servo is possible.
But I have no idea if this is necessary (would it save gas? prevent overpressure valve from letting out steam?) or not.
The setup works like this, I thought of a 2 way toggle switch, if itīs just a push switch you have to change the code.
Press Switch low (input on Attiny is connected to ground) and then power on the module with 5V --> it goes into setupmode
All 3 LED are blinking
place boiler sensor above water level and press switch to high
wait for 1s
place boiler sensor below water level and press switch to low again
1 LED stops flashing, 2 LED still flashing
place feed tank sensor above water level and press switch to high
wait for 1s
place feed tank sensor below water level and press switch to low again
1 LED stops flashing, 1 LED still flashing
Pilot flame adjustment, Servo is set to 2ms at the beginning of setupmode (what setting should the "water servo" have during setup?)
You adjust the pilot flame now
Press Switch to high, last LED stops flashing
Disconnect module from electric power
Press Switch to high
Wait for 30s
Repower the module with switch=high and it starts in normal mode with calibrated water level sensor without flashing the LEDCan you somehow calibrate the pressure sensor (with external pump, without steam pressure)? Maybe you do this once, and manually change the value before flashing the chip (pressuresensvalue=512 = 2,5V)
And also a recommondation regarding your circuit.
Best is to separate servo and chip power (even if itīs just 2 different BEC modules)
If this is (as in most cases) not possible, do not just put a 100n cap between VCC and GND of the chip.
You need a bigger cap to decouple the interference from the servoīs and a strong power supply, otherwise you may get some very strange reactions from brown outs to erasion of the non volatile memory.
'******************************************************
'
' (c)2014 Tobias Birkner / For Non-Commercial use only
'
'******************************************************
'Project: Cheddar ABC Clone
'
'Prozessor: Attiny44
'Bascom-Version: 2.0.7.7
'
'
'Version 2.0
'1.0 06.08.14 Test Program
'2.0 07.08.14 Completed code for automatic boiler control
'******************************************************
'
'======================================================
'System
'======================================================
'Definition Attiny
$regfile "ATTiny44.dat"
' (8Mhz)
$crystal = 8000000
$hwstack = 32
$swstack = 10
$framesize = 40
' Pin configuration
Config Pina.0 = Input 'Boiler lvl sensor
Config Pina.1 = Input 'pressure sensor
Config Pina.2 = Input 'Pilot flame pot
Config Pina.3 = Input 'Feed tank lvl sensor
Config Porta.4 = Output 'Servo1
Config Porta.5 = Output 'Servo2
Config Porta.6 = Output 'LED
Config Porta.7 = Output 'LED
Config Portb.0 = Output 'output for FET
Config Portb.1 = Output 'LED
Config Pinb.2 = Input 'Setup Mode Switch
Portb.2 = 1 'internal pullup on
Sensorcalibswitch Alias Pinb.2 'Digital in, internal pullup switched on, but you can add an external pullup resistor
Servo1 Alias Porta.4
Servo2 Alias Porta.5
Waterlowled Alias Porta.6
Gashighled Alias Porta.7
Waterbypassled Alias Portb.1
Electricpump Alias Portb.0
'Konfiguration des Timer 1
Config Timer0 = Timer , Prescale = 1024 'timer for hyteresis 10s
Config Timer1 = Timer , Prescale = 8 'timer for servos
Config Adc = Single , Prescaler = 64 , Reference = Avcc
Start Adc
Dim Reading As Bit
Dim Rc_value As Word
Dim Analogueinput(4) As Word
Dim Kanal As Byte
Dim Servo(2) As Word 'theoretical 1000 values resolution. 64036 = Middle +500 -500 = normal servo way 90°, increase for 180°
Dim Eedummy As Eram Byte 'dummy since first adress is buggy
Dim Watersensvalue(2) As Word 'average value between "no water present" and "Water present" 1= boiler 2=feed tank
Dim Eewatersensvalue(2) As Eram Word 'saved value in EERAM
Dim Waterpresent(2) As Byte 'flag for 10s delay
Dim Tensecond As Word 'counter to increment since timer0 is too fast at 8Mhz
Dim Pressuresensvalue As Word 'average value between "pressure high" and "pressure low"
Dim Eepressuresensvalue As Eram Word 'saved value in EERAM
Dim Pilotflame As Word 'Amount of regulation value for pilot flame
Dim Calibstate As Byte 'flag for setupmode
Dim Ledtoggle As Byte 'counter to toggle LED during setup mode
Const Smv = 64036 'Servo Middle Value
'Interrupt-Service-Routines
On Timer1 Servoirq 'servo
On Timer0 Waterirq
'Enable anything
Enable Timer0
Stop Timer0
Enable Timer1
Start Timer1
Enable Interrupts
'Initialize before main program
Servo(1)=SMV+500 '1ms pump bypass valve open
Servo(2)=SMV-500 '2ms only Pilot flame at startup
Calibstate=0
If Sensorcalibswitch = 0 Then
Goto Calibration
End If
watersensvalue(1)=EEwatersensvalue(1)
Waitms 10
If watersensvalue(1)=0 then 'only for first startup, if no calibration value is present
watersensvalue(1)=512
End IF
watersensvalue(2)=EEwatersensvalue(2)
Waitms 10
If watersensvalue(2)=0 then 'only for first startup, if no calibration value is present
watersensvalue(2)=512
End IF
'pressuresensvalue=EEpressuresensvalue 'not needed right now
'waitms10 'not needed right now
pressuresensvalue=512
'main program
Do
'read ADC
Analogueinput(1) = Getadc(0)
Analogueinput(2) = Getadc(1)
Analogueinput(3) = Getadc(2)
Analogueinput(4) = Getadc(3)
'Check if water present with optical sensor
If Analogueinput(1) <= Watersensvalue(1) Then 'ADC0
Servo(1) = Smv + 500 '1ms bypass valve open
Waterpresent(1) = 1
Waterlowled=0
Electricpump=0
Tensecond = 0
Stop Timer0
Endif
If Analogueinput(1) > watersensvalue(1) then
Start Timer0
End if
'Check Feed Tank Level Sensor
If Analogueinput(4) <= Watersensvalue(2) Then 'ADC3
WaterbypassLED=0
waterpresent(2)=1
Endif
If Analogueinput(4) > Watersensvalue(2) Then
Servo(1) = Smv + 500 '1ms pump bypass valve open, overwrites "bypass valve closed due to low lvl in boiler"!!!
waterpresent(2)=0
WaterbypassLED=1
End If
'alternate programming with digital sensor voltages
'If Tanklvlsens=0 then
' WaterbypassLED=0
' waterpresent(2)=1
'Else
' Servo(1)=SMV+500 '1ms pump bypass valve open
' WaterbypassLED=1
' waterpresent(2)=0
'End IF
'Boiler pressure regulation
'Read and calculate Pilot Flame Pot
Pilotflame = Analogueinput(3) / 10 'ADC2, makes a maximum of 102 = 0,102 ms, by dividing it just by 5 it will reach 20° max
If Analogueinput(2) <= Pressuresensvalue Then 'ADC1
Servo(2) = Smv + 500 '1ms
GASHIGHLED=1
End If
If Analogueinput(2) > pressuresensvalue then
Servo(2) = Smv - 500 '2ms
Servo(2) = Servo(2) + Pilotflame 'if servo is jittering use another variable to combine these calculations and give out only 1 value
Gashighled = 0
End If
Loop
End
Servoirq:
If Kanal = 0 Then
If Servo1 = 0 Then 'if port low
Timer1 = Servo(1) 'timer1 on reload value
Servo1 = 1 'port=1
Else 'happens at next interrupt
Servo1 = 0 'port=0
Incr Kanal 'next servo
End If
End If
If Kanal = 1 Then
If Servo2 = 0 Then
Timer1 = Servo(2)
Servo2 = 1
Else
Servo2 = 0
Incr Kanal
End If
End If
If Kanal = 2 Then
Timer1 = 53536 'Pause for 16ms
Kanal = 0
End If
Return
waterirq:
incr tensecond
Timer0=0
If Tensecond > 304 And Waterpresent(2) = 1 Then '304 = 10s = 304x32,8ms for 1 timer overflow
waterpresent(1)=0
Servo(1) = Smv - 500 '2ms bypass valve closed
Waterlowled=1
Electricpump=1
End If
Return
Calibration:
DO
INCR LEDtoggle
Analogueinput(1)=Getadc(0)
Analogueinput(2)=Getadc(1)
Analogueinput(3)=Getadc(2)
Analogueinput(4)=Getadc(3)
Pilotflame = Analogueinput(3)/10
Servo(1) = Smv + 500 ' 1ms
Servo(2) = Smv - 500 '2ms if servo is jittering use another variable to combine these calculations and give out only 1 value
Servo(2)= Servo(2)+Pilotflame
If Ledtoggle > 100 Then 'Toggle cycletime depending on time needed for ADC
IF Calibstate=0 then
Toggle WaterlowLED
Toggle GASHIGHLED
Toggle WaterbypassLED
End if
IF Calibstate=<2 then
WaterlowLED=0
Toggle GASHIGHLED
Toggle WaterbypassLED
End if
IF Calibstate=<4 then
WaterlowLED=0
GASHIGHLED=0
Toggle WaterbypassLED
End if
IF Calibstate=<5 then
WaterlowLED=0
GASHIGHLED=0
WaterbypassLED=0
End if
End if
'Calibration Boiler sensor
If Sensorcalibswitch=1 and Calibstate=0 then
Watersensvalue(1) = Analogueinput(1) 'Measures voltage without water when switch is switched on again
Calibstate=1
End If
If Sensorcalibswitch=0 and Calibstate=1 then
Watersensvalue(1) = Watersensvalue(1) + Analogueinput(1) 'Measures voltage with water when switch is switched off again
Watersensvalue(1) = Watersensvalue(1) / 2
Eewatersensvalue(1) = Watersensvalue(1) 'writes average sensor value on EERAM
Waitms 10
Calibstate = 2
Waterlowled = 0
End If
'Calibration feed tank sensor
If Sensorcalibswitch = 1 And Calibstate = 2 Then
Watersensvalue(2) = Analogueinput(4) 'Measures voltage without water when switch is switched on again
Calibstate=3
End If
If Sensorcalibswitch = 0 And Calibstate = 3 Then
Watersensvalue(2) = Watersensvalue(2) + Analogueinput(4) 'Measures voltage with water when switch is switched off again
Watersensvalue(2) = Watersensvalue(2) / 2
Eewatersensvalue(2) = Watersensvalue(2) 'writes average sensor value on EERAM
Waitms 10
Calibstate = 4
GASHIGHLED=0
End if
If Sensorcalibswitch=1 and Calibstate=2 then
Calibstate=5
WaterbypassLED=0
End if
Loop
End