EOS

Instruments

Rate Sensor

Programming Exercise in PicAxe

The output of the Philip Harris Rate Sensor is directly proportional to the number of radioactive events per second detected by the Geiger-Müller tube.  The Blue Box output voltage ranges from 0 to +1V.  Count rates are measured in events, or counts, per second (1/s) on three scales, switch-selected: 10 counts per second, 250 counts per second and 1000 counts per second. 

Power Supply on PicAxe Circuit Board

Power Input:                +7.0 V to +35.0V; connector is center positive; nominally +9.0V dc power adaptor is used (+9.0 V battery for portable use, but avoid if possible since current drain is high - battery won’t last long).

Power Output:            +5.0 V, regulated

                                       200mA maximum current

                                       Red LED “on” indicator.

This power supply is hardwired to both the PicAxe and the OLED display; red lead positive/black lead ground, 0V.

Blue Box Manual

Solution

Note on count rate

The unit of radioactive decay in the System International Units (commonly known as the MKS system) is becquerel, which is one decay per second.  This refers to the disintegration of a sample of radioactive material at the source.  Another common unit of decay rate is the curie, which is 3.7 x 10^10 becquerel.

 

However, the count rate as determined with a Geiger-Müller tube is not quite the same as the decay rate.  The G-M tube only detects that fraction of the decay products which are incident on the tube.  Since the products of the decay may be emitted in all directions the Geiger-Müller tube count rate is not an accurate measure of the decay rate.   Furthermore, the G-M tube may not detect all by-products of radioactive disintegration; for example, some G-M tubes may detect beta and gamma radiation, but not alpha radiation. 

 

A Geiger-Müller tube connected to a rate counter is known as a Geiger counter.  The rate sensor measures in units of counts per second (1/s).

The Assignment

The task here is to write a PicAxe program to read the analog input C.2, convert that to count rate, continuously update and display the result on the OLED.  The OLED display must include the term “Count Rate” centered on the first line.  The second line must display – centered – “Rate = “, followed by the current rate with its proper unit, 1/s.

Preliminary Tasks

The logic of the toggle switch must be determined.

NOTE:      The Blue Box is separate and independent of the PicAxe microprocessor; thus the switch selection on the Blue Box is not automatically reflected in the microprocessor. The purpose of the toggle switch in front of the OLED is to correlate the scale within the microprocessor program to the Blue Box scale.

To display the count rate properly on the OLED the toggle switch position must be programmed into the PicAxe and the switch position must match the switch on the Blue Box.

 

The Solution

The simplest solution is to write a Flowchart in Logicator first, then convert the Flowchart into Basic language.  Inevitably, the Flowchart will not be complete so a modification of the program will be necessary.   Use Programming Editor 6 to complete the program.  The Flowchart might look something like this:

Some PicAcxe Basic Commands

First, define some variables such as these:

             symbol  variablename = pinC.2                        ‘for example

             symbol  Counts = w0                                          ‘w0 and w1 are word variables, i.e., 16 bit

             symbol   Rate = w1

             symbol  ToggleInput3 = pinC.3                        ‘defines both variable name and which pin it represents

             symbol  ToggleInput4 = pinC.4                        ‘no space between the “n” and the “C” in the command

 

Commands related to reading the analog or digital logic input:

             fvrsetup FVR2048

             adcconfig %011

             readadc10 C.2

             if variablename = 1  then (etc.)            ‘this statement reads the input to check the “if” logic;                                                                                                       ‘variablename must be defined with “symbol” statement;

                                                                              ‘”if” query is true when pin is high

Commands related to displaying the output:

             bintoascii

             serout C.1, N2400_4,(254, 128,”                “) 

             serout C.1, N2400_4,(254, 192, “   “,b9,b10,b11,”          “)

                          Note that whatever is within the parenthesis is displayed on the OLED.

                          Make sure that there are exactly 16 characters and/or spaces within the parenthesis.

                          128 is the leftmost position on line 1 of the OLED

                          192 is the leftmost position of line 2 of the OLED

                          bintoascii converts a bit number to a display character.

Commands related to logic and math:

             if   variablename = 0     then

             endif

             goto (line name)

Two logical conditions are necessary in order to determine the switch position.

             if pinC.3 = ? (high or low)    and    if pinC.4 = ? (high or low) 

             then  . . . .

             endif

Toggle Switch             (in front of the OLED)

Three position toggle switch – single pole, triple throw.

Switch is hardwired to – and switch logic is read at – Picaxe microprocessor pins C.3 and C.4

Black lead connected to ground, 0V / Orange lead hardwired to PicAxe microprocessor pin C.3 and blue lead hardwired to PicAxe microprocessor pin C.4

To find the logic of the switch, use a voltmeter on the microprocessor actual leg of pins C.3 and  C.4 (check the PicAxe pin-out diagram, and be careful not to short other actual legs).  Zero volts means logic state “low”, or 0; +5.0 V means logic state “high”, or 1.  Use two logical conditions to determine the position of the switch.

Switch circuit diagram:

Switch circuit analysis:

If the switch is in the position as shown in the left diagram, pin C.3 is shorted to ground and is thus low.  Pin C.4 is connected to the +5.0 V power supply (no current through the 10KΩ resistor) and is thus high.

In the right diagram, the conditions are reversed: pin C.3 is high and pin C.4 is low.

In the center diagram, both pins are low.

             (no debounce protection)

Philip Harris Rate Sensor                  Blue Box

Use only the red and black banana jack connectors on the Blue Box.  Never use the blue banana jack.

 

Power requirements:                 +6.0 V; separate external battery pack

                                                    Battery pack red lead positive/Black lead ground, 0V

Output (red/black banana jacks):

             Output ranges from 0 Volts to +1 Volt, and is linear in count rate.

             Red jack, voltage out; Black jack, ground, 0V.

Switch in “BATT” position:

             The Blue Box output will be +1.0 V if the battery voltage is +6.0 V.   Replace batteries if this output is below +0.75 V (corresponding to a battery voltage of +4.5 V).

Three scales, switch selected, correspond to a count rate of 50 1/s, 250 1/s and 1000 1/s.

 

NOTE:      The Blue Box scale switch selection must match the toggle switch selection for the output to display the count rate correctly on the OLED.

NOTE:      Do not use blue banana jack – negative voltage on the PicaAxe input may damage the microprocessor.

Text Box: 001	'BASIC
002	'Rate Counter
003	'
004				
005	{ ;Symbols
006	
007	symbol C3 = pinC.3
008	symbol C4 = pinC.4
009	symbol BlueBoxVoltage = w2
010	symbol CountRate = w3
011	symbol digit1 = w4
012	symbol digit2 = w5
013	symbol digit3 = w6
014	symbol digit4 = w7
015	symbol digit5 = w8
016	}
017	
018	main:
019		let dirsB = 0
020		
021	Cell_7_4:
022			
023		fvrsetup FVR2048  		 ; set FVR as 2.048V
024		adcconfig %011    		 ; set FVR as ADC Vref+, 0V Vref-
025		readadc10 C.2, BlueBoxVoltage       
026		
027	'test the switch position		
028			
029		if C3 = 0 and C4 = 1 then  	'scale = 50 counts per second
030			goto Cell_10_15
031		end if
032	
033		if C3 = 0 and C4 = 0 then   	'scale = 250 counts per second
034			goto Cell_10_14
035		end if
036	
037		if C3 = 1 and C4 = 0 then   	'scale = 1000 counts per second
038			goto Cell_10_13
039		end if
040	
041		if C3 = 1 and C4 = 1 then   	'no such position possible (if so, there is an error)
042			goto Cell_7_4
043		end if
044	
045		
046		
047		
048		
049	Cell_10_15: 					
050	'scale = 50 counts per second
051		let CountRate = BlueBoxVoltage * 100
052		if CountRate > 50000 then
053			goto Cell_10_10
054		endif
055		serout C.1, N2400, (254, 128, "   Rate Count   ")
056		bintoascii CountRate, digit1, digit2, digit3, digit4, digit5
057			if digit1 = $30 then 
058				if digit2 = $30 then
059					serout C.1, N2400, (254, 192, "     .",digit3,digit4," per sec")
060					goto Cell_7_4
061				endif
062				serout C.1, N2400, (254, 192, "    ",digit2,".",digit3,digit4," per sec")
063				goto Cell_7_4
064			endif
065			serout C.1, N2400, (254, 192, "   ",digit1,digit2,".",digit3,digit4," per sec")
066	
067		goto Cell_7_4
068	
069	Cell_10_14:
070	'scale = 250 counts per second
071		let CountRate = BlueBoxVoltage * 100 /2
072			if CountRate > 25000 then
073			goto Cell_10_10
074		endif
075		serout C.1, N2400, (254, 128, "   Rate Count   ")
076		bintoascii CountRate, digit1, digit2, digit3, digit4, digit5
077			if digit1 = $30 and digit2 = $30 then 
078				if digit3 = $30 then
079					serout C.1, N2400, (254, 192, "      .",digit4," per sec")
080					goto Cell_7_4
081				endif
082				serout C.1, N2400, (254, 192, "     ",digit3,".",digit4," per sec")
083			endif
084			if digit1 = $30 then
085				if digit2 = $30 then
086					serout C.1, N2400, (254, 192, "     ",digit3,".",digit4," per sec")
087					goto Cell_7_4
088				endif
089				serout C.1, N2400, (254, 192, "    ",digit2,digit3,".",digit4," per sec")
090				goto Cell_7_4
091			endif
092			serout C.1, N2400, (254, 192, "   ", digit1,digit2,digit3,".",digit4," per sec")
093			
094			
095			goto Cell_7_4
096	
097	
098	
099	
100	
101	
102	Cell_10_13:
103	'scale = 1000 counts per second
104		let CountRate = BlueBoxVoltage * 20
105			if CountRate > 10000 then
106			goto Cell_10_10
107		endif
108		serout C.1, N2400, (254, 128, "   Rate Count   ")
109		bintoascii CountRate, digit1, digit2, digit3, digit4, digit5
110			if digit1 = $30 and digit2 = $30 then 
111				if digit3 = $30 then
112					serout C.1, N2400, (254, 192, "      ",digit4,". per sec")
113					goto Cell_7_4
114				endif
115				serout C.1, N2400, (254, 192, "     ",digit3,digit4,". per sec")
116				goto Cell_7_4
117			endif
118			if digit1 = $30 then
119				if digit2 = $30 then
120					serout C.1, N2400, (254, 192, "     ",digit3,digit4,". per sec")
121					goto Cell_7_4
122				endif
123				serout C.1, N2400, (254, 192, "    ",digit2,digit3,digit4,". per sec")
124				goto Cell_7_4
125			endif
126		serout C.1, N2400, (254, 192, "   ",digit1,digit2,digit3,digit4,". per sec")
127	
128	
129		goto Cell_7_4
130	
131	
132	
133	
134	
135	
136	
137	Cell_10_10:
138	      			'off scale
139		serout C.1, N2400, (254, 128, "   Rate Count   ")
140		serout C.1, N2400, (254, 192, "   off scale    ")
141	
142		goto Cell_7_4
143	
144	
145	
146	
147	
148	#no_data    'reduce download time

 

Switch Left

Switch Center

Switch Right

Logic state of pin C.3

(high or low)

 

 

 

Logic state of pin C.4

(high or low)