Académique Documents
Professionnel Documents
Culture Documents
Contents
1 Introduction
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
5
5
8
9
9
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
11
11
11
14
14
15
15
16
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4 Measurements
18
5 Future Work
20
6 Conclusion
21
22
B PHP Code
25
Introduction
The programmable state-variable filter is the first part of a internet laboratory, also known as a
weblab, for 6.302 (Feedback Systems). The weblab allows students access to real systems through
the web much like the one used for 6.012 (Microelectronic Devices). The weblab allows students to
perform experiments from their computer and eliminates the need to go to lab.
The types of experiments that are performed are frequency responses. To fully understand
the filter responses, these measurements must be made while changing filter characteristics such
as natural frequencies and damping ratio/quality factor. The natural frequencies determine the
bandwith of the filter and the damping ratio/quality factor determine how much peaking occurs
at the corner frequency. In order to change these filter characteristics from a remote terminal, the
circuit representation of the filter needs to be adjusted by the server to which it is connected.
In order for the remote terminal to interface with the server, it must communicate with the server
through a scripting language. The server chosen for this project is the Apache Webserver, which is
a free open source server that is easily configurable and extendable. The scripting language used
is the PHP scripting language, another open-source product. It is used because Apache supports
it and it has a powerful set a functions to create almost any type of application. One of those
applications is the full control of the servers RS232 serial port which will be used in this project
to both send data to the circuit and to receive data from the circuit.
The overall weblab system consists of the PC/Server controlled by the remote client through the
PHP scripting language, a level shifter, a microcontroller to interpret the server signals and set
filter characteristics, and the filter itself. A system level block diagram of the weblab system is
shown in Figure 1. The DACs are latch free, so as long as the DAC select bits are set at the same
time as the data bits, they will work correctly. This is great for testing the DACs since there are
no timing issues associated with writing to the DACs.
The level shifter changes RS232 logic (+12 and 12 volts) from the server to TTL logic (+5 and
0 volts) which can be interpreted by the PIC microcontroller. The microcontroller uses the signals
from the server to determine the values to be sent to each digital to analog converter (DAC) over 8
bits of data. The PIC processor has two input/output ports known as PORTA and PORTB, both
8 bits wide. PORTA is used to DAC selection and PORTB is used to transfer the data.
DAC Select
PC/Server
DAC
n1
Vin
4
Level
Shifter
DAC
PIC
n2
8-bit bus
DAC
Voltage
Control
Filter
2
2.1
A very useful filter for teaching any signals class is the state-variable filter. The state-variable
filters topology is such that depending on where the output of the filter is read, a low-pass, bandpass, or high-pass characteristic can be realized. This unique characteristic comes from the filters
implementation using only integrators and gain blocks. A block diagram of the state-variable filter
is shown in Figure 2.
Vi
Vohp
n1
s
Vobp
n2
s
Volp
The three outputs of the filter are shown in Figure 2 as V olp , Vobp , and Vohp corresponding to
the low-pass, band-pass and high-pass filters respectively. Utilizing Blacks formula, the system
function for each filter is as follows:
Volp
n1 n2
(s) = 2
Vi
s + 2n1 s + n1 n2
(1)
Vobp
n1 s
(s) = 2
Vi
s + 2n1 s + n1 n2
(2)
Vohp
s2
(s) = 2
Vi
s + 2n1 s + n1 n2
(3)
s = j
(4)
It is the placement of the integrators in the signal path that determine the filters responses. The
low-pass filter has both integrators in the forward path. The band-pass filter has one integrator in
the forward path and one in the feedback path. And the high-pass filter has both integrators in
the feedback path.
2.2
Integrator Blocks
The most important part of the state-variable filter is the integrator. And in order to build a
programmable filter, the gain of the integrator needs to be adjustable. An adjustable integrator
can be implemented as shown in Figure 3 with the use of a transconductance amplifier, a capacitor
and an operational amplifier.
5
C
Ib
Vi
G
M
Vo
+
GM
Vo
(s) =
Vi
Cs
(5)
which is exactly what is needed. When this block is used as part of the overall filter, the natural
frequency (n ) is:
GM
n =
(6)
C
This natural frequency can be adjusted by changing the bias current I b . The bias current is related
to the transconductance GM by some constant factor k. The value of this constant was measured
using the circuit in Figure 4 using two sets of R B and RL to simulate current levels used to set n
and . The experiment was performed as follows:
Table 1: Experiment to determine value of k
1.
2.
3.
4.
5.
The natural frequencys bias current level is in the millamp range, from 0 to 0.5mA. The damping
ratios bias current level is in the microamp range, from 0 to 2.3A. The results of the experiment
are presented in two graphs, Figure 5 for the natural frequencies and Figure 6 for the damping
ratio. The equations that define the relationships between the the gain A v , the transconductance
GM and bias current Ib are:
GM = I b k
(7)
Av = G M RL
(8)
Using the values of the constants kn and k determined from experiment, the state-variable filter
was designed to meet the ranges of n and required, which are discussed in the implementation
section for the state-variable filter.
6
+5V
RB
+5V
+
Ib
+
Vid
Vo
G
M
RL
Transconductance Gm (Mhos)
0.008
0.006
0.004
0.002
0
0
0.0001
0.0002
0.0003
0.0004
0.0005
The use of a lead compensator can correct negative phase shifts by adding positive phase margin to the system.
Transconductance Gm (Mhos)
2.5e05
2e05
1.5e05
1e05
5e06
0
0
5e07
1e06
1.5e06
2e06
2.5e06
2.3
Low-Pass Function
n2
s2 + 2n s + n2
(9)
The low-pass filter contains two poles, and therefore it has a roll-off of 40dB/decade. Depending on
the relative locations of the two poles, peaking can occur. If the gain is high enough or in this case,
if the natural frequencies are high enough, complex poles result and peaking occurs. A bode plot
of the filters frequency response with changing damping ratio/quality factor is shown in Figure 7.
20
Increasing
zeta
Magnitude (dB)
0
20
40
60
80
100
0
Phase (deg)
45
90
135
180
1
10
10
10
10
n
2
s2 +2n s+n
10
with varying
The low-pass filter does just that, it lets low frequencies pass and attenuates frequencies higher
than its corner frequency. The corner frequency ( n ), where n = n1 = n2 in this bode plot is
10 radians per second (krad/s), therefore, frequencies higher than 10 rad/s are attenuated.
2.4
Band-Pass Function
s2
n s
+ 2n s + n2
(10)
The band-pass filter exhibits the peaking seen in the frequency response of the low-pass filter. This
characteristic comes from the fact that the filters have the same closed loop poles.
The band-pass filters frequency response explains what it does. The band-pass filter lets a band
of frequencies around its natural frequency, n = n1 = n2 is 10 rad/s in this case to pass,
and attenuates frequencies much higher or much lower than the pass band. The band-pass filters
frequency response is shown in Figure 8.
10
Increasing
zeta
Magnitude (dB)
0
10
20
30
40
50
60
90
Phase (deg)
45
45
90
1
10
2.5
10
10
10
n s
2
s2 +2n s+n
10
with varying
High-Pass Function
s2
s2 + 2n s + n2
(11)
The high-pass filter exhibits the peaking seen in the frequency response of the low-pass and the
band-pass filters due to the fact that it too has the same closed loop poles. The band-pass filters
frequency response is shown in Figure 9. This filter lets high frequencies, those higher than its
9
20
0
Increasing
zeta
Magnitude (dB)
20
40
60
80
100
120
180
Phase (deg)
135
90
45
0
1
10
10
10
10
s2
2
s2 +2n s+n
10
with varying
natural frequency, n = n1 = n2 in this case, also 10 rad/s to pass and attenuates all other
frequencies.
10
3.1
3.1.1
Hardware
Filter
Moving from the state-variable filter theory, the circuit implementation of the filter can be
synthesized using common analog building blocks such as: integrators, gain blocks, adders and
subtractors. The circuit implementation is appended as Figure 26.
From some hand analysis, a block diagram can be developed showing exactly how the circuit
implementation is related to the block diagram shown in Figure 2. Kirchoffs current rule at the
inverting input of U12 of Figure 26 gives:
Vi
Vohp Volp
+
+
+ Vobp GM U 23 = 0
R5
R8
R17
(12)
Assuming R5 = R17 = R8 and multiplying both sides of the equation by R 8 , and solving for Vohp ,
we get:
Vohp = (Volp + Vi + Vobp GM U 23 R8 )
(13)
which represents the first adders in Figure 2. Continuing along the signal path from V ohp to Vobp ,
we get the equation:
GM U 14
Vobp = Vohp
(14)
C7 s
which is the first integrator of the block diagram 2 . Immediately apparent from this block is the
value of n1 , which is:
GM U 14
.
(15)
n1 =
C7
The next block that is easily recognized is the feedback block from V obp to the adder, which represents the value of 2. From this circuit, we see that this value translates into:
2 = GM U 23 R8 .
(16)
Continuing in the signal path from V obp to Volp we encounter another integrator of the form:
Volp = Vobp
GM U 6
C1 s
(17)
GM U 6
.
C1
(18)
The last part of the block diagram synthesis is the feedback path from V olp to the adder, which we
already got from equation 13 which turns out to be unity because of the equal resistor assumption.
11
Vi
Vohp
GMU14
C7 s
Vobp
GMU6
C1 s
Volp
GMU23 R8
(20)
(21)
n2 =
2 =
The the last 3 equations were used to determine values for resistors and capacitors based on desired
ranges of n1 , n2 , and . The desired range of both n1 and n2 is 0 to 62.832 krad/s which
corresponds to 10kHz. The desired range for is from 0 to 2. Using the standard capacitor value
of 68nF, Vref max of 5 volts, and VBE of 0.6 volts, the desired value for R 6 and R7 is 15 k, and
the desired value for R18 is 3.2 M .
To understand where these equations originate, it is important to take a look at the circuit in
Figure 11. This circuit is used to set the bias current for each transconductance amplifier pertaining
to each system variable, i.e. n1 , n2 and . To see how the output bias current I o is related to
the reference voltage Vref , a feedback block diagram of this circuit is analyzed. The block diagram
is shown in Figure 12.
The circuit in Figure 11 works through the use of two feedback loops to create a bias current
dependent only on the resistor Re and the reference voltage Vref . There is a major and minor
feedback loop in this circuit. The minor loop is provided by the emitter follower circuit and the
2
Note, this integrator has a noninverting topology since it is the noninverting pin of the transconductance amplifier
that is grounded as opposed to the inverting pin.
12
Vdd
Re
Ve
Vref
Vb
Io
Io
1+gmRe
=
e
Vref
1 + A(s)gmR
1+gmRe
Vref
+
_
Ve
(22)
Vb +
A(s)
Io
gm
_
Ve
Re
Re
Figure 12: Block Diagram for Bias Current Setting Circuit
The variables A(s), and gm represent the frequency-dependent gain of the operational amplifier,
and the transconductance of the bipolar junction transistor respectively. Assuming V ref is changing
slowly, the gain of the operational amplifier is at DC is 10 5 according to the TL082 datasheet and
it is assumed that:
A(s)gmRe 1 + gmRe
(23)
and the relationship between Vref and Io simplifies to:
Io
1
Vref
Re
13
(24)
and therefore:
Io
Vref
Re
(25)
One minor detail omitted when creating the block diagram of Figure 12 is that V dd has an effect
on the bias current. Vdd is assumed to be a small signal ground, and therefore omitted in the block
diagram but the large signal bias current is dependent on this value and therefore the equation
that relates Vref and Io is more correctly:
Io =
3.1.2
Vdd Vref
Re
(26)
DAC-Filter Interface
The bias currents that set the dynamics of the filter are set through the use of digital-to-analog
converters. Each DAC receives eight bits of data pertaining to the value of the filters characteristics,
which are set by the user. The implementation of the DAC-Filter interface is shown in Figure 25.
The data that is received by the DACs determines the reference voltages V ref 13 derived from
Equations 19-21 which are reinterpreted here as:
Vref 1 = Vdd
n1 R6 C7
k n
(27)
Vref 2 = Vdd
n1 R7 C1
k n
(28)
2R18
k R8
(29)
Vref 3 = Vdd
Future improvements on the programmable filter should use these equations in software to convert
the users inputs to eight bit values to set the reference voltages.
3.1.3
Computer-DAC Interface
In order to use the signals from the RS232 interface, they need to be converted from RS232 logic
to TTL logic. This means that the voltages need to be changed from +12 and 12 volts to 0 and
+5 volts. This can done with the use of the Maxim 233 level shifter chip. The Maxim 232 takes
RS232 logic and converts it to TTL for transmitting and vice versa for receiving. The only pins
needed in this project are the transmitted data, received data and ground. With these three
pins, a serial interface between the server and the PIC microcontoller is possible. The PIC has an
onboard USART, with a receive and a transmit pin, therefore, the only configuration needed can
be done in software.
A diagram of the interface is shown in Figure 13. The protocol for checking if the right variable
is sent is as follows. The PIC is initally set up to wait for a serially transmitted byte of data,
meaning one bit after the other, least significant bit first. There are 8 bits of data, 1 stop bit and
no parity. The processor then stores the variable and sends it back to the server. The server is then
expected to send back to the PIC a 1 if the data matches and a 0 if it does not. The PIC then
checks a counter to determine which variable was sent. The counter only updates when confirmed
14
+5V
1
2
3
4
5
Rx
Tx
5
4
PIC16F628
6
7
8
9
MAX233
Serial
Port
Data
6 9
3.2
Software
The filters software comes in two interdependent parts. The first part is the PIC microcontrollers
program which creates an interface between the signals coming from the server and the state-variable
filter itself. The second part is the PHP program which creates an interface between the remote
user and the Apache web server. The values operated on by the two parts of the software are
interdependent and therefore a handshaking mechanism is used. The mechanism is also useful
for error checking, making sure that values received by the PIC are values sent by the server. A
complete flow chart of the handshaking mechanism is shown in Figure 14.
3.2.1
In order to interpret the signals sent through the serial port by the server, a microcontroller
is used. The Microchip PIC16F628 microcontroller was used here because it is cheap, requires
few external components, has a Reduced Instruction Set (RISC) processor and has an onboard
Universal Synchronous/Asynchronous Receiver/Transmitter module (USART) for serial interfaces.
The only external components required for immediate programming of the PIC microcontroller
are: two capacitors and a crystal oscillator. These three components generate the processors clock.
A 20 MHz crystal oscillator was used in this case making the instruction cycle 200 ns (the PIC has
an internal divide by four, which makes the clock frequency actually 5 MHz).
The RISC architect means that there are few instructions needed to fully control the processor.
In this case, there are only 35 instructions.
15
Here is n1
Here is the n1 you sent,
Does it match?
Yes
Ready for n2 now (sent n1 to n1 s DAC in background)
Here is n2
Here is the n2 you sent,
Does it match?
Yes
Ready for now (sent n2 to n2 s DAC in background)
Here is
Here is the you sent,
Does it match?
No (Assuming some error occurred)
Resynchronizing
Waiting for
Here is
Here is the you sent,
Does it match?
Yes
Waiting for next 3 variables (sent to
s DAC in background)
The USART allows the processor to communicate to any other device serially. This module was
the most important part of this project because it provided a way for the system under test to
receive the instructions presented by the webserver.
The flow chart of the server/system interface is presented in Figure 14, along with the actual
implementation.
3.2.2
As stated before, in order to set the variables for the filter, control of the servers serial port is
required. The PHP scripting language has such capabilities. PHP along with its COM functions
allows the control the servers serial port running Windows. COM is a technology which allows the
reuse of code written in any language (by any language) using a standard calling convention and
hiding behind APIs the implementation details such as what machine the Component is stored on
and the executable which houses it.
The COM module that was used for this project is provided by ActivExperts from
www.activexperts.com on a trial basis and can be licensed for a fee of $150.00. Alternatives to the
COM module, is to use Apache on Linux, where PHP offers functions to directly control the serial
16
port, or write a Dynamic Linked-Library (.dll) file so that a windows based server can control the
serial port. The PHP code that makes use of this module is shown in Appendix B. The code takes
the user values entered in a form and prepares them for transmission to the webserver and to its
serial port, which is later on interpreted by the PIC processor for setting filter values. There is
a hand-shaking mechanism implemented such that PHP and the microcontroller have the same
values presented by the user.
17
Measurements
To determine if the programmable filter works as expected, step response experiments were
performed. The natural frequency, along with the damping ratio were set for each experiment
through the use of the PHP web interface and the peak overshoot (P o ) and the time to peak
(tp ) were measured. The natural frequency and the damping ratio were then determined from
the following equations and compared to the theoretical values for accuracy. For all experiments
n1 = n2 = n . In the measurement tables nt and t are the theoretical values, i.e. set by server,
while nc and c are values calculated from measured values of P o and tp . The errors are represented
by variables err and nerr . The two trends that should be visible are: the independence of P o on
n and the inverse proportionality between t p and n . If these trends are observed, the rest is just
calibration.
Po = 1 + e 1 2
p
tp =
n 1 2
(30)
(31)
nt (krad/s)
12.566
25.133
37.699
50.265
t
0.2
0.4
0.6
0.707
0.8
1.0
0.2
0.4
0.6
0.707
0.8
1.0
0.2
0.4
0.6
0.707
0.8
1.0
0.2
0.4
0.6
0.707
0.8
1.0
Po
1.53
1.51
1.19
1.11
1.17
1.07
1.54
1.51
1.19
1.11
1.17
1.07
1.54
1.51
1.19
1.11
1.17
1.07
1.54
1.51
1.19
1.11
1.17
1.07
tp (s)
282
284
259
289
237
274
155
142
123
119
122
136
85.6
89
75.5
77.6
74.5
88
62.2
64.8
57.8
55
53.2
57.8
18
c
0.198
0.210
0.467
0.575
0.491
0.650
0.192
0.210
0.467
0.575
0.491
0.650
0.192
0.210
0.467
0.575
0.491
0.650
0.192
0.210
0.467
0.575
0.491
0.650
nc (krad/s)
11.365
11.314
13.717
13.286
15.216
15.087
20.652
22.627
28.884
32.267
29.558
30.396
37.396
36.103
47.056
49.481
48.404
46.976
51.464
49.586
61.465
69.226
67.784
71.571
err (%)
-1.0
-47.5
-22.2
-18.7
-38.6
35.0
-1.0
-47.5
-22.2
-18.7
-38.6
35.0
-1.0
-47.5
-22.2
-18.7
-38.6
35.0
-1.0
-47.5
-22.2
-18.7
-38.6
35.0
nerr (%)
-9.5
-10
9.2
5.7
21.1
20.1
-17.8
-9.97
15
28.4
17.6
20.9
0.8
-4.23
24.8
31.25
28.4
24.6
2.4
-1.35
22.3
37.7
34.9
42.4
From the measurements table, it is clear that the two required trends are present, but aside
from that, the measurements seem to contain a large amount of error within the center values of .
Reasons for this could be a nonlinear G M of the transconductance amplifiers when they are used
in the overall filter, measurement errors, calibration techniques, i.e. rounding the final value to be
sent to the DAC to rid the data of leading decimals. This rounding function under PHP will round
both 4.5 and 4.99 up to 5. Another problem discovered by the author was the value of k n and
k . The values determined from the test circuit and the values observed in the circuit were not
consistent. The values were adjusted on the server side until an expected response was observed,
but then, this was not the case at all points of measurement as apparent from the low error in
both variables at = 0.2. There were no other problems other than calibration errors, because the
signals overall appeared to match the step reponses in Figures 15-17
Some of the step response signals for each output are shown in Figures 18-23. These Figures
were taken at a time when was calibrated well by n was not.
19
Future Work
Future work to be completed for the weblab project includes the construction of more systems/filters and the implementation of a graphical user interface (GUI) to control the experiments
and to gather data from those experiments. More robust calibration techiques need also to be
implemented for this specific filter, most likely could be done in the software on the server side.
Other work includes the construction of more filters/systems for experimentation. Although
a state-variable filter is a great example of a low-pass, band-pass and high-pass filter, a more
extensive set of filters are required for feedback systems. Filters that are more specific to 6.302 are
the lag, lead, and the dominant pole compensators/filters. These filters demonstrate the benefits of
feedback to achieve more desirable system dynamics than those of the open-loop or uncompensated
system.
20
Conclusion
The programmable state-variable filter is a good start to the installation of a feedback systems
weblab, but the first version is not perfect and can be improved upon. For a version 2, a PIC with
the USART on a separate port from the data port should be chosen. The PIC16F628 was chosen
because it had 2 byte sized ports, an onboard USART, and is inexpensive. The replacement should
have an onboard USART separate from the data ports, in addition to the requirements above.
The shared port of the PIC16F628 causes a 2-bit error because the receive pin is not available to
send data to the DACs since it is configured as an input for the USART. The receive pin therefore
either sits at either 5 volts or ground depending on the output from the level shifter, and cannot
be connected to any other potential. A diagram of the connections between the PIC and the level
shifter is shown in Figure 25. Since the receive pin cannot be used as an output, data bit DB1 is
connected to 5 volts in this case.
The 2 bit error might be acceptable for a first version of the filter but future filters/systems may
require higher precision for acceptable use. In its present state, the DAC is referenced to 5 volts
therefore a 2 bit error represents an error in voltage of just:
Verror =
2
5 = 0.039mV
256
(32)
21
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Author: Rayal Johnson
;
; Title: PIC16F628 Programmable State-Variable Filter
;
;
;
; Description: Programmable state-variable filter that
;
; interacts with a PHP web interface to receive, check
;
; and set values for the filters natural frequencies
;
; and the damping ratio/Quality factor.
;
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
list p=16f628,f=inhx32
#include <p16f628.inc> ;Available at microchip.com
__config 0x3FE1
PC
CNT
TEMP
equ
equ
equ
0x02
0x20
0x21
org
0x0000
;Initialize porta and portb
start
movlw
0x00
bcf
STATUS,RP0
bcf
STATUS,RP1
movwf
PORTA
movlw
0x07
movwf
CMCON
bsf STATUS,RP0
movlw
0x20
movwf
TRISA
;change to
;bank 0
;clear PORTA
;turn off comparators and
;enable pins for I/O
;bank 1
;set RA<4:0> as outputs
;TRISA<5> always 1
b00000010
;set Receive pin as input
TRISB
;all outputs except RX pin
OPTION_REG,NOT_RBPU ;enable pull-up resistors
0x81
;set baud rate to 9600
SPBRG
;assuming BRGH =1 (address 99h)
b00100100
;bit 6 clear - 8-bit transmission
;bit 5 set - enable transmission
22
movwf
bcf
movlw
TXSTA
STATUS,RP0
b10010000
movwf
RCSTA
;USART is now set up
;Programmable Filter
getvars
movlw
movwf
0x00
CNT
;set up counter
;for variables
btfss
goto
movf
movwf
movwf
PIR1,RCIF
rcvgo
RCREG,W
TEMP
TXREG
btfss
goto
bcf
movlw
andwf
btfsc
goto
movf
PIR1,RCIF
check
STATUS,Z
0x01
RCREG
STATUS,Z
rcvgo
CNT,W
addwf
goto
goto
goto
PC
sndDAC1
sndDAC2
sndDAC3
movlw
movwf
movf
movwf
movlw
b00001001
PORTA
TEMP,W
PORTB
0x01
rcvgo
check
;
;check data
;for 1 -> for Yes ->data matches
;
;data doesnt match, get rid of it
;if data matches,
;send to correct DAC
sndDAC1
23
movwf
goto
CNT
rcvgo
movlw
movwf
movf
movwf
movlw
movwf
goto
b00000110
PORTA
TEMP,W
PORTB
0x02
CNT
rcvgo
movlw
movwf
movf
movwf
movlw
movwf
goto
b00001000
PORTA
TEMP,W
PORTB
b00001010
PORTA
getvars
sndDAC2
sndDAC3
end
24
PHP Code
<html>
<head>
<title>Serial Interface Test</title>
</head>
<body>
<?php import_request_variables("p", "svf_");
$vdd_n
$vdd =
$R_6 =
$C_7 =
$k_1 =
= 5;
5;
15000;
6.8e-8;
16.92;
$R_7 = 15000;
$C_1 = 6.8e-8;
$k_2 = 16.92;
$R_8 = 200000;
$R_18 = 2.0e6;
$k_3 = 18.46;
$true = 1;
$false = 0;
$status = 1;
$s1 = round((($vdd_n - (($svf_omega1*$R_6*$C_7)/($k_1)))/($vdd))*256);
$s2 = round((($vdd_n - (($svf_omega2*$R_7*$C_1)/($k_2)))/($vdd))*256);
$sd = round((($vdd_n - (($svf_damping*2*$R_18)/($k_3*$R_8)))/($vdd))*256);
$v1 = $s1*(5/256);
$v2 = $s2*(5/256);
$v3 = $sd*(5/256);
//voltages in circuit
//used for testing
//and troubleshooting
//process form
//set comport ID, baudrate, parity,
//number of databits, stopbits, then open port
25
PortID, 1);
BaudRate, 9600);
DataBits, 8);
Stopbits, 1);
//set
//set
//set
//set
port to COM1
baud rate to 9600kbps
data bits to 8 bits
stopbits to 1
$obj->Open();
26
27
Start
Get Data from
HTML form
Convert users
to DAC values
Start PIC
Set up Ports
Set up USART
Open Serial Port
CNT = 0
$i = 0
Yes
$i = 2 ?
Wait
Close Serial Port
Serial Port
Input to
RXREG
Comment
$i = 0 -> Omega 1
$i = 1 -> Omega 2
$i = 2 -> Damping
No
Write ith data
to serial port
No
RXREG
full?
Wait
Yes
Store RXREG in
TEMP
Send TEMP to
serial port
Input TEMP
from serial
port
TEMP=ith
Value ?
Wait
Yes
Serial Port
Input to
RXREG
No
Write "0"
Write "1"
to Serial Port
to Serial Port
RXREG
full?
No
$i = $i - 1
Yes
No
Data = 1?
$i = $i + 1
Yes
1
3
CNT Value
2
Send to
Send to
Omega 1 DAC
Omega 2 DAC
Send to
Damping DAC
CNT = CNT + 1
Step Response
LowPass n = 31416 vs.
1.5
Increasing
Amplitude
0.5
= 0.25
= 0.5
= 0.75
=1
= 1.25
0
4
Time (sec)
8
4
x 10
Step Response
BandPass n = 31416 vs.
1
0.8
Increasing
Amplitude
0.6
0.4
0.2
0
= 0.25
= 0.5
= 0.75
= 1.0
=1.25
0.2
0.4
4
Time (sec)
29
8
4
x 10
Step Response
HighPass = 31416 vs.
n
0.8
0.6
Increasing
Amplitude
0.4
0.2
0.2
= 0.25
=0.5
= 0.75
= 1.0
= 1.25
0.4
0.6
4
Time (sec)
8
4
x 10
30
31
32
33
U39
5V
U42
C6
100u
VOUT
-15Vdc
3
L7805
VIN
C5
.1u
-5V
VIN
GND
15Vdc
GND
VOUT
2
C9
33u
L7905
J1
DB9F
7
8
9
1
2
3
4
5
5V
C10
U37
1u
R1IN
R2IN
R1OUT
R2OUT
3
20
2
1
T1IN
T2IN
T1OUT
T2OUT
5
18
8
13
11
15
10
16
14
12
17
C1+
C1C2+
C2+
C2C2V+
VV-
5V
U41
17
18
1
2
3
DAC A/DAC B 1
WR1
DAC A/DAC B 2
WR2
C2
16
15
15p
4
XTAL
14
MAX233
RA0
RA1
RA2
RA3
RA4/TOCKI
RB0/INT
RB1/RX
RB2/TX
RB3
RB4
RB5
OSC1/CLKIN
RB6
OSC2/CLKOUT
RB7
6
7
8
9
10
11
12
13
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
VDD
CS1
CS2
MCLR
Vss
4
19
C4
5V
34
PIC16F628
15p
Title
Programmable State Variable Filter
Size
A
Date:
5
Document Number
1
Sunday, February 08, 2004
2
Rev
1
Sheet
of
1
1
5Vdc
-5Vdc
17
VDD
VIN A
OUTA
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
6
15
16
5
2
3
AGND
20
Vref3
Vref1
2 -
19
-5Vdc
AD644
U35A
RFB A
OUTA
14
13
12
11
10
9
8
7
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
6
15
16
5
AGND
Vref2
1
3 +
VIN B
AD7528
2
3
18
VDD
U32
VIN A
CS 1
CS 2
17
5Vdc
-5Vdc
DAC A/DAC B 1
WR 1
DAC A/DAC B 2
WR2
output
bits(RA<3:0>)(wr2 d2 wr1 d1)
omega1 (Vref1) 1001
omega2 (Vref2) 0110
damping (Vref3) 1000
Vfreq
0100 -> For future use
35
AD644
U34A
18
VIN B
1
3 +
AD7528
14
13
12
11
10
9
8
7
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
AD644
U33A
RFB A
U32
D
20
2 -
19
AD644
U34A
-5Vdc
Title
Programmable State Variable Filter
Size
A
Date:
5
Document Number
1
Tuesday, February 17, 2004
2
Rev
1
Sheet
of
1
1
5Vdc
5Vdc
R6
R7
15k
-
Vref1
15k
Q2N3906
Vref2
Q1
Q2N3906
1
Q2
TL082
U19A
TL082
U20A
U15A
TL082
3 +
Vohp
2 R17
C
200k
C1
68n
3
CA3080
U14
2
3
CA3080
U6
3 +
Volp
2 LF411
U8
LF411
U7
LF411
U12
U16A
TL082
200k
6
-
U9A
TL082
+
3 +
2 -
U24A
TL082
Vref3
Vobp
Q4
3 +
2 A
CA3080
U23
Q2N3906
VCC
36
200k
68n
R8
R5
Vi
C7
Title
R18
2.0M
Size
A
Document Number
1
Rev
1
5Vdc
Date:
5
Sheet
2
of
1
1