;This application uses a horizontal anemometer style propeller on on the end of ;a pole that is immersed to measure river velocity at various lewvels. ;It has a magnet on the rotor which closes a red switch each time it rotates ; and the Picaxe times this after the "take a reading" button is pressed ; then sounds this out as seconds first then the tenths of a second ;A calibration graph needs to be produced with known flows measured by ;timing a floating item over a fixed distance ; ;NOTE: this works but needs a better design of the sensor impellor head we used as it tended to get locked by ; the current flowing around it at its minimun obstruction position. Also for faster water velocities the program ; should be modified to do a few meaurements then everage them as it measure s the time between pulses which could ; be a bit erratic if there was a lot of turbulence in the water flow ;This program is a written in the battery box picaxe 14m controller ;hardware which provides the following functions ;external input 1 - connected to reed switch via two pins nearest to edge ;green LED at standbyy up is connnected to display sensor input pulse ;amber led is lit after the take a reading pusbutton is pressed ;red LED indicates that an error has ocurred high squeeks on sounder ; alrm blip followed by ; +0 squeek = 30 sec reminder power is on and in standby mode ; +1 squeek = rate is is less than 0.1 revs/min ; +2 squeek = rate is greater than 9.9 rev/sec ; ;serial in and serial out connection to a computer vis a 3.5mm stereo plug ; input 0 = ADC - light dependent resistor to detect daylight and synchonise tie of day ; input 1 = external input on pin 2 of the connector - there is an internal pull up resistor 10kohm (microswitch) ; input 2 = external input on pin 3 of the connector - there is an internal pull up resistor 10kohm ; input 3 = test pushbutton on unit - to extract internal data etc anddisplay on LEDS ; input 4 = ADC - Infrared detector to detect local body heat ;output 1 = to drive high the pull up resistors on the ADC inputs above (so they do not drain battery power) ;output 2 = to drive piezo sounder ;output 3 = to drive dedicated green LED ;output 4 = to drive amber LED and also to external output pin 4 via darlington solenoid / motor driver ;output 5 = to drive red LED and also to external output pin 5 via darlington solenoid / motor driver ;Internalconnection: symbols (tba means - to be assighned leter) symbol red = 5 ; Red LED (and output below) symbol amber = 4 ; Amber LED ( and output below) symbol green = 3 ; green LED ( and output below) symbol sounder = 2 ; Sounder symbol adcon = 1 ; ADC ower to sensors to take a reading. symbol light = 0 ; light dependant resitstor symbol pushbutton = pin3 ; test button symbol infrared = 4 ; LED infrared detectior ;extrnal connection symbols: symbol reedswitchpin = pin1 ; switch across pin 1 and 2 on connector symbol reedswitch = 1 symbol tba_in2 = 3 ; switch across pin 1 and 3 on connector symbol tba_out4 = 4 ; motor or lamp across pin 4 and 6 of connector symbol tba_out5 = 5 ; motor or lamp across pin 5 and 6 of connector ;******************************************* ;Register use Total of 14 bytes (use this to keep track of what you use for each kind of store) ;word layout = ------------- high byte (0-255) ------------ --------------low byte (0-255) ; bit15 bit14 bit13 bit12 bit11 bit10 bit9 bit8 bit7:bit6:bit5:bit4:bit3:bit2:bit1:bit0 ; 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 ; byte maximun if all bits set =255 ----- ; word maximum if all bits set = 65 535 -------------------------------------------------- ;symbol w0 symbol flags = b0 ;Allocate first byte as 8 single bit flags ;(redefine symbols flag1 etc with your own flag name) symbol flag0 = bit0 ; symbol flag1 = bit1 ; symbol flag2 = bit2 ; symbol flag3 = bit3 symbol flag4 = bit4 ; symbol flag5 = bit5 ; symbol flag6 = bit6 symbol flag7 = bit7 symbol wb1 = b1 ; 3 GENERAL PURPOSE WORKINGBYTE REGISTERS ;symbol w1 ; ; symbol wb2 = b2 ; symbol wb3 = b3 ;symbol w2 ; 6 BYTE OR 3 WORD REGISTERS TO DEFINE IN PROGRAM ; symbol tba1 = b4 symbol tba2 = b5 ;symbol w3 symbol tba3 = b6 symbol tba4 = b7 ;symbol w4 symbol tba5= b8 symbol tba6= b9 symbol ww2 = w5 ;UO TO 2 GENERAL USE WORKING WORD REGISTERS ;(USED TO PASS PARAMETERS TO MATHS SUBROUTINES ETC) symbol ww2l = b10 symbol ww2h = b11 symbol ww1 = w6 symbol ww1l = b12 symbol ww1h = b13 ;Storage variable space : (48 available) direct access with peek and poke commands ;********************************* symbol var_start = 80 ;start of command record table symbol var_end = 127 ;end of command record table ( total 227 entries possible) ; ;############################################################################################# ; Here are the instructions that make up the program ( break it into bits ) init: let ww1 = 0 start: nap 1 inc ww1 if ww1 > 1000 then goto error0 if reedswitchpin = 0 then goto st01 ; output pulse to green LED as a test let b1 = green low green goto waitstart st01: high green ;******************************************** ;read rotation time ( Period in 10 usecs) of impellor (MAX REV TIME APPROX 5 SECS) waitstart: if pushbutton = 1 then goto start ;wait for start button press low red low green high amber readper: ; clear store for result if reedswitchpin = 0 then goto readper ; loop until switch closes readper11: let ww1 = 0 let ww2 = 0 let wb3 = 0 pulsin reedswitch,0,ww1 if ww1 != 0 then goto readper09 ; timeout so keep on looking let wb3 = wb3+1 ;add another overflow (0.653 secs) goto readper11 readper09: let ww1 = ww1/100 ; save closed period in Msec readper12: pulsin reedswitch,1,ww2 if ww2 != 0 then goto readper13 ; timeout so keep on looking let wb3 = wb3+1 if wb3 > 15 then goto error ;add another overflow (0.653 secs) goto readper12 readper13: let ww2 = ww2/100 ; save open period in Msec readper14: let ww1 = ww1 + ww2 ; add open and closed periods let ww2 = wb3*653 ; work out the time taken in overflows let ww1 = ww1 + ww2 ; add to get total period in msecs (50000max 14,000msecs) let ww1 = ww1 /2 ; scale it to 50-500 let ww1 = 50000/ww1 ; convert to revs/sev revs.dec let ww1 = ww1/10 ;convert scal to 100 - 1 ; get to two places of decimal ;debug ;goto start goto pulsemsec ` ; **************************************** ;pulse out result on sounder pulsemsec: 'untitled tune sounder, 1,($10) ;Reading marker if ww1 < 1 then goto error1 ; revs/sec >9.9 if ww1 > 99 then goto error2 ; revs/ses let wb1 = ww1/100 ;get tens gosub pulseout let ww2 = ww1//100 ;get reminder let wb1 = ww2/10 ;get units gosub pulseout let wb1 = ww2//10 ;get reminder - decimals gosub pulseout low amber goto init pulseout: if wb1= 0 then goto pulseout1 tune sounder, 2,(200) pause 500 dec wb1 goto pulseout pulseout1: pause 1000 return ;*************************************** ;error routine error0: let wb1 = 0 goto error error1: let wb1 = 1 goto error error2: let wb1 = 2 goto error erorr3: let wb1 = 3 error: high red low amber tune sounder, 2, ($100) bleep: if wb1 = 0 then goto init pause 200 tune sounder,5,(10) dec wb1 goto bleep ;************************************************************************************** ;This is the old test program for the battery box (not used but it may give some ideas) ;low red ;high adcon ; put supply onto the ADC's ;pause 100 ;readadc light,b0 ; put light reading into a0 ;pause 100 ;bk: readadc infrared,b4 ;put Infrared detector reading into a4 ;debug b4 ;pause 100 ;inp3: let b3=pins ;read all digital inputs into a3 ;let pins=pins ;output these to all outputs NO ;debug b0 ; low adcon ; ;high green ; flash green LED ;pause 500 ;low green ;high amber ; flash amber LED external output pin 4 ;pause 500 ;low amber ;high red ; flash red LED external output pin 5 ;pause 500 ;low red ;setfreq m8 ;sound sounder,(122,2,123,2,124,2,125,2,126,2,127,2) ; test sounder ;for b1=0 to 4 ;main: for b0=122 to 127 ;sound sounder,(b0,2) ;pause 10 ;next b0 ;pause 20 ;next b1 ;pause 1000 ;setfreq m4 ;goto start