Anda di halaman 1dari 37

RF Remote Controller

On these pages, I will introduce Remote Controller with Radio Frequency.


The electric wave sending-out is controlled with the code by PIC for transmission
and the code is deciphered by PIC for receiving.

You can jump to the page of photographs when you click the part where the pointer become the hand.

Transmitter
Hardware Software
Circuit Time chart
drawing Flow chart
Pattern List
drawing Processing
Circuit explanation
explanation Operation
Parts confirmation
explanation

Receiver-1
Hardware Software
Circuit Time chart
drawing Flow chart
Pattern List
drawing Processing
Circuit explanation
explanation Operation
Parts confirmation
explanation

Receiver-2
I looked for the IC for the FM receiver to use for a high frequency receiving part.
However, I could not get appropriate IC. Therefore, the making of receiver-2 is
stopped temporarily.
Circuit drawing for Transmitter

Pattern drawing for Transmitter


(Wiring side)

Olive-green line shows the wiring at the component side.


Pink line shows the external parts.

Circuit explanation of Transmitter

High frequency oscillation circuit


The Colpitts circuit is used for the high frequency oscillation circuit.

The figure on the left is the basic circuit of the Colpitts oscillation circuit.
Roughly oscillation frequency is found by the following formula. The oscillation frequency
changes by the length of the wiring, the capacitance of the transistor and other condition.
So, the way of making actually and ascertaining is realistic.
This formula is a simplified formula and in the correct formula, the condition of the
transistor is added.

To understand the operation of this circuit correctly, it is necessary to do the professional knowledge of the Electrical
Engineering. So, I don't do a detailed explanation. The operation of the outline is hereinafter.
Oscillation operation is done by dividing the voltage which occurs between the collector and the base by C1 and C2
and making it return to the emitter.

An oscillation circuit this time is shown on the left. 10000pF(103=10x103) is used


for C2 and C3 of this circuit.
The oscillation frequency of the circuit this time is about 83MHz. A 10000pF
capacitive reactance (the resistance value with the alternating current) at 83MHz is
shown below.

That is, there is little resistance when seeing C2 and C3 at the high frequency. It is
in the condition which is the same when connected with the wire.

It becomes a figure on the left when seeing this circuit at the high frequency.
As for this circuit, C4 is connected with the L in parallel but you find that it is Colpitts oscillation circuit.

The calculation of the value of coil (L) was difficult and this time, I decided it by the cut & try. I decided an
oscillation frequency on 83 MHz which don't overlap with the frequency of FM broadcasting station. There is no
problem at the other frequency if not overlapping with the strong electric wave.
The coil to be using this time is using the one to have wound a tin plating wire with 0.6mm diameter around the stick
(the screwdriver) with 4.6mm diameter seven times. I make a tap (the node of the power) at the position of 4.5 turns
from the side which connects with the collector. The position of this tap is my sense. As for this position, the supply
of the high frequency electric power to the amplifier of the following stage is considered. The adjustment of the
oscillation frequency is done by C4. The frequency fine control can do by expanding or crinkling a coil. It dosen't
need to touche this coil basically after adjustment. The frequency changes when a coil is transformed by the
vibration and so on. I used the a little thick diameter of 0.6mm for the wiring material of the coil to prevent the
change of the frequency by these phenomena.
In case of the high frequency circuit, the wiring becomes the part of the coil. So, when picturing the pattern of the
circuit, the wiring that the high frequency passes makes it as short as possible.
High frequency power amplification circuit
This is the circuit which amplifies the signal to have made with oscillator. An antenna is put to emit an electric wave.
When putting an antenna to the oscillator directly, the position of the antenna and so on change an oscillation
frequency. This amplification circuit is doing the function which prevents the operation of the oscillation circuit
from the situation of the antenna, too.

As the circuit which receives the signal of the oscillator, generally, the high
frequency transformer which has the 1st coil and the 2nd coil is used.
In the circuits which I made, it is making do the function of the transformer with one
coil. The signal can be transmitted to the power amplifier only with one coil because
the base of the oscillation circuit transistor is grounding potential on the high
frequency.

This power amplification circuit is a very simple circuit. It applies a few electric currents to the base and it makes the
amplifier which is near a class "B" amplification. When handling high frequency, to make a class "A" amplification
isn't necessary. It had better put a tuning circuit to the collector, too. However, the circuit this time omits for a circuit
to be simplified.
When emitting an electric wave, the output is prescribed in the electric wave law. I think that there is no problem of
the electric wave law because the electric wave which it is possible to emit with this circuit is very feeble. Please
examine electric wave law in your country.

Control code generation circuit


The control code does the electric wave of the transmitter to the control of ON/OFF. At design first, I examin the
adoption of the frequency modulation (FM) method by the control code. However, I adopted an electric wave
ON/OFF method because the circuit was simple.
A control code is controlled by the software of PIC. With this,
the control code can be easily changed. There are two purposes
in this control code.
The 1st is to secure security. The FM electric wave which was
modulated at the single frequency can be made with the other
equipment, being easy. At the circuit this time, a control code
with byte(8bits) is used. To recognize a control code, to detect a
specific signal in front of it is needed. Also, it makes not
recognize a normally control code when not detecting a
normally signal more than one time.
The 2nd is to change the kind of the control. The kind to
control are designated by the contents of the byte. At the circuit
this time, only two kinds of codes are used. More kinds can be
controlled if changing the input circuit of the control.
The operation (the oscillation/the stop) of the oscillation circuit is controlled using the RA4 port of PIC. It is because
the RA4 port is an open type. As for the other port, at the time of ON (the H level), +5V are output and at the time of
OFF (the L level), 0V are output. As for RA4, at the time of ON (the H level), output is only separated from the
grounding and voltage isn't output. So, it becomes the condition which is the same as PIC's not being connected
when seeing from the oscillator and the oscillation circuit does oscillation operation. When RA4 is OFF (the L
level), 0V are output. Because the base of the oscillation circuit is grounded when RA4 becomes 0V, the oscillation
stops.

Power switch and control code selection circuit

The operation of the circuit of the transmitter only when


pushing a control switch. When a control switch isn't pushed, it
makes all circuits stop. When a control switch isn't pushed, it
makes all circuits stop to suppress the consumption of the
battery cell. The control switch combines the selector switch of
the control code and the power switch. A control switch is
connected with the side of the positive of the cell and a power
is supplied to the circuit even if it pushes any switch. Control
code selection malfunction is prevented by the diodes.

Power supply circuit


I used a +9V dry battery for the power of the transmitter. This dry battery is called 006P in Japan. Maybe this dry
battery is called as 1604(NEDA) or 6F22(IEC). Anyway, this is 9V dry battery for transistor radios. The voltage for
PIC is converted to +5V with the 3 terminal regulator. The voltage of the dry battery falls in consumption of the
electric power. When the power supply voltage changes, the oscillation frequency of the Colpitts oscillation circuit
to be using this time changes. Even if the transmission frequency changes little, the receiver can detect an electric
wave. So, it isn't using a stabilization voltage circuit for the oscillation circuit. However, when the voltage of the dry
battery falls extremely, the oscillation frequency of the transmitter becomes the detection impossible condition with
receiver.
PIC needs to make the voltage of the power and all input-output ports equal to or less than +5V. The parts
(RA0,RA1 and RA4) which connects with the +9V circuit makes less than +5V.

Parts explanation of Transmitter

PIC16F84A
The electric wave which was made with oscillato is
controlled by this PIC.
A control code is made with the software of PIC16F84A.
The control code can be easily changed if changing
software.
It uses RA0 and RA1 for the input to choose a control
code and it is using RA4 for the control of the oscillation
circuit.

Data sheet for PIC16F84A


Transistor for high frequency oscillation and high frequency power amplification (
2SC1906 )

2SC1906 is used for the high-frequency oscillator and the power amplification.
The transistor with high fT (the maximum cutoff frequency) is needed because it handles a high
frequency. The fT of 2SC1906 is 600MHz-1000MHz. Because it handles an about 80-MHz
frequency at the circuit this time, there is a lot of leeway.

Data sheet for 2SC1906

3 terminal regulator ( 78L05 )

The power of this transmitter is a +9V battery.


3 terminal regulator is used to make the power (+5V) of PIC from +9V power.
A 100mA type is used.

Data sheet for 78L05

Resonator
This is the oscillation device to make the clock of PIC. A ceramic vibrator and
capacitors are incorporated.
The clock frequency this time is 4 MHz. It is possible to make do the operation of
PIC16F84A with the a maximum of 20MHz clock.
Diode
This is the diode to control the input of PIC by the switch operation. This time, I used
diodes for the rectification. However, because few flowing electric currents occur, the
switching diode (Io=120mA) such as 1S588 and so on can be used.

Coil
The coil to be using this time is using the one to have wound a tin plating wire with
0.6mm diameter around the stick (the screwdriver) with 4.6mm diameter seven times.
I make a tap (the node of the power) at the position of 4.5 turns from the side which
connects with the collector.
You can use a coil bobbin with the core, too.

IC socket
This is an 18 pins socket for PIC16F84A.
I used a round hole type but you can use a board type, too.

Resistor

As for the resistor, all 1/8W are used.


Time Chart for Transmitter

I will show the time chart of the control code in the figure above. This
composition is the composition which I contrived and is not standard
composition. The switching time of each bit is 10 milliseconds.
The signal to transmit from the transmitter is composed of three blocks. In the
program, three blocks are managed by transmission status (TX_STATUS). ST0,
ST1, ST2 show transmission status with the figure above. A bit in each block is
managed by sub status (TX_SUBSTATUS). The figure which is written under
the signal in the figure above shows sub status.

A preamble signal is transmitted in the first block. This signal repeats ON/OFF
and is used to confirm that it is a signal from the normally transmitter at the
receiver. Also, it uses to decide the detection position of the bit at the receiver. At
the end of the preamble signal, it is shown in the ON condition which was
continued twice and the OFF condition after that.
The following block is the block which sends a control code. Each bit of the
control code is put in by the ON signal and the OFF signal. With this, even if all
bits of the control code are "1"(ON), the OFF condition always exists. Also, the
ON condition always exists even if all the bits of the control code are "0"(OFF).
Wrong detection at the receiver is prevented by this. Moreover, because it uses 3
bits to send 1 bit, the detection of the signal which repeats ON/OFF can be
prevented.
In the last, it is a code ending block. It is in the ON condition which was
continued three times. The ON condition which was continued three times exists
only in this block. In case of continuously the electric wave, the ON condition
which was continued three times exists. However, the following in this block is
the block of the preamble again. So, the detection which was wrong with the
continuously electric wave isn't done.
Above-mentioned three blocks are repeatedly transmitted.

The receiver doesn't always receive the electric wave which was transmitted from
the transmitter from the beginning. The receiver checks a preamble signal when it
receives an electric wave. The receiver judges a preamble signal when receiving
the signal which changes as ON-OFF-ON. Such a change doesn't exist in the
control code block and the code ending block. When beginning to receive from
the control code block, it skips the control code and the ending code and it
catches a preamble signal.
Software Flow chart of Transmitter (1/6)

Source code file of Transmitter


001 ;********************************************************
002 ;
003 ; Remote Controller Transmitter
004 ;
005 ; Author : Seiichi Inoue
006 ;********************************************************
007
008 list p=pic16f84a
009 include p16f84a.inc
010 __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
011 errorlevel -302 ;Suppress bank warning
012
013
014 ;**************** Label Definition ********************
015 cblock h'0c'
016 tx_status ;TX status save area
017 tx_substatus ;TX substatus save area
018 pattern ;Pattern save area
019 endc
020
021 ptn1 equ b'11110000' ;Pattern 1 data
022 ptn2 equ b'00001111' ;Pattern 2 data
023 ra4 equ d'4' ;RA4 bit position
024
025 ;**************** Program Start ***********************
026 org 0 ;Reset Vector
027 goto init
028 org 4 ;Interrupt Vector
029 goto int
030
031 ;**************** Initial Process *********************
032 init bsf status,rp0 ;Change to Bank1
033 movlw b'00000011' ;RA4-2:OUT RA1,0:IN mode
034 movwf trisa ;Set TRISA reg
035 movlw b'00000101' ;RBPU/TOCS/PSA=0,PS=101
036 movwf option_reg ;Set OPTION_REG
037 bcf status,rp0 ;Change to Bank0
038
039 clrf porta ;Stop wave emission
040 clrf tx_status ;Clear TX status
041 clrf tx_substatus ;Clear TX substatus
042
043 movlw b'00000001' ;Set mask pattern
044 andwf porta,w ;Pick up RA0
045 btfsc status,z ;RA0 = 1 (SW1 ON) ?
046 goto in1 ;No. Check next input
047 movlw ptn1 ;Set pattern1 data
048 in0 movwf pattern ;Save pattern data
049 goto tm ;Jump to timer set
050 in1 movlw b'00000010' ;Set mask pattern
051 andwf porta,w ;Pick up RA1
052 btfsc status,z ;RA1 = 1 (SW2 ON) ?
053 goto init ;No. Illegal input
054 movlw ptn2 ;Set pattern2 data
055 goto in0 ;Jump to pattern save
056
057 tm movlw d'100' ;256-10000us/64us = 100
058 movwf tmr0 ;Set 10msec to TMR0
059 movlw h'a0' ;GIE=1,TOIE=1
060 movwf intcon ;Interruption enable
061
062 goto $ ;Wait interruption
063
064 ;********* Begin Timer Interruption Process ***********
065 int
066 bcf intcon,t0if ;Clear timer int flag
067
068 stchk0
069 movf tx_status,w ;Read TX status
070 btfss status,z ;TX status = 0 ?
071 goto stchk1 ;No. Next
072
073 ;************ Preamble data send Process **************
074 movlw d'7' ;Set check data
075 subwf tx_substatus,w ;Substatus - check data
076 btfsc status,z ;Substatus = 7 ?
077 goto stinc ;Yes. Substatus + 1
078 movlw d'8' ;Set check data
079 subwf tx_substatus,w ;Substatus - check data
080 btfsc status,z ;Substatus = 8 ?
081 goto st01 ;Yes.
082 movlw d'9' ;Set check data
083 subwf tx_substatus,w ;Substatus - check data
084 btfsc status,z ;Substatus = 9 ?
085 goto st02 ;Yes.
086 movlw b'00000001' ;Set mask pattern
087 andwf tx_substatus,w ;Pick up LSB
088 btfss status,z ;LSB = 0 (Even) ?
089 goto st00 ;No. (Odd)
090 bsf porta,ra4 ;Start wave emission
091 goto stinc ;Jump to Substatus + 1
092 st00 bcf porta,ra4 ;Stop wave emission
093 goto stinc ;Jump to Substatus + 1
094 st01 bcf porta,ra4 ;Stop wave emission
095 goto stinc ;Jump to Substatus + 1
096 st02 bsf porta,ra4 ;Start wave emission
097 clrf tx_substatus ;Clear TX substatus
098 incf tx_status,f ;Set TX status = 1
099 goto int_end ;Jump to timer int end
100
101 ;********************************************************
102 stchk1
103 movlw d'1' ;Set check data
104 subwf tx_status,w ;TX status - check data
105 btfss status,z ;TX status = 1 ?
106 goto stchk2 ;No. Next
107
108 ;************ Control data send Process ***************
109 movf tx_substatus,w ;Read TX substatus
110 btfss status,z ;Substatus = 0 ?
111 goto st11 ;No. Next
112 movlw b'00000001' ;Set mask pattern
113 andwf pattern,w ;Pick up data
114 btfss status,z ;Data = 0 ?
115 goto st10 ;No. Data = 1
116 bcf porta,ra4 ;Stop wave emission
117 goto stinc ;Jump to Substatus + 1
118 st10 bsf porta,ra4 ;Start wave emission
119 goto stinc ;Jump to Substatus + 1
120
121 st11 movlw d'1' ;Set check data
122 subwf tx_substatus,w ;Substatus - check data
123 btfss status,z ;Substatus = 1 ?
124 goto st12 ;No. Next
125 bcf porta,ra4 ;Stop wave emission
126 goto stinc ;Jump to Substatus + 1
127
128 st12 movlw d'2' ;Set check data
129 subwf tx_substatus,w ;Substatus - check data
130 btfss status,z ;Substatus = 2 ?
131 goto st13 ;No. Next
132 bsf porta,ra4 ;Start wave emission
133 goto stinc ;Jump to Substatus + 1
134
135 st13 movlw d'3' ;Set check data
136 subwf tx_substatus,w ;Substatus - check data
137 btfss status,z ;Substatus = 3 ?
138 goto st15 ;No. Next
139 movlw b'00000010' ;Set mask pattern
140 andwf pattern,w ;Pick up data
141 btfss status,z ;Data = 0 ?
142 goto st14 ;No. Data = 1
143 bcf porta,ra4 ;Stop wave emission
144 goto stinc ;Jump to Substatus + 1
145 st14 bsf porta,ra4 ;Start wave emission
146 goto stinc ;Jump to Substatus + 1
147
148 st15 movlw d'4' ;Set check data
149 subwf tx_substatus,w ;Substatus - check data
150 btfss status,z ;Substatus = 4 ?
151 goto st16 ;No. Next
152 bcf porta,ra4 ;Stop wave emission
153 goto stinc ;Jump to Substatus + 1
154
155 st16 movlw d'5' ;Set check data
156 subwf tx_substatus,w ;Substatus - check data
157 btfss status,z ;Substatus = 5 ?
158 goto st17 ;No. Next
159 bsf porta,ra4 ;Start wave emission
160 goto stinc ;Jump to Substatus + 1
161
162 st17 movlw d'6' ;Set check data
163 subwf tx_substatus,w ;Substatus - check data
164 btfss status,z ;Substatus = 6 ?
165 goto st19 ;No. Next
166 movlw b'00000100' ;Set mask pattern
167 andwf pattern,w ;Pick up data
168 btfss status,z ;Data = 0 ?
169 goto st18 ;No. Data = 1
170 bcf porta,ra4 ;Stop wave emission
171 goto stinc ;Jump to Substatus + 1
172 st18 bsf porta,ra4 ;Start wave emission
173 goto stinc ;Jump to Substatus + 1
174
175 st19 movlw d'7' ;Set check data
176 subwf tx_substatus,w ;Substatus - check data
177 btfss status,z ;Substatus = 7 ?
178 goto st20 ;No. Next
179 bcf porta,ra4 ;Stop wave emission
180 goto stinc ;Jump to Substatus + 1
181
182 st20 movlw d'8' ;Set check data
183 subwf tx_substatus,w ;Substatus - check data
184 btfss status,z ;Substatus = 8 ?
185 goto st21 ;No. Next
186 bsf porta,ra4 ;Start wave emission
187 goto stinc ;Jump to Substatus + 1
188
189 st21 movlw d'9' ;Set check data
190 subwf tx_substatus,w ;Substatus - check data
191 btfss status,z ;Substatus = 9 ?
192 goto st23 ;No. Next
193 movlw b'00001000' ;Set mask pattern
194 andwf pattern,w ;Pick up data
195 btfss status,z ;Data = 0 ?
196 goto st22 ;No. Data = 1
197 bcf porta,ra4 ;Stop wave emission
198 goto stinc ;Jump to Substatus + 1
199 st22 bsf porta,ra4 ;Start wave emission
200 goto stinc ;Jump to Substatus + 1
201
202 st23 movlw d'10' ;Set check data
203 subwf tx_substatus,w ;Substatus - check data
204 btfss status,z ;Substatus = 10 ?
205 goto st24 ;No. Next
206 bcf porta,ra4 ;Stop wave emission
207 goto stinc ;Jump to Substatus + 1
208
209 st24 movlw d'11' ;Set check data
210 subwf tx_substatus,w ;Substatus - check data
211 btfss status,z ;Substatus = 11 ?
212 goto st25 ;No. Next
213 bsf porta,ra4 ;Start wave emission
214 goto stinc ;Jump to Substatus + 1
215
216 st25 movlw d'12' ;Set check data
217 subwf tx_substatus,w ;Substatus - check data
218 btfss status,z ;Substatus = 12 ?
219 goto st27 ;No. Next
220 movlw b'00010000' ;Set mask pattern
221 andwf pattern,w ;Pick up data
222 btfss status,z ;Data = 0 ?
223 goto st26 ;No. Data = 1
224 bcf porta,ra4 ;Stop wave emission
225 goto stinc ;Jump to Substatus + 1
226 st26 bsf porta,ra4 ;Start wave emission
227 goto stinc ;Jump to Substatus + 1
228
229 st27 movlw d'13' ;Set check data
230 subwf tx_substatus,w ;Substatus - check data
231 btfss status,z ;Substatus = 13 ?
232 goto st28 ;No. Next
233 bcf porta,ra4 ;Stop wave emission
234 goto stinc ;Jump to Substatus + 1
235
236 st28 movlw d'14' ;Set check data
237 subwf tx_substatus,w ;Substatus - check data
238 btfss status,z ;Substatus = 14 ?
239 goto st29 ;No. Next
240 bsf porta,ra4 ;Start wave emission
241 goto stinc ;Jump to Substatus + 1
242
243 st29 movlw d'15' ;Set check data
244 subwf tx_substatus,w ;Substatus - check data
245 btfss status,z ;Substatus = 15 ?
246 goto st31 ;No. Next
247 movlw b'00100000' ;Set mask pattern
248 andwf pattern,w ;Pick up data
249 btfss status,z ;Data = 0 ?
250 goto st30 ;No. Data = 1
251 bcf porta,ra4 ;Stop wave emission
252 goto stinc ;Jump to Substatus + 1
253 st30 bsf porta,ra4 ;Start wave emission
254 goto stinc ;Jump to Substatus + 1
255
256 st31 movlw d'16' ;Set check data
257 subwf tx_substatus,w ;Substatus - check data
258 btfss status,z ;Substatus = 16 ?
259 goto st32 ;No. Next
260 bcf porta,ra4 ;Stop wave emission
261 goto stinc ;Jump to Substatus + 1
262
263 st32 movlw d'17' ;Set check data
264 subwf tx_substatus,w ;Substatus - check data
265 btfss status,z ;Substatus = 17 ?
266 goto st33 ;No. Next
267 bsf porta,ra4 ;Start wave emission
268 goto stinc ;Jump to Substatus + 1
269
270 st33 movlw d'18' ;Set check data
271 subwf tx_substatus,w ;Substatus - check data
272 btfss status,z ;Substatus = 18 ?
273 goto st35 ;No. Next
274 movlw b'01000000' ;Set mask pattern
275 andwf pattern,w ;Pick up data
276 btfss status,z ;Data = 0 ?
277 goto st34 ;No. Data = 1
278 bcf porta,ra4 ;Stop wave emission
279 goto stinc ;Jump to Substatus + 1
280 st34 bsf porta,ra4 ;Start wave emission
281 goto stinc ;Jump to Substatus + 1
282
283 st35 movlw d'19' ;Set check data
284 subwf tx_substatus,w ;Substatus - check data
285 btfss status,z ;Substatus = 19 ?
286 goto st36 ;No. Next
287 bcf porta,ra4 ;Stop wave emission
288 goto stinc ;Jump to Substatus + 1
289
290 st36 movlw d'20' ;Set check data
291 subwf tx_substatus,w ;Substatus - check data
292 btfss status,z ;Substatus = 20 ?
293 goto st37 ;No. Next
294 bsf porta,ra4 ;Start wave emission
295 goto stinc ;Jump to Substatus + 1
296
297 st37 movlw d'21' ;Set check data
298 subwf tx_substatus,w ;Substatus - check data
299 btfss status,z ;Substatus = 21 ?
300 goto st39 ;No. Next
301 movlw b'10000000' ;Set mask pattern
302 andwf pattern,w ;Pick up data
303 btfss status,z ;Data = 0 ?
304 goto st38 ;No. Data = 1
305 bcf porta,ra4 ;Stop wave emission
306 goto stinc ;Jump to Substatus + 1
307 st38 bsf porta,ra4 ;Start wave emission
308 goto stinc ;Jump to Substatus + 1
309
310 st39 movlw d'22' ;Set check data
311 subwf tx_substatus,w ;Substatus - check data
312 btfss status,z ;Substatus = 22 ?
313 goto st40 ;No. Next
314 bcf porta,ra4 ;Stop wave emission
315 goto stinc ;Jump to Substatus + 1
316
317 st40 bsf porta,ra4 ;Start wave emission
318 clrf tx_substatus ;Clear TX substatus
319 incf tx_status,f ;Set TX status = 2
320 goto int_end ;Jump to timer int end
321
322 ;************** End data send Process *****************
323 stchk2 movlw d'2' ;Set check data
324 subwf tx_substatus,w ;Substatus - check data
325 btfss status,z ;Substatus = 2 ?
326 goto stinc ;No.Jump to Substatus + 1
327 bcf porta,ra4 ;Stop wave emission
328 clrf tx_substatus ;Clear TX substatus
329 clrf tx_status ;Clear TX status
330 goto int_end ;Jump to timer int end
331
332 ;*********** Substatus Increment Process **************
333 stinc incf tx_substatus,f ;Substatus + 1
334
335 ;******** End of Timer Interruption Process ***********
336 int_end movlw d'100' ;256-10000us/64us = 100
337 movwf tmr0 ;Set 10msec to TMR0
338 retfie ;End of interruption
339
340 ;********************************************************
341 ; END of Remote Controller Transmitter
342 ;********************************************************
343
344 end
Processing explanation of Transmitter

Environment setting
Various environment setting is done at the line number 008-011 of the list.

008 list It is defining the name of PIC to use.


009 include The file (p16f84a.inc) that a various standard label is defined is taken in.
010 __config The contents of Configuration Word are designated.
_hs_osc Type of the oscillator : HS
_wdt_off Watch-dog timer : It isn't used.
_pwrte_on Power up timer : It is used.
_cp_off Code protector : It isn't used.
The value of Configuration Word by above-mentioned specification is H'3FF2'.

011 errorlevel It makes not show bank switching warning message [302].
At the RAM file register of PIC16F84A, a bank method is adopted. For example,
both memory addresses of TMR0 and OPTION_REG is 01. However, TMR0 is at
bank 0 and OPTION_REG is at bank 1. In the definition file which is read by
INCLUDE, it defines the address of OPTION_REG as being H'0081'. Bank
information is written. The bank must be designated with RP0 bit of the STATUS
register by the actual processing. In case of MPLAB, to prevent mistake in the bank
processing, warning message "Message[302]" is shown in the processing of the
register of bank 1.
"Register in operand not in bank 0. Ensure that bank bits are correct."
Even if specifying a bank normally, this message is shown. To make not display this
message, there is a way of changing a definition file designation. That is, the message
becomes not displayed when changing the address of OPTION_REG into H'0001'.
Or, there is a way of stopping the display of 302 messages using the ERRORLEVEL
directive to be using this time.

Label definition
;**************** Label Definition ********************
CBLOCK and ENDC are used for the block definition of the RAM register file. The area of the label
among these commands is automatically set in the order from the address which is specified by CBLOCK.
This time, it is the same as specifying as follows.
tx_status equ h'000c'
tx_substatus equ h'000d'
pattern equ h'000e'
ptn1 and ptn2 are the label which specifies control code data. If changing the value to specify here, the
control code to transmit can be changed. In the case, the side of the receiver must be changed too.
ra4 is the label which specifies the position of port A. "4" can be designated to direct by the instruction even
if it doesn't use ra4, too.

Program start
;**************** Program Start ***********************
The program memory address 0 is the program starting address when turning on or reset occurs. Also, the
program memory address 4 is a start address when interruption occurs. These addresses are decided with the
hardware of PIC16F series.
Initialization process
;**************** Initial Process *********************
Port initialization
First, the initialization of the port is done. RA0 and RA1 are set to the input mode and the other
RA ports which contain RA4 are set to the output mode.

Timer setting
This circuit controls the data to transmit in the 10-millisecond interval. Timer 0 is used to make
10-millisecond time. TOCS and PSA of OPTION_REG are set to "0" to use an internal clock and
prescaler for timer 0. It makes prescaler value "101"(1:64). Because it is using 4 MHz for the
oscillator of PIC, the clock is one microsecond. TMR0 is increased every 64 microseconds when
combining with prescaler. The timer interrupt generates TMR0 when count value (TMR0)
becomes 0 from 255(H'FF'). So, the value to set to TMR0 for the 10-millisecond timer is 256-
(10000/64)=100. The other value can be used for the prescaler value. In case of 1:128, the timer
increases every 128 microseconds. In the case, the set value of TMR0 is 256-(10000/128)=178. In
case of 1:256, it is 256-(10000/256)=217. When the prescaler value is small, the timer value by
TMR0 can be set, being detailed. However, in case of 1:32, it becomes 10000/32=312.5. The value
more than 255 can not be set to TMR0.

Initialization of the register


When turning on the power of PIC, the initialization for various register is executed with hardware.
I am doing initialization to make those original values certainty.

Confirmation of the transmission pattern


It checks the condition of RA0 and RA1 and it confirms a transmission pattern. RA0 becomes an
H level when SW1 is pushed and RA1 becomes an H level when SW2 is pushed. By the condition
of the pushed switch, a control code pattern is set to the PATTERN register. When SW1 and SW2
are pushed at the same time, SW1 is judged to have been pushed.

Timer interrupt wait


After above processing, it waits for the interruption of the timer only. It specifies $ (its address) by
the GOTO instruction, and it repeats the processing of the same address and it waits for the
interruption.

Timer interrupt process


;********* Begin Timer Interruption Process ***********
In the processing this time, the interruption has only a timer time-out. So, it assumes that all interruption is a
timer interrupt. When using the other interruption (the RB port change interruption, and so on), judgment
processing of the interruption factor is needed.
First, it clears a timer interrupt flag. When not clearing this, the timer interrupt occurs again immediately
after executing interruption ending instruction (RETFIE).

Preamble data sending-out process


;************ Preamble data send Process **************
When transmission status (TX_STATUS) is "0", it sends out a preamble signal. It transmits ON and OFF
three times alternately and making do continuously ON in twice in case of transmission ending. After
transmitting the end mark, it makes an electric wave OFF and it ends in the sending-out of a preamble
signal and it makes transmission status "1".
Control code data sending-out process
;************ Control data send Process ***************
When the transmission status is "1", the sending-out processing of a control code is done. It sends ON
signal in front of each bit of the control code and it sends OFF signal back. The condition of the sending-out
bit is managed by sub status (TX_SUBSTATUS). I think that it is possible for more few processing steps to
realize if devising processing. However, I made the processing of each signal to be independent. The
quantity consumed of the program memory increases but can make an execution time little. It is because
there are not judgement processing and so on too much. This time, because the program is small, the
memory is enough. Also, in this way, the understanding of processing is easy and there is little possibility to
make bug (the mistake of the software). It makes transmission status "2" when the sending-out of a control
code ends.

Ending data sending-out process


;************** End data send Process *****************
When the transmission status is "2", the sending-out processing of an ending code is done. The ending code
continues ON condition three times and makes it OFF condition last.
By making transmission status "0" after finishing transmitting an ending code, the transmission of the
preamble is again done.

Timer interrupt ending process


;*********** Substatus Increment Process **************

;******** End of Timer Interruption Process ***********


A timer interrupt is done every 10 milliseconds and code transmission processing is done by the contents of
the transmission status and the transmission sub status.
When the timer interrupt processing ends, it sets 10 milliseconds to timer value (TMR0) and it sets a timer
interrupt condition for next time. Depending on the condition of the status, sub status is sometimes
increased. The interruption processing ends using the RETFIE instruction. With this instruction, the GIE bit
of the INTCON register becomes "1" and the interruption becomes possible.

Operation confirmation of Transmitter


Operation confirmation of the transmitter
It turns on the power of the transmitter without mounting PIC. Because the base of the oscillation transistor
isn't controlled by PIC when not mounting PIC, it
oscillates continuously.

It connects a frequency counter with the collector of


output transistor (TR2) and it adjusts an oscillation frequency.
A frequency is adjusted by the pitch of the oscillation
coil. I adjusted to the frequency (about 83 MHz) which
doesn't overlap with the FM broadcasting. There is no
problem at the other frequency.

Measurement of the frequency change


The frequency stability of the oscillator which was used this time isn't good. I measured a frequency change
from turning on the power.
The measurement of the frequency was done for 7 minutes and the frequency changed from 82.985 MHz to
83.180 MHz. The band is 195 kHz. This measuring time was too long. Actually, the frequency change
immediately after the turning on is important. The receiver should be controlled by the transmitter. The
operation of the transmitter may be short time. Generally, the receiver can be controlled below 10 seconds.
The frequency change in 10 seconds was to 4 kHz be. This frequency change seems to be cause for the
change of the capacitance of the transistor by the heat which is caused by the electric current of the
transistor. This frequency change is related with the receiving sensitivity with receiver. In case of being the
receiver which can not do receiving in the 4-kHz frequency change, it is a problem. Generally, even if it
shifts by 4 kHz, there is no problem. However, when the electric wave is weak, the influence sometimes
comes out.

Measurement of the frequency change by the power supply voltage


The power of the transmitter is a dry battery. So, the dry battery consumes when using long and the power
supply voltage falls. I changed a power supply voltage and measured a frequency change. The oscillation
frequency changes when making do the operation of the transmitter. Therefore, I measured a frequency
after stopping a transmitter after setting voltage and keeping time for a while.

The frequency change when changing power supply voltage from 7V to 11V was to 16kHz be. This is not a
big change. It seems that it does the operation even if the dry battery weakens.
Confirmation of the oscillation
frequency by the dip meter
I recognize the oscillation frequency of the transmitter by
the frequency counter. Moreover, I checked a frequency
with dip meter.
I will use a dip meter for the frequency adjustment for
the receiver. So, this measurement is the operation
confirmation of the dip meter.

Circuit drawing for Receiver-1

Pattern drawing for Receiver-1


(Wiring side)
Olive-green line shows the wiring at the component side.

Circuit explanation of Receiver-1


FET amplification circuit is used for a high frequency amplification circuit of the receiver.
It is because the getting of parts is easy. So, it doesn't have high sensitivity.
To make the receiver with high sensitivity, the circuit which used IC for FM receiver is good.

High frequency amplification circuit

The 2 stages FET amplifier is used for the high


frequency amplification. The FET amplifies
only at the voltage to apply to gate (G). The
resistor to be putting in the source (S) of the
FET is to make the bias voltage of the gate.
When making a resistance value big, voltage of
the source goes up to the grounding and the
bias voltage becomes big. In case of the gain of
the amplifier is big, when the signal of the
output returns to the input, an amplifier
oscillates. In the case, it makes this resistance
value big and the gain must be lowered.
The power of the FET connects with the center
tap of the coil (L2 and L3) to be putting in the side of drain (D). This is to make do operation to have been stable,
improving the characteristic of the resonance circuit. The characteristic of the resonance circuit is called queue (Q).
The ideal resonance circuit picks up only a resonant frequency. However, the actual resonance circuit becomes a
shape like the mountain which made a resonant frequency a top. When the Q of the resonance circuit is high, the
voltage at the resonant frequency becomes high and the resonant characteristic becomes good.
Detection circuit

Rectifying the output of the high-frequency amplifier directly with Germanium diode and it
makes the DC voltage from high frequency voltage. This circuit can get twice voltage
compared with usual rectification circuit. Because the charging takes time when the value of
the capacitor (C6) to use for input is big, the change of the output voltage becomes late. I
decided a value of this capacitor by the cut & try.

Voltage comparator
The DC voltage which was made with high frequency detection circuit
changes at the strength of the electric wave to receive.
At the circuit this time, it identifies a control code in the existence in the
electric wave. It makes the output of the voltage comparator H level
condition if receiving an electric wave and it makes it an L level condition if
not receiving. Slightly positive voltage is applied to the negative terminal of
IC1 to prevent from a malfunction by the noise. It uses 10 k-ohm for R4,
100 ohm for R5 and the power supply voltage is 12 V. So, the voltage of the
negative terminal is 12x100/(10000+100)=0.12 V. Probably, because there
is no noise, a negative terminal may ground. When the output voltage (the
positive terminal input) of the detection circuit becomes higher than the
voltage of the negative terminal, the output of the voltage comparator
becomes H level. Because a Zener diode (for 5 V) is connected with the output, the H level is 5 V. This voltage
doesn't exceed the permission voltage of PIC.

Clock oscillation circuit for PIC


It puts a vibrator to make do the operation of PIC. A correct oscillation frequency is
gotten when there is a crystal oscillator as the vibrator. This time, I used the resonator
which used a ceramic. Because to make do the high-speed operation of PIC isn't
necessary at the circuit this time, the oscillation frequency is 4 MHz.
Relay drive circuit
RB5 and RB7 port of PIC make do the
operation of the relays. It is converting the
output voltage of PIC with the transistor.
It makes LED light up to find the operation of
the relay. It puts a resistor in the LED in series
and it is limiting the electric current which
flows through the LED to about 10 mA.
It is putting a diode in parallel with the relay.
When the drive electric current of the relay
passes away, the back electromotive force
occurs to the coil of the relay. A transistor is
prevented from the high voltage by passing the
electric current of the back electromotive force
to this diode. Because the relay to be using this
time is small, there are few gravities that the
transistor breaks even if it doesn't put a diode. I put it for the safety.

Power circuit for PIC

3 terminal regulator is used to make the stable +5V voltage which PIC needs from
12V power.
It is enough in the 100mA type because it uses for PIC only.

Parts explanation of Receiver-1

PIC16F84A
This PIC analyzes the control code to take from the
transmitter and when receiving a normally code, it
controls a relay.

Data sheet for PIC16F84A


Low noise operational amplifier ( LM358 )
The voltage of the signal which detected a high frequency isn't enough for
PIC. The input voltage which PIC needs is made by amplifying by this
amplifier. The operation is similar to the comparator. The output becomes
an open condition when the input voltage of the positive terminal exceeds
the voltage of the negative terminal. For the mounting space, I used the
operational amplifier of the 8 pin type.

Data sheet for LM358

FET for the high frequency amplification ( 2SK439 )

This transistor is used to amplify a received electric wave.

Data sheet for 2SK439

Transistor for relay drive ( 2SC1815 )


This transister is used to drive the relay.

Data sheet for 2SC1815

3 terminal regulator ( 78L05 )


3 terminal regulator is used to make the power (+5V) of PIC from +12V power.
A 100mA type is used.

Data sheet for 78L05


Time Chart for Receiver

First, the receiver confirms that the electric wave exists. A 5-millisecond timer is
set when an electric wave is received and the input signal becomes ON. The
signal which is sent from the transmitter is a 10-millisecond interval. To detect
ON/OFF in the position of the stable state, it is shifting for 5 milliseconds from
the standing-up of the signal.
The electric wave which is sent from the transmitter is composed of three blocks.
In the program, it is managing three blocks by receiving status (RX_STATUS).
ST0, ST1, ST2 show receiving status with the figure above. A bit in each block is
managed by sub status (RX_SUBSTATUS). The figure which is written under
the signal in the figure above shows sub status.
When detecting the signal which doesn't match above-mentioned composition,
the detection operation returns first and begins with the condition of the existence
confirmation of the electric wave.

First, the detection operation of the preamble signal is done. It detects ON-OFF
three times, and it detects the ending mark (being OFF behind twice continuously
ON) of the preamble and it is judged a normally preamble signal. It makes status
"1" when receiving a normally preamble signal and the detection of the control
code is done.
Each bit of the control code is between the ON signal and the OFF signal. It is
stored in CONT_DATA every time it detects each bit. It makes status "2" when
receiving all of the 8 bits normally and it confirms an ending code.
The ending code is a three times continuously ON signal. When receiving an
ending code normally, the checking of a received control code is done. It is
checked with the beforehand registered control code. As a result, the RB port
which corresponds to the control code is controlled.

When finishing receiving above signal normally, it makes the condition of the
existence confirmation of the electric wave like the time of the receiving start-up.
Receiving timing is set once again by this. The clock of the transmitter and the
clock of the receiver aren't the same. So, when receiving long in the same timing,
the timing shifts and sometimes becomes that it isn't possible to receive. If
detecting the standing-up of the signal every time it receives each frame, the
receiving timing doesn't shift. Only the case to become ON condition from the
OFF condition is detected because it is using the last Look for the standing-up
detection of the signal.
Software Flow chart of Receiver (1/6)

You can jump to the corresponding flow chart when you click the part where the hand pointer.

Source code file of Receiver


001 ;********************************************************
002 ;
003 ; Remote Controller Receiver
004 ;
005 ; Author : Seiichi Inoue
006 ;********************************************************
007
008 list p=pic16f84a
009 include p16f84a.inc
010 __config _hs_osc & _wdt_off & _pwrte_on & _cp_off
011 errorlevel -302 ;Eliminate bank warning
012
013
014 ;**************** Label Definition ********************
015 cblock h'0c'
016 rx_status ;RX status save area
017 rx_substatus ;RX substatus save area
018 rx_edge ;Input edge check flag
019 last_look ;Input last look flag
020 code_ck ;Code check flag
021 cont_data ;Control Data
022 relay ;Relay ON counter
023 w_save ;W reg save area
024 s_save ;Status reg save area
025 endc
026
027 ptn1 equ b'11110000' ;Pattern 1 data
028 ptn2 equ b'00001111' ;Pattern 2 data
029 ra1 equ d'1' ;RA1 bit position
030 rb5 equ d'5' ;RB5 bit position
031 rb7 equ d'7' ;RB7 bit position
032
033 ;**************** Program Start ***********************
034 org 0 ;Reset Vector
035 goto init
036 org 4 ;Interrupt Vector
037 goto int
038
039 ;****************** Initial Process *******************
040 init bsf status,rp0 ;Change to Bank1
041 movlw b'00011111' ;RA4-0:IN mode
042 movwf trisa ;Set TRISA reg
043 movlw b'00000000' ;RB7-0:OUT mode
044 movwf trisb ;Set TRISB reg
045 movlw b'00000101' ;RBPU/TOCS/PSA=0,PS=101
046 movwf option_reg ;Set OPTION_REG
047 bcf status,rp0 ;Change to Bank0
048
049 clrf portb ;RL1,RL2 OFF
050 clrf rx_status ;Clear RX status
051 clrf rx_substatus ;Clear RX substatus
052 clrf rx_edge ;Clear Edge check flag
053 incf last_look,f ;Set Last Look flag ON
054 clrf code_ck ;Clear code check flag
055 clrf cont_data ;Clear Control Data
056 clrf relay ;Clear Relay ON counter
057 movlw d'100' ;256-10000us/64us = 100
058 movwf tmr0 ;Set 10msec to TMR0
059 movlw h'a0' ;GIE=1,TOIE=1
060 movwf intcon ;Interruption enable
061
062 ;*********** Initial Input check Process **************
063 edge_check
064 btfss porta,ra1 ;Input signal ON ?
065 goto check1 ;No. Signal OFF
066 btfsc last_look,0 ;Last Look flag OFF ?
067 goto edge_check ;No. Input NOT changed
068 bcf intcon,gie ;Interruption disable
069 incf code_ck,f ;Set code check flag ON
070 incf last_look,f ;Set Last Look flag ON
071 movlw d'178' ;256-5000us/64us = 178
072 movwf tmr0 ;Set 5msec to TMR0
073 bsf intcon,gie ;Interruption enable
074 wait
075 btfss rx_edge,0 ;Input edge check ?
076 goto wait ;No. Wait interruption
077 clrf rx_edge ;Clear edge check flag
078 goto edge_check ;Jump to Input edge check
079 check1
080 clrf last_look ;Set Last Look flag OFF
081 goto edge_check ;Jump to Input edge check
082
083 ;************ Timer Interruption Process **************
084 int
085 movwf w_save ;Save W register
086 movf status,w ;Read STATUS reg
087 movwf s_save ;Save STATUS reg
088 bcf status,rp0 ;Change to Bank0
089 bcf intcon,t0if ;Clear timer int flag
090
091 movf relay,w ;Read Relay ON counter
092 btfsc status,z ;Counter = 0 ?
093 goto stchk0 ;Yes
094 decfsz relay,f ;Counter - 1 = 0 ?
095 goto stchk0 ;No
096 clrf portb ;Relay OFF
097
098 stchk0
099 movf code_ck,w ;Read code check flag
100 btfsc status,z ;Flag ON ?
101 goto int_end ;No. End of interruption
102 movf rx_status,w ;Read RX status
103 btfss status,z ;Status = 0 ?
104 goto stchk1 ;No. Next
105
106 ;*********** Preamble data check Process *************
107 movf rx_substatus,w ;Read RX substatus
108 btfss status,z ;Substatus = 0 ?
109 goto st00 ;No. Next
110 goto st_on ;Input signal ON ?
111 st00 movlw d'1' ;Set check data
112 subwf rx_substatus,w ;Substatus - check data
113 btfss status,z ;Substatus = 1 ?
114 goto st01 ;No.
115 goto st_off ;Input signal OFF ?
116 st01 movlw d'2' ;Set check data
117 subwf rx_substatus,w ;Substatus - check data
118 btfss status,z ;Substatus = 2 ?
119 goto st02 ;No.
120 goto st_on ;Input signal ON ?
121 st02 movlw d'3' ;Set check data
122 subwf rx_substatus,w ;Substatus - check data
123 btfss status,z ;Substatus = 3 ?
124 goto st03 ;No.
125 goto st_off ;Input signal OFF ?
126 st03 movlw d'4' ;Set check data
127 subwf rx_substatus,w ;Substatus - check data
128 btfss status,z ;Substatus = 4 ?
129 goto st04 ;No.
130 goto st_on ;Input signal ON ?
131 st04 movlw d'5' ;Set check data
132 subwf rx_substatus,w ;Substatus - check data
133 btfss status,z ;Substatus = 5 ?
134 goto st05 ;No.
135 goto st_off ;Input signal OFF ?
136 st05 movlw d'6' ;Set check data
137 subwf rx_substatus,w ;Substatus - check data
138 btfss status,z ;Substatus = 6 ?
139 goto st06 ;No.
140 goto st_on ;Input signal ON ?
141 st06 movlw d'7' ;Set check data
142 subwf rx_substatus,w ;Substatus - check data
143 btfss status,z ;Substatus = 7 ?
144 goto st07 ;No. Substatus=8
145 goto st_on ;Input signal ON ?
146 st07 btfsc porta,ra1 ;Input signal OFF ?
147 goto illegal ;No. Jump to illegal
148 clrf rx_substatus ;RX substatus = 0
149 incf rx_status,f ;RX status = 1
150 clrf cont_data ;Clear count data
151 goto int_end ;End of interruption
152
153 ;********************************************************
154 stchk1
155 movlw d'1' ;Set check data
156 subwf rx_status,w ;RX status - check data
157 btfss status,z ;RX status = 1 ?
158 goto stchk2 ;No. Next
159
160 ;************ Control data check Process **************
161 movf rx_substatus,w ;Read RX substatus
162 btfss status,z ;Substatus = 0 ?
163 goto st10 ;No. Next
164 goto st_on ;Input signal ON ?
165 st10 movlw d'1' ;Set check data
166 subwf rx_substatus,w ;Substatus - check data
167 btfss status,z ;Substatus = 1 ?
168 goto st11 ;No.
169 btfss porta,ra1 ;B0 = 1 ?
170 goto stinc ;Jump to Substatus + 1
171 bsf cont_data,0 ;Set B0 = 1
172 goto stinc ;Jump to Substatus + 1
173 st11 movlw d'2' ;Set check data
174 subwf rx_substatus,w ;Substatus - check data
175 btfss status,z ;Substatus = 2 ?
176 goto st12 ;No.
177 goto st_off ;Input signal OFF ?
178 st12 movlw d'3' ;Set check data
179 subwf rx_substatus,w ;Substatus - check data
180 btfss status,z ;Substatus = 3 ?
181 goto st13 ;No.
182 goto st_on ;Input signal ON ?
183 st13 movlw d'4' ;Set check data
184 subwf rx_substatus,w ;Substatus - check data
185 btfss status,z ;Substatus = 4 ?
186 goto st14 ;No.
187 btfss porta,ra1 ;B1 = 1 ?
188 goto stinc ;Jump to Substatus + 1
189 bsf cont_data,1 ;Set B1 = 1
190 goto stinc ;Jump to Substatus + 1
191 st14 movlw d'5' ;Set check data
192 subwf rx_substatus,w ;Substatus - check data
193 btfss status,z ;Substatus = 5 ?
194 goto st15 ;No.
195 goto st_off ;Input signal OFF ?
196 st15 movlw d'6' ;Set check data
197 subwf rx_substatus,w ;Substatus - check data
198 btfss status,z ;Substatus = 6 ?
199 goto st16 ;No.
200 goto st_on ;Input signal ON ?
201 st16 movlw d'7' ;Set check data
202 subwf rx_substatus,w ;Substatus - check data
203 btfss status,z ;Substatus = 7 ?
204 goto st17 ;No.
205 btfss porta,ra1 ;B2 = 1 ?
206 goto stinc ;Jump to Substatus + 1
207 bsf cont_data,2 ;Set B2 = 1
208 goto stinc ;Jump to Substatus + 1
209 st17 movlw d'8' ;Set check data
210 subwf rx_substatus,w ;Substatus - check data
211 btfss status,z ;Substatus = 8 ?
212 goto st18 ;No.
213 goto st_off ;Input signal OFF ?
214 st18 movlw d'9' ;Set check data
215 subwf rx_substatus,w ;Substatus - check data
216 btfss status,z ;Substatus = 9 ?
217 goto st19 ;No.
218 goto st_on ;Input signal ON ?
219 st19 movlw d'10' ;Set check data
220 subwf rx_substatus,w ;Substatus - check data
221 btfss status,z ;Substatus = 10 ?
222 goto st20 ;No.
223 btfss porta,ra1 ;B3 = 1 ?
224 goto stinc ;Jump to Substatus + 1
225 bsf cont_data,3 ;Set B3 = 1
226 goto stinc ;Jump to Substatus + 1
227 st20 movlw d'11' ;Set check data
228 subwf rx_substatus,w ;Substatus - check data
229 btfss status,z ;Substatus = 11 ?
230 goto st21 ;No.
231 goto st_off ;Input signal OFF ?
232 st21 movlw d'12' ;Set check data
233 subwf rx_substatus,w ;Substatus - check data
234 btfss status,z ;Substatus = 12 ?
235 goto st22 ;No.
236 goto st_on ;Input signal ON ?
237 st22 movlw d'13' ;Set check data
238 subwf rx_substatus,w ;Substatus - check data
239 btfss status,z ;Substatus = 13 ?
240 goto st23 ;No.
241 btfss porta,ra1 ;B4 = 1 ?
242 goto stinc ;Jump to Substatus + 1
243 bsf cont_data,4 ;Set B4 = 1
244 goto stinc ;Jump to Substatus + 1
245 st23 movlw d'14' ;Set check data
246 subwf rx_substatus,w ;Substatus - check data
247 btfss status,z ;Substatus = 14 ?
248 goto st24 ;No.
249 goto st_off ;Input signal OFF ?
250 st24 movlw d'15' ;Set check data
251 subwf rx_substatus,w ;Substatus - check data
252 btfss status,z ;Substatus = 15 ?
253 goto st25 ;No.
254 goto st_on ;Input signal ON ?
255 st25 movlw d'16' ;Set check data
256 subwf rx_substatus,w ;Substatus - check data
257 btfss status,z ;Substatus = 16 ?
258 goto st26 ;No.
259 btfss porta,ra1 ;B5 = 1 ?
260 goto stinc ;Jump to Substatus + 1
261 bsf cont_data,5 ;Set B5 = 1
262 goto stinc ;Jump to Substatus + 1
263 st26 movlw d'17' ;Set check data
264 subwf rx_substatus,w ;Substatus - check data
265 btfss status,z ;Substatus = 17 ?
266 goto st27 ;No.
267 goto st_off ;Input signal OFF ?
268 st27 movlw d'18' ;Set check data
269 subwf rx_substatus,w ;Substatus - check data
270 btfss status,z ;Substatus = 18 ?
271 goto st28 ;No.
272 goto st_on ;Input signal ON ?
273 st28 movlw d'19' ;Set check data
274 subwf rx_substatus,w ;Substatus - check data
275 btfss status,z ;Substatus = 19 ?
276 goto st29 ;No.
277 btfss porta,ra1 ;B6 = 1 ?
278 goto stinc ;Jump to Substatus + 1
279 bsf cont_data,6 ;Set B6 = 1
280 goto stinc ;Jump to Substatus + 1
281 st29 movlw d'20' ;Set check data
282 subwf rx_substatus,w ;Substatus - check data
283 btfss status,z ;Substatus = 20 ?
284 goto st30 ;No.
285 goto st_off ;Input signal OFF ?
286 st30 movlw d'21' ;Set check data
287 subwf rx_substatus,w ;Substatus - check data
288 btfss status,z ;Substatus = 21 ?
289 goto st31 ;No.
290 goto st_on ;Input signal ON ?
291 st31 movlw d'22' ;Set check data
292 subwf rx_substatus,w ;Substatus - check data
293 btfss status,z ;Substatus = 22 ?
294 goto st32 ;No. Substatus=23
295 btfss porta,ra1 ;B7 = 1 ?
296 goto stinc ;Jump to Substatus + 1
297 bsf cont_data,7 ;Set B7 = 1
298 goto stinc ;Jump to Substatus + 1
299 st32 btfsc porta,ra1 ;Input signal OFF ?
300 goto illegal ;No. Jump to illegal
301 clrf rx_substatus ;RX substatus = 0
302 incf rx_status,f ;RX status = 2
303 goto int_end ;End of interruption
304
305 st_on
306 btfss porta,ra1 ;Input signal ON ?
307 goto illegal ;No. Jump to illegal
308 goto stinc ;Jump to Substatus + 1
309 st_off
310 btfsc porta,ra1 ;Input signal OFF ?
311 goto illegal ;No. Jump to illegal
312 goto stinc ;Jump to Substatus + 1
313
314 ;************** End data check Process ****************
315 stchk2 btfss porta,ra1 ;Input signal ON ?
316 goto illegal ;No. Jump to illegal
317 movlw d'2' ;Set check data
318 subwf rx_substatus,w ;Substatus - check data
319 btfss status,z ;Substatus = 2 ?
320 goto stinc ;Jump to Substatus + 1
321
322 ;**************** Data check Process ******************
323 movf cont_data,w ;Read control data
324 xorlw ptn1 ;Check Pattern1
325 btfss status,z ;Data = Pattern1 ?
326 goto dtchk0 ;No.
327 bcf portb,rb7 ;RL2 OFF
328 bsf portb,rb5 ;RL1 ON
329 goto dtchk1 ;Jump to ON counter set
330 dtchk0
331 movf cont_data,w ;Read control data
332 xorlw ptn2 ;Check Pattern2
333 btfss status,z ;Data = Pattern2 ?
334 goto illegal ;No. Jump to illegal
335 bcf portb,rb5 ;RL1 OFF
336 bsf portb,rb7 ;RL2 ON
337 dtchk1 movlw d'50' ;Set 500msec Relay ON
338 movwf relay ;Save Relay ON counter
339
340 ;***************** Illegal Process ********************
341 illegal incf rx_edge,f ;Edge check flag ON
342 clrf rx_substatus ;RX substatus = 0
343 clrf rx_status ;RX status = 0
344 clrf code_ck ;Clear code check flag
345 goto int_end ;End of interruption
346
347 ;*********** Substatus Increment Process **************
348 stinc incf rx_substatus,f ;Substatus + 1
349
350 ;******** End of Timer Interruption Process ***********
351 int_end movlw d'100' ;256-10000us/64us = 100
352 movwf tmr0 ;Set 10msec to TMR0
353 movf s_save,w ;Read saved STATUS reg
354 movwf status ;Recover STATUS reg
355 swapf w_save,f ;Read saved W register
356 swapf w_save,w ;Recover W register
357 retfie ;End of interruption
358
359 ;********************************************************
360 ; END of Remote Controller Receiver
361 ;********************************************************
362
363 end

Processing explanation of Receiver

Environment setting
Like the software of the transmitter, various environment setting is done at the line number 008-011 of the
list.

008 list It is defining the name of PIC to use.


009 include The file (p16f84a.inc) that a various standard label is defined is taken in.
010 __config The contents of Configuration Word are designated.
_hs_osc Type of the oscillator : HS
_wdt_off Watch-dog timer : It isn't used.
_pwrte_on Power up timer : It is used.
_cp_off Code protector : It isn't used.
The value of Configuration Word by above-mentioned specification is H'3FF2'.

011 errorlevel It makes not show bank switching warning message [302].
At the RAM file register of PIC16F84A, a bank method is adopted. For example,
both memory addresses of TMR0 and OPTION_REG is 01. However, TMR0 is at
bank 0 and OPTION_REG is at bank 1. In the definition file which is read by
INCLUDE, it defines the address of OPTION_REG as being H'0081'. Bank
information is written. The bank must be designated with RP0 bit of the STATUS
register by the actual processing. In case of MPLAB, to prevent mistake in the bank
processing, warning message "Message[302]" is shown in the processing of the
register of bank 1.
"Register in operand not in bank 0. Ensure that bank bits are correct."
When specifying a bank normally, this message is shown. To make not display this
message, there is a way of changing a definition file designation. That is, the message
becomes not displayed when changing the address of OPTION_REG into H'0001'.
Or, there is a way of stopping the display of 302 messages using the ERRORLEVEL
directive to be using this time.
Label definition
;**************** Label Definition ********************
CBLOCK and ENDC are used for the block definition of the RAM register file. The area of the label
among these commands is automatically set in the order from the address which is specified by CBLOCK.
ptn1 and ptn2 are the label which specifies control code data. The value to specify here must be the same as
the control code of the transmitter.
RX_STATUS Receiving status management area
0 : Preamble code receiving status
1 : Control code receiving status
2 : Ending code receiving status
RX_SUBSTATUS Receiving status management area
In each above-mentioned status, a status every receiving bit is managed.
RX_EDGE Electric wave rising edge detection request flag
When detecting an abnormal condition when receiving a control code from the
transmitter, this flag ONs. When detecting flag ON, the rising edge detection of the
electric wave becomes done.
LAST_LOOK Last Look flag
For the rising edge detection of the electric wave, the detection of the electric wave is
needed from the condition which doesn't have an electric wave. The condition that an
electric wave isn't received when checking the input port (RA1) which shows the
condition of the electric wave is memorized in this Last Look area. The rising edge of
the electric wave can be known if comparing with the Last Look area when receiving
an electric wave at the RA1 port.
CODE_CK Code check flag
For the operating time of the output relay, the 10-millisecond timer is making do
always operation. Because it checks a receiving code using this timer, it controls
whether or not to process a code in the checking by this flag. When receiving an
electric wave, a flag is made ON.
CONT_DATA Control data saving area
A control data is received every bit. Every time it receives a bit, data is saved in this
area.
RELAY Relay operating time count area
The operation of the output relay makes hold for about 500 milliseconds. When
making do the operation of the relay, 50 is set in this area. This value is subtracted
with the 10-millisecond timer and stops the operation of the relay when becoming 0.
W_SAVE W register saving area
When the timer interruption occurred, the content of the W register to be using by the
processing which was interrupted is saved in this area.
S_SAVE STATUS register saving area
When the timer interruption occurred, the content of the STATUS register to be using
by the processing which was interrupted is saved in this area.

Program start
;**************** Program Start ***********************
The program memory address 0 is the program starting address when turning on or reset occurs. Also, the
program memory address 4 is a start address when interruption occurs. These addresses are decided with the
hardware of PIC16F series.

Initialization process
;**************** Initial Process *********************
Port initialization
First, the initialization of the port is done. RA0 to RA4 are set to the input mode and the RB0 to
RB7 are set to the output mode.
In the relation of the wiring, RA0 and RA3 are grounded. So, RA0 and RA3 must be always made
an input mode.

Timer setting
This circuit controls the data to transmit in the 10-millisecond interval. Timer 0 is used to make
10-millisecond time. TOCS and PSA of OPTION_REG are set to "0" to use an internal clock and
prescaler for timer 0. It makes prescaler value "101"(1:64). Because it is using 4 MHz for the
oscillator of PIC, the clock is one microsecond. TMR0 is increased every 64 microseconds when
combining with prescaler. The timer interrupt generates TMR0 when count value (TMR0)
becomes 0 from 255(H'FF'). So, the value to set to TMR0 for the 10-millisecond timer is 256-
(10000/64)=100. It uses the prescaler value which is the same as the transmitter to make a timer
error little.

Initialization of the register


When turning on the power of PIC, the initialization for various register is executed with hardware.
I am doing initialization to make those original values certainty.
PROTB = 0 It stops the operation of the output relay.
RX_STATUS =0
It does the initialization of the receiving status management area.
RX_SUBSTATUS = 0
RX_EDGE = 0 It clears an electric wave rising edge detection request flag.
LAST_LOOK It does the initialization of the Last Look to electric wave
=1
receiving(ON).
CODE_CK = 0 It makes the condition which doesn't check a control code.
CODE_DATA = 0 It does the initialization of the control data save area.
RELAY = 0 It clears a relay operation counter.

10 milliseconds timer setting


It starts a 10-millisecond timer to manage the operating time of the relay.

Receiving preprocess
;*********** Initial Input check Process **************
The receiving state of the electric wave is checked by the condition of the RA1 port. When not receiving an
electric wave, Last Look flag (LAST_LOOK) is made OFF. You have the possibility to seem, that this
processing is unnecessary. To detect the rising edge timing of the electric wave, it is necessary to confirm
that there is not an electric wave. Also, it is possible to prevent the wrong operation which is due to the
continuously electric wave with this Last Look data. The time is the rising edge of the electric wave when
an electric wave is detected in the last Look flag is OFF. The pulse from the transmitter switches over in the
10-millisecond interval. So, the signal detection timing at the receiver is shifted for 5 milliseconds from
therising edge of the electric wave. These 5 milliseconds are only first. The signal detection timing after that
is a 10-millisecond interval. A 10-millimeter timer is set by the initialization processing. When detecting the
rising edge of the electric wave, this timer is again set to 5 milliseconds compulsorily. Therefore, to prevent
timer interruption's occurring during this timer setting processing of 5 milliseconds, interruption disable
processing is done.(INTCON.GIE=0) After it, it makes code check flag (CODE_CK) ON and it makes
execute code check processing to timer process. Because it detected an electric wave, it makes a Last Look
flag ON. An interruption is made enable after setting a 5-millisecond timer to TRM0. After this, it becomes
the processing to wait for the timer interruption. In the processing of interruption's wait, the checking of the
electric wave rising edge detection request flag is done. When to be illegal is detected by the detection
processing of a control code, this flag is made ON. When detecting ON of this flag during interruption's
wait processing, after clearing this flag, it jumps to the electric wave rising edge detection processing and
the receiving operation returns to the initial state.
Timer interrupt process
;************ Timer Interruption Process **************
Saving registers
In the timer interruption processing, the saving of W register and STATUS register is done first.
When not doing this processing, the contents of the register before the interruption are changed by
the interruption processing and the processing after interruption's ending becomes impossible. This
time, it is to be OK even if W register isn't saved, because W register isn't used in the processing
before the interruption. I saved them for the safety. When sharing the other register, they must be
saved too. Memory bank specification is set for the safety too.

Clearing of a timer interruption flag


When the interruption occurs, the flag which shows an interruption factor is set. In case of timer 0,
the INTCON.T0IF bit is set. This bit must be cleared by the interruption processing. When not
clearing, the interruption factor doesn't go out and also the same interruption has occurred.

Checking of an output relay counter


fter making do the operation of the output relay, it is made to continue operation for about 500
milliseconds. The value of relay operation counter (RELAY) is subtracted to watch over the time.
When the counter value is 0 already, counter subtraction processing isn't done. The counter is not 0
and when becoming 0 with the subtracted result, the operation of the relay is stopped.

Checking of receiving status


Checking processing is decided by the contents of RX_STATUS. In case of 0, a preamble code is
checked. In case of 1, a control code is checked. In case of 2, an ending code is checked.

;*********** Preamble data check Process *************


Checking of a preamble code
The preamble code is 101010110. At design first, I assumed that the ending of the preamble was
judged at 11 after 10 continuously was detected. However, finally, I changed to be judged
normally all preamble code strings. It is because the control code can have 10110 bit strings too.
For example, it becomes the same bit string when receiving from the position of B0 in case of
B0=1, B1=1. However, because the ahead of B0 is always 1, the rising edge detection of the
electric wave isn't done and wrong operation like the above isn't done. However, I decided to
check all bit strings because I had changed processing. Receiving status management of each bit is
done by RX_SUBSTATUS. It makes RX_STATUS "1" when receiving a normally preamble code
and it enters control code receiving. At this time, it clears control data saving area (CODE_DATA)
and it erases the control code which was received before. It jumps to illegal process when detecting
abnormally in the bit string.

;************ Control data check Process **************


Checking of a control code
The configuration of the control code is 1x01x01x01x01x01x01x01x0. x is the bit of the control
code. There are 8 bits at all. It checks this bit string in the order and the part of x is saved into
control data saving area (CODE_DATA). It makes RX_STATUS "2" when receiving a normally
control code and it enters ending code receiving. It jumps to illegal process when detecting
abnormally in the bit string.

;************** End data check Process ****************


Checking of an ending code
The ending code is 111. It judges a normally ending code when 1 is continuously received three
times when RX_STATUS is in the condition of "2" and it enters the checking processing of a
control data. It jumps to illegal process when detecting abnormally in the bit string.

;**************** Data check Process ******************


Checking of a control data
As for the control data checking processing, it confirms whether the received data matches the data
of pattern 1 or pattern 2. These patterns must be made the same as the pattern of the transmitter.
When matching pattern 1, make do the operation of relay 1 and it makes relay 2 non-operation.
When matching pattern 2, make do the non-operation of relay 1 and it makes relay 2 operation.
Then, after making do the operation of either relay, 50 is set in relay operating time count area
(RELAY) for the 500-millisecond holding time. This value is subtracted every 10 milliseconds and
the operation of the relay stops 500 milliseconds later. It enters illegal processing in case of control
data's matching neither patterns or driving a relay normally. It is to make set receiving timing again
every time it receives a code normally that it enters illegal processing in case of normally.

Illegal process
;***************** Illegal Process ********************
This illegal processing is executed when the code to receive is not a prescribed string or all data is normally
received. In the illegal processing, the following processing is done.
It sets the electric wave rising edge detection request flag (RX_EDGE) and the rising edge detection of the
electric wave is done by this. It clears the receiving status management data
(RX_STATUS,RX_SUBSTATUS) and it makes the condition to check a preamble code. It clears code
check flag (CODE_CK) and it makes control code checking processing in timer processing of 10
millimeters skip. After that, it enters interruption's ending processing.

Substatus increment process


;*********** Substatus Increment Process **************
Substatus is used to manage the position of the detection bit in each receiving condition (the preamble, the
control code, the ending code). Every time it receives by 1 bit, it increases substatus. After that, it enters
interruption's ending processing.

Interruption's ending process


;******** End of Timer Interruption Process ***********
Timer interruption's ending is done by this processing.
First, it sets the timer value of 10 milliseconds to TMR0 because of the timer interruption next time. It
restores W register and STATUS register after it. It restores STATUS register first. This is to use W register
to restore STATUS register. The contents of the W register have changed with the restoration value when
restoring W register first. It restores W register last. However, the contents of the STATUS register have
changed when using MOVF instruction for the restoration of the W register. Therefore, it restores W
register using the SWAPF instruction which the contents of the STATUS register don't change. The
interruption processing ends last in the RETFIE instruction. With this instruction, it jumps to the
interruption return address which was saved in the stack area and moreover "1" is set to the INTCON.GIE
bit and the interruption becomes an enable condition.

Operation confirmation of Receiver-1

Adjustment of the receiving frequency


I used Dip meter, High frequency detector and Circuit tester for the adjustment of the receiver.
In case of the high frequency circuit, the resonant frequency is not as the calculation. The wiring becomes the part of
the coi and the capacitance changes in the interval of the wiring and influences the value of the capacitor. So, an
adjustment is always needed.
Adjustment of the high frequency transformer
There is a notch at the top of the core of the high frequency transformer and the position of the
core can be adjusted with the screwdriver and so on. When turning a core to the right, a core is
inserted in the coil of the transformer. With this, the inductance of the coil becomes big and the
resonant frequency becomes low. When turning a core to the left, the core gets away from the coil.
With this, the inductance of the coil becomes small and the tuning frequency becomes high. As for
the position at the head of the core, the position of the surface of the transformer is desirable. It
changes the value of the capacitor to be putting in the coil in parallel to become like this as
possible.

Adjustment of L1
It connects a high frequency detector with . It checks the resonant frequency of L1 while
changing the frequency of the dip meter. When different from the planned frequency (about 83
MHz) extremely, it changes the value of C1. Because there is not an amplifier in the part of , the
voltage is small. So, the circuit tester which is connected with the high frequency detector should
be set in the voltage range as small as possible. But, it is necessary to pay attention in the surplus
of the voltage to prevent circuit tester's breaking. Because the voltage of is small, it doesn't have
to adjust, being detailed.

Adjustment of L2
Next, it connects a high frequency detector with and it adjusts L2. When changing the value of
C1 in adjustment of L1, it makes C2 the same value too. Because there is a high-frequency
amplifier before , the output voltage becomes higher little than .

Adjustment of L3
Next, it connects a circuit tester with and it adjusts L3 as previous. Because the voltage of is
changed into the direct current by the diode, it can not connect a high frequency detector.
I made the value of C3 1pF less than C2. The core fitted the top of the transformer at this value.

Last adjustment of the resonant frequency


It stops the oscillation of the dip meter and it brings the coil of the dip meter close to the coil of the
transmitter. While turning the dial of the dip meter, it checks the point where the needle of the
meter moves. The frequency is the oscillation frequency of the transmitter.
Making do the operation of the oscillator of the dip meter without changing the position of the dial.
It brings an antenna with receiver close to the coil of the dip meter. It connects a circuit tester with
the position of , it adjusts L1, L2 and L3 in the order and the voltage of maximizes. The
electric wave of the transmitter can be used without using a dip meter, too. Because the
transmission frequency changed when the transmitter made do long operation, I used a dip meter.
It confirms that it receives the electric wave of the transmitter after the adjustment by the dip meter
ends and that voltage is gotten at .

Confirmation of the comparator output


It connects a circuit tester with the 7th pin of IC1. It confirms that it becomes 0V when not
receiving an electric wave and it becomes +5V when receiving an electric wave.
Above, all adjustments of the receiver are ending. After this, it loads PIC and it confirms the operation of the relay
and the lighting-up of the LED which corresponds with the transmission code.
I mounted PIC and confirmed normally operation.

Sensitivity with receiver


The sensitivity with the receiver which was made this time isn't good. I can not measure sensitivity because
I don't have a measurement receptacle. Approximately hereinafter.
It puts a 1-m antenna to the receiver and it puts a 20-cm antenna to the transmitter. As for the distance
between the receiver antenna and the transmitter, about 1m is a limit.
It seems not to be practical. However, I think that it can be used for the control of the door or the control of
the security lock and so on. In this case, there is not high receiver sensitivity, being needed. (Excusing)
At first, I thought that it was possible to control from the place to have left by about 5m. It was impossible.
Because the receiving sensitivity which was hoped for wasn't gotten, I think that I will make the receiver
which used IC for the FM receiver.

Anda mungkin juga menyukai