Professional Documents
Culture Documents
On these pages, I will introduce the electronic circuits making which used the PIC(Peripheral Interface
Controller) which is the one-chip microprocessor.
I will make this page for the beginner of PIC including me.
PIC Programmer
Radix
In the software of the computer, hexadecimal is often used.
Decimal
In our daily life, 10 numbers from "0" to "9" are used.
In case of the count-up, after 9, the carry is done and becomes 10. We are using properly but this is
the count method of the number which the human being decided.
This seems to depend on that the fingers of the hand of the person is 10.
Binary
Only two values of "0" and "1" are used to express a condition by the digital world which included a
computer. These are sometimes expressed by "Low level " and "High level ", too.
Like 0 1 10, after 1, it is 10.
Hexadecimal
In the condition to be handling with the computer, it is a binary number but it is difficult to
understand for the person who is using the decimal.
163(Decimal) 10100011(Binary)
Therefore, a hexadecimal is used as the expression which it is easy for the person to understand. As
for the hexadecimal, 16 numbers are used for 1 digit. It is from 0 to 9 that it is expressed by the
figure. So, six of the remainder are expressed by the alphabet.
10 A, 11 B, 12 C, 13 D, 14 E, 15 F
The figure has begun with 0. Therefore, 10 of the figure shows the 11th and 15 shows the 16th.
16 kinds of conditions are expressed by 4 bits in the binary. Oppositely, the hexadecimal is used
because that it is possible to express 16 by 4 bits. There is the octal which is expressed by 3 bits. In
case of the hexadecimal, 1 byte is expressed by 2 digits.
Also, it puts "h" to distinguish the hexadecimal from the decimal. h is the initial of hexadecimal(16).
It shows in 00h or H'00' or 0x00. However, an expression isn't unified.
The change of Binary, Decimal and Hexadecimal can make simple if you use the function electronic
calculator which is attached to the Windows.
When changing without using the calculator, it is possible to do in the following way.
It is possible to change simply if dividing 4 bits.
It is easier if learning a binary pattern to Fh from Ah.
EX. 111000100100010000100 1C4884h
It is possible to change 1 digit of the hexadecimal into the binary in the order.
EX. 5F37Bh 1011111001101111011
This is troublesome a little.
First, you write a decimal value every bit like
the following figure. Total the decimal value of
the bit of "1".
EX.
Change a decimal into the binary first and change a result into the hexadecimal more.
In case of the example(D B) which was shown above, 582 = 1001000110 = 246h.
2's Complement
The 2's complement is the one which shows negative numerical value.
For example, "-1" of the decimal number is 11111111 when showing by the binary with byte.
It is as follows when confirming.
OPECODE
The code to distinguish a instruction is written.
:
d (Destination select) It specifies the register which stores the execution result of the instruction.
: d=0 : It specifies working register ( W reg ).
d=1 : It specifies file register which is specified by f.
In case of the assembler language, d is written in W or F.
(EX) ADDWF COUNT,W ( d=0 when writing W )
ADDWF COUNT,F ( d=1 when writing F )
f (Register file) : It specifies the address of the register which is dealt with for the instruction.
f can specify an address from 0(00h) to 127(7Fh) because it is 7 bits.
In case of PIC16F84A, because the register memory is 80 bytes including SFR, it is
possible to be specified by f if being 7 bits.
When writing by the assembler language, the label is put to the register and uses.
(EX) ADDWF COUNT,F ( COUNT is the label of the register)
f (Register file) : It specifies the address of the register which is dealt with for the instruction.
f can specify an address from 0(00h) to 127(7Fh) because it is 7 bits.
In case of PIC16F84A, because the register memory is 80 bytes including SFR, it is
possible to be specified by f if being 7 bits.
When writing by the assembler language, the label is put to the register and uses.
k (Literal field) : This is the fixed number to use for the calculation.
It specifies by the numerical value or the label.
Because it is a byte except JUMP and CALL instruction, it is the range of 0(00h) to
255(FFh).
Because GOTO or CALL instruction is 11 bits, it is the range of 0(00h) to
2047(7FFh).
In PIC16 series, RISC(Reduced Instruction Set Computer) is adopted and the number of the instructions to
use is 35 kinds.
When clicking the mnemonic of each instruction, you can jump to the instruction specification.
The terminology explanation
Mnemonic : The assembler language which made an operation code plain
Operands : The specification part except the operation code
MSb : Most Significant bit
LSb : Least Significant bit
Flag : The field of the STAUS register
CLRF f Clear f Z
CLRW - Clear W Z
COMF f, d Complement f Z
DECF f, d Decrement f Z
INCF f, d Increment f Z
MOVF f, d Move f Z
MOVWF f Move W to f
NOP - No Operation
GOTO k Go to address
x : Don't care
Detail specification of PIC16F84A(1)
On this page, I will explaine about the specification of the contents of the various registers of the PIC16F84A.
A color of INDF and EECON2 is changed because the way of using these registers is different from the other
register.
R= Readable bit
P= Programmable bit
-n = Value at POR reset
u= Unchanged
Bit13-4: Code Protection bit
CP 1 = Code protection off
0 = All memory is code protected
Code protection is used to prevent from the reading of the memory contents of the
PIC.
It sets to OFF if not needing the reading protection.
Bit3: Power-up Timer Enable bit
PWRTE(inv) 1 = Power-up timer is disabled
0 = Power-up timer is enabled
The power up timer is the timer to maintain the reset condition for about 72 ms
after the turning on.
Generally, it sets to enable.
Bit2: Watchdog Timer(WDT) Enable bit
WDTE 1 = WDT enabled
0 = WDT disabled
Bit1-0: Oscillator Selection bits
FOSC1 FOSC1 FOSC0 Oscillator mode Freq
FOSC0
1 1 Resistor/Capacitor Less than 1MHz
1 0 High Speed Crystal/Resonator 4MHz to 20MHz
0 1 Crystal/Resonator Less than 4MHz
0 0 Low Power Crystal Less than 200KHz
Instruction spec (1) of PIC16 series
Instruction set
Operation
(EX)
Instruction
1 cycle
cycles
(EX)
Instruction
1 cycle
cycles
ANDLW AND literal with W
Operation
(EX)
Instruction
1 cycle
cycles
(EX)
Instruction
1 cycle
cycles
Next instructions
Instruction spec (2) of PIC16 series
Instruction set
Operation
(EX)
Flag No change
Instruction
1 cycle
cycles
Operation
(EX)
Flag No change
Instruction
1 cycle
cycles
Flag No change
Instruction
1 cycle
cycles
Flag No change
Instruction
1 cycle
cycles
Instruction spec (3) of PIC16 series
Instruction set
Flag No change
Instruction
2 cycles
cycles
CLRF Clear f
00000000 f register
Operation 1 Z flag
CLRW Clear W
Operands None
00000000 W register
Operation 1 Z flag
Instruction
1 cycle
cycles
Operands None
Operation
Instruction
1 cycle
cycles
Instruction spec (4) of PIC16 series
Instruction set
COMF Complement f
(EX)
Instruction
1 cycle
cycles
DECF Decrement f
(EX)
Flag No change
Instruction 1 cycle
cycles When skipping, it is 2 cycles.
GOTO Go to address
Flag No change
Instruction
2 cycles
cycles
Instruction spec (5) of PIC16 series
Instruction set
INCF Increment f
(EX)
Instruction
1 cycle
cycles
Flag No change
Instruction 1 cycle
cycles
(EX)
Instruction
1 cycle
cycles
(EX)
Instruction
1 cycle
cycles
Instruction spec (6) of PIC16 series
Instruction set
MOVF Move f
Instruction
1 cycle
cycles
Operation
Operation No change
Instruction
1 cycle
cycles
MOVWF Move W to f
Operation
Flag No change
Instruction
1 cycle
cycles
NOP No Operation
Operands None
Flag No change
Instruction
1 cycle
cycles
Instruction spec (7) of PIC16 series
Instruction set
Operands None
Flag No change
Instruction
2 cycles
cycles
Flag No change
Instruction
2 cycles
cycles
RETURN Return from Subroutine
Operands None
Operation
Flag No change
Instruction
2 cycles
cycles
Instruction
1 cycle
cycles
Instruction spec (8) of PIC16 series
Instruction set
Instruction
1 cycle
cycles
Operands None
Instruction
1 cycle
cycles
(EX)
Instruction
1 cycle
cycles
(EX)
Instruction
1 cycle
cycles
Instruction spec (9) of PIC16 series
Instruction set
Operation
Flag No change
Instruction
1 cycle
cycles
Operation
(EX)
Instruction
1 cycle
cycles
XORWF Exclusive OR W with f
(EX)
Instruction
1 cycle
cycles
Software making procedure
Flow chart
It is an old technique but to make software using the flow chart is simple. The flow of the processing can be
made clear. When the step of the software increases, there is possibility to get not to understand the whole.
More than two kinds of flow charts are sometimes made.
To make software is to make the order of the operation to make PIC do. Therefore, it is necessary to decide
what operation you want to make the PIC.
For example, it makes an LED blink, it makes judge the condition of the input or it lets out a specific signal...
I will explain the following example for you to understand software creating easily.
Condition
The memory to count-up is the 0Ch address of the RAM file register.
Processing flow
The processing immediately after the turning on starts from address 0 of the PM.
In the actual program, the initialization processing is necessary. However, in the example
this time, it is omitted.
The PIC does following operation when writing contents like the above in the 3 words from the head
of the PM and turning on the power.
First, the 0Ch address of the file register is cleared in address 0 of PM and count-up in address 1 of
PM. Next, the GOTO instruction is executed in address 2 and jumps to address 1. Then, it repeats the
operation to count-up again. This processing doesn't end until it switches off the power.
PIC recognizes the combination of "0" and "1" which was written in the PM as the instruction. The
instruction which was expressed by the combination of "0" and "1" is called machine code. At the
digital computer, machine code is always used. Machine code is used for the personal computer
which you are using, too. However, the contents of the machine code depend on the processor.
Therefore, the Pentium doesn't work by the machine code for PIC.
I did contents above by the hand computation. However, it is difficult to do in the hand computation
when the number of the processing(Step) increases.
Therefore, the soft development tool which is called the assembler or the compiler is used for the
software creating. These tools are the one to make it easy for the person to make software.
The instruction can be expressed by the character. It is possible to use a character string(Label) when
specifying the address of the memory. So on.
Also, when working the same software in the hardware which the machine code is different from, it
is sometimes possible if changing only machine code. In the such case, because the assembler or the
compiler changes into the machine code which suited the hardware automatically, the person has the
advantage that he can make software without being conscious of the machine code, too.
It is as follows when changing above-mentioned processing into the machine code automatically
using MPASM(Assembler) of the Microchip Inc..
The input file for the assembler(Source code) is made with Editor. The person makes this source
code. This work is called CODEING.
GOTO
LOOP
END
The Listing File
00001 LIST
P=16F84A
0000 00002 ORG
0
0000 018C 00003 CLRF
0C
0001 0A8C 00004 LOOP INCF
0C,1
0002 2801 00005 GOTO
LOOP
00006 END
To debug, there are some ways. Here, the way of executing 1 step and the way by the breakpoint(It stops
processing temporarily) are explained.
I use the program which was shown by the previous example for the explanation.
The preparation
It had better display a listing file and a file register beforehand in the window.
Window > Absolute Listing : The listing file display
Next, let's attempt to confirm the contents of the file register. 03h become 18. This addess is
STATUS register. TO and PD become "1". This shows a condition immediately after the turning on.
When clicking the step button, the PC bar change address 1 and address 2 alternately.
Every time the instruction of 1 address is executed, 0Ch of the file register is updated.
( Setting 2 )
This is the way of making a label a breakpoint.
A breakpoint setting dialog is displayed when pressing .
This setting can make execute with Debug > Break Settings... , too.
Choose the label to want to set a breakpoint by the Start item of the setting dialog.
When clicking the "Add" button, a breakpoint is added. If a checking mark is displayed, the
breakpoint is effective.
The preparation
It had better display a listing file and a file register beforehand in the window.
Window > Absolute Listing : The listing file display
Window > File Registers : The file register display
02h (PC) 00
03h (STATUS) 18
In the condition which stops at the breakpoint, the debugging operation continues. When ending
debugging, it is necessary to make stop at the stop button.
Guidelines to make the Source Code
The source code should be written by the language which is interpreted by the assembler or the compiler.
When using MPASM, an assembly language is used. When you write a source code with the C language, the
compiler of the C language is necessary.
The compiler interprets the sentence which was written in 1 line and spreads out to the instruction
group(Generally, it is more than one instruction) to realize it. In case of the assembler, it changes each source
code into the instruction. The C language can make a program with few source codes. But, a wasteful
machine code is sometimes contained by the performance of the compiler. It is because it replaces with the
machine code automatically.
When using a compiler, you can make a program easily. When using a memory efficiently, the assembler
suits.
The source code file can be created using any ASCII text file editor. The lowercase and the uppercase are to
be OK as the character.
I will explain the making of the source code which used an assembly language on these pages.
Generally, using the TAB, the position of the mnemonic, the operand, the comment is arranged for.
It is for that it is easy to see.
Mnemonics
Assembler instruction mnemonics, assembler directives and macro calls must begin in
colum two or greater.
If there is a label on the same line, instructions must be separated from that label by a
colon, or by one more spaces or tabs.
Generally, the position of the instructions are arranged for using the tab.
The character which it is possible to use is an alpha character or an under bar.
Operands Operands must be separated from mnemonics by one more spaces, or tabs.
Multiple operands must be separated by commas.
The spaces can be put behind the commas for that it is easy to see.
Directive Language
PIC16F84A has 35 kinds of instructions. These instructions are the instructions to use when PIC
processes.
MPASM has the directives to control the operation of the assembler as well as it. MPASM has 58
kinds of directives.
These directives are used according to need. However, in the end of the source code, the END
must be always written.
When there is not an END, the assembler doesn't recognize written contents as the source code.
| : An OR selection
Descripton Generates a series of RETLW instructions, one instruction for each <expr>.
Syntax END
Occurring on a line by itself, the LIST directive has the effect of turning listing
output on, if it had been previously turned off. Otherwise, one of the following
list option can be supplied to control the assembly process or format the listing
file.
Set the program origin for subsequent code at the address defined in <expr>.
Descripton
If no ORG is specified, code generation will begin at address zero.
IF <expr>
........
Syntax
ELSE
........
Begin execution of a conditional assembly block. If <expr> evaluates to true,
the code immadiately following the IF will assemble. Otherwise, subsequent
code is skipped until an ELSE directive or an ENDIF directive is encountered.
An expression that evaluates to zero is considered logically FALSE. An
Descripton expression that evaluates to any other value is considered logically TRUE. The
IF and WHILE directives operate on the logical value of an expression. A
relational TRUE expression is guaranteed to return a nonzero value, FALSE a
value of zero.
These directives don't generate instructions like the C language. They only
WHILE <expr>
Syntax ........
ENDW
The lines between the WHILE and the ENDW are assembled as long as <expr>
evaluates to TRUE. An expression that evaluates to zero is considered logically
FALSE. An expression that evaluates to any other value is considered logically
TRUE. A relational TRUE expression is guaranteed to return a non-zero value;
Descripton FALSE a value of zero.
A WHILE loop can contain at most 100 lines and be repeated a maximum of
256 times.
These directives don't generate instructions like the C language. They only
control the source code to assemble.
Radix Specifications
Type Syntax Example
Decimal D'<digits>' or .(dot)<digits> D'100' or .100
H'<hex_digits>' or 0x<hex_digits> or H'A8' or 0xA8 or
Hexadecimal
0<hex_digits>H 0A8H
Octal O'<octal_digits> O'567'
Binary B'<binary_digits> B'011001'
ASCII A'<characters>' or '<characters>' A'ABC' or 'ABC'
_ _badram <expr>[-<expr>][,<expr>[-
_ _BADRAM Specify invalid RAM locations
<expr>]]
constant
CONSTANT Declare Symbol Constant
<label>[=<expr>,...,<label>[=<expr>]]
[<label>] db <expr>[,<expr>,...,<expr>]
DB Declare Data of One Byte [<label>] db
"<text_string>"[,"<text_string>",...]
[<label>] de <expr>[,<expr>,...,<expr>]
DE Define EEPROM Data [<label>] de
"<text_string>"[,"<text_string>",...]
#define <name>[<value>]
#DEFINE Define a text Substitution Label
#define <name>[<arg>,...,<arg>]<value>
[<label>] dt <expr>[,<expr>,...,<expr>]
DT Define Table [<label>] dt
"<text_string>"[,"<text_string>",...]
[<label>] dw <expr>[,<expr>,...,<expr>]
DW Declare Data of One Word
[<label>] dw
"<text_string>"[,"<text_string>",...]
variable
VARIABLE Declare Symbol Variable
<label>[=<expr>,...,<label>[=<expr>]]
On these pages, I will introduce the Ultrasonic Range Meter with PIC16F873.
As for the range meter which doesn't use PIC, refer to "Ultrasonic Range Meter".
A/D The propagation speed of the sound changes with the temperature.
converter I used A/D converter to revise a display.
Hardware Software
Circuit drawing List
Receiver circuit
The receiver circuit is almost same
as the "Ultrasonic Range Meter"
which is not used PIC.
Detection circuit
The detection is done to detect the received ultrasonic signal. This is the half-wave rectification circuit
with Shottky barrier diodes. The DC voltage according to the level of the detection signal is output to
the capacitor behind the diode. The Shottky barrier diodes are used because the high frequency
characteristic is good.
As for the Shottky barrier diode, refer to "Diodes".
Signal detector
This circuit is the circuit which detects the ultrasonic which returned from the measurement object. The
output of the detection circuit is detected using the comparator. At the circuit this time, the operational
amplifier of the single power supply is used instead of the comparator. The operational amplifier
amplifies and outputs the difference between the positive input and the negative input.
In case of the operational amplifier which doesn't have the negative feedback, the output becomes the
saturation state by a little input voltage. Generally, the operational amplifier has over 10000 times of
mu factors. So, when the positive input becomes higher a
little than the negative input, the difference is tens of
thousands of times amplified and the output becomes the
same as the power supply almost.(It is the saturation state)
Oppositely, when the positive input becomes lower a little
than the negative input, the difference is tens of thousands of
times amplified and the output becomes 0 V almost.(It is in
the OFF condition) This operation is the same as the
operation of the comparator. However, because the inner
circuit of the comparator is different from the operational
amplifier, the comparator can not be used as the operational
amplifier.
At the circuit this time, the output of the detection circuit is connected with the positive input of the
signal detector and the voltage of the negative input is made constant.
Vrf = ( Rb x Vcc )/( Ra + Rb )
= ( 47K-ohm x 9V )/( 1M-ohm + 47K-ohm )
= 0.4V
So, when the rectified ultrasonic signal becomes more than 0.4 V, the output of the signal detector
becomes the H level (Approximately 9V).
This output is lowered with the resistor to make fit with the input of signal holding circuit (TTL:0V to
5V).
This is the holding circuit of detected signal. SR ( Set and Reset ) flip-flop is used. For the details of
SR-FF, refer to "The operation explanation of the D-type flip-flop".
The detector is made to be not operate in the constant time(About 1.5 milliseconds) after sending out a
transmission pulse to prevent from the wrong detection which is due to the influence of the transmission
pulse. This operation is controlled with the software of PIC.
When using the capture feature of PIC, this circuit isn't indispensable. Capture operation is done by the
change of the capture input in the once. The reason why I am using this circuit is to confirm signal
detection operation within the reflected signal detection time(About 65 milliseconds). When sending
out next ultrasonic pulse, the output of this circuit is checked. And when the output is L level, an error
display is done because the reflected signal could not be detected.
Transmitter circuit
The inverter is used for the drive of the ultrasonic sensor. The two inverters are connected in parallel
because of the transmission electric power increase.
The phase with the voltage to apply to the positive terminal and the negative terminal of the sensor has
been 180 degrees shifted. Because it is cutting the direct current with the capacitor, about twice of
voltage of the inverter output are appied to the sensor.
The power supply voltage of this drive circuit is +9V. It is converting voltage with the transistor to
make control at the operating voltage of PIC(+5V). Because C-MOS inverters are used, it is possible to
do ON/OFF at high speed comparatively.
Three 7 segment LEDs are used for 3-digit display. As for the lighting-up of the LED, 1 digit is
displayed in the order with the software of PIC.
At the circuit this time, I
make light up it when the
terminal of PIC is L level.
So, ANODE
COMMON type is used
as the LED. The anode
common type is the type
which the side of the
positive(Anode) of the LED
is connected inside. It lights
up when grounding(L level)
a cathode in the segment to
want to make light up.
As the 7 segment LED, the others have a cathode common type. When you buy them, the specification
of the type should be checked.
At this range meter, a conversion value is generated using the A/D conversion feature. The A/D
converter converts input voltage into the 10-bit digital data. This time, I am using upper 3 bits. So, the
A/D conversion result from 0V to 5V is the value from 0 to 7. And 54 is added to this value.
Then, the conversion value range is from 54 to 61.
Resonator
I used 4-MHz resonator.
I used 4 MHz in the relation of the timer in the count time.
When using 4-MHz clock, it is 1 microsecond per count for
the counter count up time. Timer1 to use for capture is a
maximum of 65535 counts(16 bits). So, a maximum of
65.535 milliseconds count is made.
The propagation speed of the sound in air is 343 m/second in
case of 20°C. In the time which goes and returns in the 10-m
distance, it is 20m/343m/sec = 0.0583 seconds (58.3
milliseconds). As the range meter this time, it is an exactly
good value.
Ultrasonic sensor
I used the ultrasonic sensor for the air which is made by the Nippon Ceramic
company. This sensor separates into the two kinds for the transmitter and the
receiver. For the transmitter, it is T40-16 and for the receiver, it is R40-16. T
shows the thing for the transmitter and R shows the thing for the receiver. 40
shows the resonant frequency of the ultrasonic.(40kHz) 16 shows the diameter of
the sensor.
Because the one of the terminal is connected with the case, when grounding, the
terminal on the side of the case should be used.
As for the detail specification, refer to "The specification of the ultrasonic sensor".
PIC1
6F87
3
In the
circuit
this
time,
capture
feature
and
A/D
convert
er
feature
are
used.
This IC is the single power supply-type operational amplifier. This IC is used for the detection of the received
signal.
The comparator can be used.
Inverters ( 4069UB )
The stable +9V can be gotten from +12V input by this IC.
The maximum output current is 100 mA.
This is the transistor to drive the C-MOS inverter which works at 9V with
the output of PIC. The output of PIC is from 0V to 5V. This transistor converts into the voltage from 0V to
9V to control the inverter.
This transistor is used to control the 7 segment LED. PNP type is used for controlling the anode side of the
LED.
Shottky barrier
diode ( 1SS106 )
These diodes are used to
detect the received ultrasonic.
The ultrasonic frequency is about 40KHz, so, the diode
with the good high frequency characteristic is used.
7 segment LED
IC socket
PIC16F873 is 28 pins of the slim type. When you can no
get a slim-type 28 pin socket, two sockets of 14 pins can
used. In the circuit this time, I used two 14 pin sockets.
Resonator
I used B type.
Resistor
Ceramic capacitor
Electrolytic capacitor
This capacitor is used as the ripple filter
capacitor of the power circuit.
There is polarity. So, Be careful so as not to make a mistake
when mounting it.
Printed board
I used the universal board with the 25 x 30 holes.
Wiring terminal
This terminal is used to connect power supply wire and wire for the variable
resistor for display proofreading.
Stud
This range meter detects a reflected wave from the object after sending out a ultrasonic pulse.
By measuring the time which returns after emitting a sound wave, a distance to the object is measured.
Label definition
;**************** Label Definition ********************
cblock h'20'
s_count ;Send-out pulse count adr
endc
I used CBLOCK directive for the definition of the workarea.
When using this directive, workareas which were defined between CBLOCK and ENDC are
automatically allocated in the order from the address which was specified by the operand of
CBLOCK. It is convenient because it is possible to prevent the double allocation of the area.
To confirm an allocated address, you confirm it by the assembly result.
The 11th is used for the interruption error display. It is for the debugging.
Initialization process
;**************** Initial Process *********************
Port initialization
Because the RA0/AN0 port is used for input of A/D converter, it is set to input mode.
Other A ports are set to the output. All B ports are set to output because it is used for
the LED segment control.
RC2/CCP1 of C port is set to the input mode because it is used for input of capture.
Interruption initialization
It makes timer0 interruption, peripheral device interruption, global interruption
possible.
The interruption of the capture and timer2 doesn't occur when not making peripheral
device interruption possible.
By this process, interruption operation is started.
When the initialization process ends, the interruption is waited for. It executes same address
repeatedly.
Interruption process
;*************** Interruption Process *****************
Capture interruption, timer2 interruption, timer0 interruption are checked. The kind of the
interruption is judged by each interruption flag. After that, it jumps to the corresponding
interruption process.
When the kind of the interruption is unsettled, processing is stopped. To confirm illegal
interruption with the actual circuit, an in-circuit simulator is needed. There is a way of
resetting but it isn't improved because it does the same operation even if it resets.
A global interruption enable bit (the GIE bit) is automatically cleared when the interruption
occurs. So, the interruption never occurs while processing in the interruption.
Actually, it doesn't work as assumed first when assembling a circuit and confirming operation.
I will explain the items which were improved including the point which wasn't normally worked when
making this circuit below.
RA4 port
At first, the control of the reception pulse detector(start/stop) was controlled by RA4 port.
The RA4 port is a special port in the PIC16F series and I have made same mistakes before.
The output of the RA4 port is an open type. So, when setting RA4 port to the H level
condition, it is only separated from the grounding and it doesn't become H level. To make RA4
H level, the pull-up resistor must be put outside.
Because mounting space of the printed board was limited at this circuit, I changed to use RA5
port.
Grounding
This circuit handles the analog signal of 40KHz. The level of the analog signal changes subtly
by the circuit wiring. For this circuit, the wiring by the printed board considered grounding is
better.
When installing this circuit in the acrylic case, it should install a circuit onto the brass board as
the ground board.
Adjustment of the transmission frequency
40KHz for the ultrasonic is generating by the software. The resonant frequency of the
transmission sonar is 40KHz. The transmission frequency must be adjusted to the resonant
frequency. The transmission efficiency declines when not fitting. The adjustment of the
frequency is done by the number of the steps of the software. It adjusts ON/OFF equally.
Connect a simple level meter with the node of D1 and D2 and adjust soft steps for a level to be
maximized. It is necessary to do while rewriting software using programmer. The equipment
and the reflection board must be fixed to compare in the same environment. It isn't possible to
compare when the reflected quantity has changed. This is a little bit hard work.
Detection operation
confirmation
The photograph on the left is the one
to have observed the signal when
measuring a 2.36m distance.
Observation points are shown below.
(1) is 1st pin of IC1 ( It is a signal
after the amplification with the
operational amplifier. )
(2) is 8th pin of IC3 ( It is a detection
holding circuit gate signal by PIC. )
(3) is 11th pin of IC3 ( It is an output
signal of the detection holding circuit.
)
When (2) is an L level, the detector stops. You can find that a malfunction by the transmission pulse is
prevented. The prevention time of this circuit is about 1.5 milliseconds. There is possibility to
malfunction when short any more.
Some feeble reflection signals are received until it detects a reception pulse. Because the threshold
voltage of the signal detector of IC2 is working effectively, those feeble signals are not detected.
The signal of (3) changes to H level from L level when detecting a reception pulse. This signal is
detected by the capture feature of PIC and the propagation time of the ultrasonic is measured.
Measuring range
The ultrasonic transmission time of this Meter is 0.5 milliseconds. So, it isn't possible to do
long-range measurement.
Most short : 29 cm
distance This distance is decided by the time to prevent from an influence by
the transmission pulse.
When measuring a long distance, the sending-out time of the
transmission pulse must be expanded. In this case, it is necessary to
expand in the prevention time, too, and the shortest measurement
distance becomes long.
Most long distance : 3.6 m
This distance is decided by the length of the transmission pulse. The
ultrasonic energy becomes big when the transmission time is long
and the long-range measurement is possible. However, as the
explaining at the most short distance, the shortest measurement
distance becomes long.
Dial Temperature
Display
condition for displaying 1.00
Full turn
to right 0.98 8.6°C
Full turn
to left 1.11 83.0°C
When doing this confirmation, I found the opposite connection of the calibration resistor. The
connection in the center is right but the connection in the both edges is opposite. I intended to turn to
the right when the ambient temperature was high. However, the actual operation is opposite. Because it
is not in the problem in case of practical use, I don't change it. A schematic and a pattern drawing are
corrected.