Maker Pro
Maker Pro

Help interfacing Current Transformers to ADC

P

Paul E. Schoen

beananimal said:
[snip good heads-up about Adobe and HP]
Back to logging current via a CT hooked to an A/D

I will be ordering the specified CT for this project ASAP. In the
meantime I am going to hack a Xformer off of a modem or something in
an
attempt to breadboard the project to garner a better understanding of
the circuit in a working state.

Question: Is it feasable to use a small pot in place of the resistor
that grounds the Rectifier (or a pot and Resistor in parallel for
safety). In my mind that would allow fine tuning of the CTs output
scale to match the A/Ds full scale voltage.
Your latest schematic cmon2.jpg has some errors, and is also way more
complex than needed. Also, I don't think you need to worry too much
about
these little CTs bursting into flame or exploding if the secondary is
open
circuited, but it is always wise to use precautions. A true current
source
would generate an output voltage high enough to arc across the terminals
or
break down internal insulation, but these small CTs will just saturate
and
put out at most maybe a hundred volts. If there are high frequency
components involved, it could be much higher, however.

I'll try to draw a suggested simple schematic that should work:

+-----+
AC-----)|(----|~ +|--+---R2---+----+----AD1
)|( | | | | |
)|( | BR1 | R1 C1 Z1
)|( | | | | |
AC-----)|(----|~ -|--+--------+----+----GND
T1 +-----+

I would suggest R1 about 200 ohms to get about 3 VDC at 10 AAC input. R2
can be about 10K, C1 about 5 uF, and Z1 a 4.7 V zener. You could put a
pot
across R1 to make it adjustable, but you can also do that in software.

For best accuracy, however, I still suggest doing the rectification with
an
absolute value routine in software, and eliminate the bridge rectifier.
Here's that circuit:
+----R3----> Vcc
|
AC-----)|(-----+---R2---+----+----AD1
)|( | | |
)|( R1 C1 Z1
)|( | | |
AC-----)|(-----+--------+----+----GND
T1

R1 should be about 150 ohms to get about 4 volts P-P at 10 amps input.
R2
and R3 should be about 2K, and C1 should be about 0.1 uF. The input to
AD1
will be just about 2.5 VDC with an AC signal varying from about 1 V to 4
V,
which is easily sampled by the A/D at about 300/sec. This should be done
in
an interrupt service routine (ISR) using a microcontroller's
programmable
resettable timer (PRT). You should read, accumulate and store the A/D at
the start of the routine, and then start the next conversion. When you
have
accumulated a certain number of readings, send it out the serial port or
whatever you will use to display it.

Breadboard the above circuits and measure values to fine tune the
resistors
and capacitors for best results, and to become familiar with how this
works. Use a scope for better visualization. You can worry about the
details of the A/D later.

Paul

1) The latest schematic was cmon3.jpg. I had hoped to fix the errors
in cmon2.jpg.
Here is the URL http://tinyurl.com/znjvc

Can you please comment on this (cmon3.jpg)
(1) The inverting op-amp may not work well at ground reference with single
supply. It will also not be able to output more than about 4 VDC, and the
emitter follower, besides being unnecessary, limits output to a little over
3 volts.

(2) The total of 2K ohm impedance into the A/D, with no capacitor, may pose
some problems when sampling occurs. If you must use an op-amp, feed the A/D
directly from the output for lowest impedance. The supply for the op-amp
should be at least 8 VDC to get a full 0-5 VDC output.

(3) The 10 ohm burden resistor will give 100 mV with 10 amps on the 1000:1
CT secondary. You need to boost that to about 4 volts for the A/D, so a
gain of about 40 is required. If R1=100, R2 should be 4K. You can replace
R2 with a 5k pot for adjustment.


2) With regards to being more complex than needed. I do understand
that there are many ways to skin a cat. Can you please explain your
reasoning and the pros and cons of your proposed schematic vs the one
Jim and John have helped me construct? I have (24) of these to build.

I don't mind more complex if there is a compeling reason or enhanced
functionality.
The main advantages of an op-amp circuit are being able to use a smaller
burden resistor to improve linearity, providing lower impedance to the A/D,
and being able to use active filtering. The bridge rectifier already
trashes the linearity, R3 and R4 adds impedance, and the active filter is
only single pole.
3) I would rather use as little sofware as possible. I am not AT ALL
versed in uC programming so just bit banging the A/D sample to the
serial port will be hard enough. I had planned on simply using a
service loop to sample the A/D ports in sequence and average every so
many. ISR and other complex uC work is again something I am not ready
to tackle. I am VERY new to uC coding. I would not know how to begin
using software to write an ABS routine to calculate the voltage in VB,
let alone doing it in uC speak.
Once you have a good reliable analog circuit that you can analyze and
understand, your physical design is done, and simple is generally better,
unless there is a strong reason for added components, and full
understanding of their purpose.

The PIC programming is really not that hard, and the more knowledge you
acquire the better. As a programmer, the concepts should not be difficult,
although you may be more in tune with object oriented events driven
software, rather than low level concepts such as ISRs and real time
considerations, where a few microseconds can make a huge difference. I can
send you some PIC code that will set up the PRT to make A/D samples at a
useful rate, for one channel, and also perform the necessary accumulation
and comparisons if you want to add a relay or LED output for an alarm. The
code I would provide would be for a PIC12F675, which is a little 8 pin IC
with an A/D. It is the same IC that is used in the Microchip PICKIT-2
evaluation kit, which has all you need to breadboard your circuit and
program the PIC, for about $30. You can then migrate to a more powerful
micro with more A/D and also a serial port or other features. I personally
like the PIC18F242 or the newer 18F2420, and I can help provide coding for
that. (It also can be used with a C compiler). There may be a PIC better
suited to your particular application, and they can be obtained as free
samples from the www.Microchip.com website, along with all kinds of app
notes and reference designs. Fear not the mighty PIC!
The goal at this point is to use (3) PIC uC to do 8 A/D inputs each.
The PICs will either all be tied to another PIC that is tied to the PC,
or simply tied to (3) serial ports on the PC. I have a spare DIGI
serial board around here somewhere.

Lastly, regarding hte POT and wiper current. What size wattage
resistors and pot need to be considered for the burden and R1 and R2?
I understand the rest of them can be standard 1/4 watt types.

All resistors and pots can be 1/4 to 1/2 watt. You are looking at no more
than 50 mA and 5 volts for all the components combined. If you use a pot,
it is best to use the wiper to tap off to the low current measurement
circuit. If you use it as a variable resistor (rheostat), tie the wiper arm
to one end so the circuit will never be open as the wiper slides on the
element.

Good luck,

Paul
 
J

John Popelish

John said:
Caution: most pots will tolerate only small wiper currents.

And yes, Adobe products are flakey garbage.
Yes. There are several ways to connect a trim pot to this amplifier
without having a significant fraction of the CT current passing
through the wiper. For instance, you can connect a pot between the
input resistor and the feedback resistor and connect the wiper to the
- input. This keeps almost all current out of the wiper.
 
J

John Popelish

beananimal said:
1) The latest schematic was cmon3.jpg. I had hoped to fix the errors
in cmon2.jpg.
Here is the URL http://tinyurl.com/znjvc

Can you please comment on this (cmon3.jpg)

Move D3 to parallel R6.
2) With regards to being more complex than needed. I do understand
that there are many ways to skin a cat. Can you please explain your
reasoning and the pros and cons of your proposed schematic vs the one
Jim and John have helped me construct? I have (24) of these to build.

I don't mind more complex if there is a compeling reason or enhanced
functionality.

3) I would rather use as little sofware as possible. I am not AT ALL
versed in uC programming so just bit banging the A/D sample to the
serial port will be hard enough. I had planned on simply using a
service loop to sample the A/D ports in sequence and average every so
many. ISR and other complex uC work is again something I am not ready
to tackle. I am VERY new to uC coding. I would not know how to begin
using software to write an ABS routine to calculate the voltage in VB,
let alone doing it in uC speak.

The goal at this point is to use (3) PIC uC to do 8 A/D inputs each.
The PICs will either all be tied to another PIC that is tied to the PC,
or simply tied to (3) serial ports on the PC. I have a spare DIGI
serial board around here somewhere.

Lastly, regarding hte POT and wiper current. What size wattage
resistors and pot need to be considered for the burden and R1 and R2?
I understand the rest of them can be standard 1/4 watt types.

You might add a 100 ohm pot element between R1 and R2, and connect the
wiper to the - input. This keeps all current out of the wiper and
allows a 2 to 1 change in the full scale output per amp AC. You can
change the value of R2 for larger changes, or to center this adjustment.

R6 absorbs almost all the power from the CT, but its low resistance
keeps its power low. Figure I^2/R. So at 30 mA secondary current,
the power is only .03^2*10=9 mW. R1 has the same voltage drop with
only 1/10th the current, so its power is much lower. R2 has the same
current as R1, but 5 volts across it at full scale current, so it
dumps a something near .003A*5V=15 mW. I would use 1/4W 1% resistors
because they are cheap and stable.

This new circuit with the external burden across the bridge, makes the
source no longer a current source to the opamp, but a 10 ohm source.
Now the ratio of R1 and R2 program the opamp to act as a voltage
amplifier for the voltage across R6. This means that R2 will need to
larger, to get the required output voltage.

For instance, if the CT has a ratio of 1000:1, and the primary current
is 10 amps, the output current will be 10 mA. That passes through the
parallel combination of R1 and R6, or 9.09 ohms, and will produce a
..0909 volt drop across R6 and R1. But the current passing through R21
will be only .0909/100 = 909 uA.

That current will also pass through R2, producing the desired output
voltage. To make that output 5 volts, R2 must be 5.909uA =5.5k.

This was the desired effect of adding R6. It lowers the current load
on the opamp output stage.

If you are not sure, exactly what full scale current ranges you will
finally choose, get an assortment of R2 values that cover the possible
range in something like 40% steps. This will allow the adjustment pot
to cover the entire range with steps in R2.
 
J

John Popelish

beananimal said:
1) The latest schematic was cmon3.jpg. I had hoped to fix the errors
in cmon2.jpg.
Here is the URL http://tinyurl.com/znjvc

Can you please comment on this (cmon3.jpg)

Forgot to add:
Once you put a current divider as a burden (add R6), reducing the
current the opamp output must carry through R2, you no longer need the
emitter follower current booster at the output.
 
J

Joerg

Hello John,
I do something similar to design digital filters, although pretty much
devoid of theory: I design an opamp-based analog filter, then "model"
it in uP code or in an FPGA. It seems to be not only easy to design,
it's usually is easier to code, in that the internal scalers seem to
be less outrageous than the factors you get when you use more
conventional IIR DSP filter design techniques.

That is an interesting method. Got to try that some time but now I am
going to be busy with a wireless project for a little.
.SBTTL . ANALOG LOWPASS FILTERS


; INPUT SAMPLES ARE TAKEN AT THE 139-HZ RATE AND SOFTWARE LOWPASS
; FILTERED. THE FILTER IS A 4-POLE, STATE-VARIABLE (INTEGRATOR-BASED)
; SORTA GAUSSIAN GADGET WITH A 'TRANSITIONAL' (EG, HOMEBREW) TRANSFER
; FUNCTION.


NODE 1 NODE 2 NODE 3 NODE 4
| | | |
IN --(+)-[K1:INT]--(+)--[K2:INT]->-(+)-[K3:INT]--(+)-[K4:INT]-->--OUT
| | | | | |
| | | | | |
| ^---(-1)--- | | ^---(-1)--- |
| | | |
| | | |
'------<----(-1)----------' '-------<------(-1)-------'


; THE FOUR LOWPASS FILTER INTEGRATION COEFFICIENTS ARE ALL EXPRESSED
; AS RIGHT-SHIFT COUNTS, AVOIDING POKEY MULTIPLIES.

; CAUTIONS: EVEN IF ALL INPUTS ARE POSITIVE NUMBERS, OCCASIONAL
; SLIGHTLY-NEGATIVE OUTPUT GLITCHES ARE POSSIBLE.

; BIG SAMPLE-TO-SAMPLE EXCURSIONS CAN CAUSE WILD END-AROUNDS, SO
; IT'S PRUDENT TO KEEP INPUT RANGE BELOW +- 0.25 FRACTIONAL.

; OK, HERE'S THE FILTER. WE USE REGISTERS D0-D6, AND ASSUME
; THAT A0 AIMS INTO A 4-NODE FILTER BLOCK.

; ON ENTRY, D0.L SHOULD HOLD THE FRESH FILTER INPUT.

; FOR SLOW ITEMS, WE USE A FILTER WITH RISETIME OF ABOUT 2 SECONDS,
; CORRESPONDING TO BANDWIDTH OF ABOUT 0.17 HZ. CONSTANTS ARE...

K1 = 7 ; 0.0078125
K2 = 5 ; 0.03125
K3 = 6 ; 0.015625
K4 = 5 ; 0.03125

Those coeffs are a bit on the small side. That is what I try to avoid. I
like them to be above 0.05 to maintain dynamic range but that will cost
extra stages.

Didn't quote the code but it made me curious: Which processor are you
using? Mine usually don't have a HW multiplier and the right and left
shift has to be done one step at a time. Looks like yours have a barrel
shifter.
 
J

John Perry

beananimal said:
...
1) The latest schematic was cmon3.jpg. I had hoped to fix the errors
in cmon2.jpg.
Here is the URL http://tinyurl.com/znjvc

Can you please comment on this (cmon3.jpg)

2) With regards to being more complex than needed. I do understand
that there are many ways to skin a cat. Can you please explain your
reasoning and the pros and cons of your proposed schematic vs the one
Jim and John have helped me construct? I have (24) of these to build.

I don't mind more complex if there is a compeling reason or enhanced
functionality.

OK, I'll jump in on this.

As John Popelish pointed out, you no longer need the transistor
_if_you_have_high_resistance_ in your feedback network. You changed my
25K to 250R, doing two bad things: 1) you kept a low feedback
resistance, and 2) you have much too low gain (2.5X).

1) The low resistance will make the load on the op amp marginal at best.
If you keep the low resistance, you should keep the transistor, but
there's no reason at all to have such low resistance, therefore no
reason to have the transistor.

2) The point of going to a 10R burden was to lower the burden voltage on
the CT. But this means that the 20A full scale you mentioned earlier
will give a full scale voltage across your burden of 200mv. 2.5 X 0.2 =
0.5V full scale out of your op amp. Using the correct 2.5K feedback
resistor will get your 5V full scale, _and_ lower the current output
from the op amp so that you don't need the transistor any more.

Oh, it also means the ripple will be even worse than Jim showed my
circuit to have (the much lower RC time constant).

You still have an LM324 op amp, which
1) has rather high offset voltage 2mv -- 5mv
2) can't get within 1.5V of Vcc,

1) 2mv doesn't sound like much at the full scale 200mv, but suppose you
have a lightly loaded motor that draws only 2A?

2) The Vcc - 15.V meands you still need the micro protection diodes,
since you'll have to have at least 7.2V for the op amp supply. Remember
my comment that 5V supply and rail-to-rail outputs avoid a lot of
problems?
3) I would rather use as little sofware as possible. I am not AT ALL
versed in uC programming so just bit banging the A/D sample to the
serial port will be hard enough. I had planned on simply using a
service loop to sample the A/D ports in sequence and average every so
many. ISR and other complex uC work is again something I am not ready
to tackle. I am VERY new to uC coding. I would not know how to begin
using software to write an ABS routine to calculate the voltage in VB,
let alone doing it in uC speak.

Understandable. I'm not happy about your learning assembly language on
a weird monster like the PIC, but ...
The goal at this point is to use (3) PIC uC to do 8 A/D inputs each.
The PICs will either all be tied to another PIC that is tied to the PC,
or simply tied to (3) serial ports on the PC. I have a spare DIGI
serial board around here somewhere.

So you want to have a signal conditioner per CT. This explains your
reluctance to use the AD8551 -- this, and the fact that the 8551 is not
available in DIP, which I recall your having expressed a preference for
in an early post. So, we need to find a 5V supply, rail-to-rail I/O,
low offset op amp that won't cost an arm and a leg, and is easy to
solder to a board.

I'll do some looking -- it's 0300, and I'm quitting for the night. If I
don't see any good candidates when I next read the group, I'll do a
search and come up with something for you. There are quite a few out
there, but they're not the old jellybean types, so you have to look
carefully both at the data sheet and at the vendor.
Lastly, regarding hte POT and wiper current. What size wattage
resistors and pot need to be considered for the burden and R1 and R2?
I understand the rest of them can be standard 1/4 watt types.

Assuming your 20A full scale, the burden will dissipate

0.2V X 0.2V / 10R = .004W

I don't think you can find a resistor that won't dissipate that
comfortably. Everything else dissipates even lower current, so you
don't have any problems there.
 
B

beananimal

(1) The inverting op-amp may not work well at ground reference with single
supply. It will also not be able to output more than about 4 VDC, and the
emitter follower, besides being unnecessary, limits output to a little over
3 volts.

(2) The total of 2K ohm impedance into the A/D, with no capacitor, may pose
some problems when sampling occurs. If you must use an op-amp, feed the A/D
directly from the output for lowest impedance. The supply for the op-amp
should be at least 8 VDC to get a full 0-5 VDC output.

(3) The 10 ohm burden resistor will give 100 mV with 10 amps on the 1000:1
CT secondary. You need to boost that to about 4 volts for the A/D, so a
gain of about 40 is required. If R1=100, R2 should be 4K. You can replace
R2 with a 5k pot for adjustment.



The main advantages of an op-amp circuit are being able to use a smaller
burden resistor to improve linearity, providing lower impedance to the A/D,
and being able to use active filtering. The bridge rectifier already
trashes the linearity, R3 and R4 adds impedance, and the active filter is
only single pole.

At this point I would like to explore building both YOUR proposed
circuit, and the one that Jim and the Johns are helping me with. I
feel that this will give me a much better feel for what is going on,
after all I am in no big hurry and this is as much about learning as it
is about building a useable project.
The PIC programming is really not that hard, and the more knowledge you
acquire the better. As a programmer, the concepts should not be difficult,
although you may be more in tune with object oriented events driven
software, rather than low level concepts such as ISRs and real time
considerations, where a few microseconds can make a huge difference.

Yes I am an OOP guy for the most part. I code in VB and have done so
for a long time. I have worked very little with inline code and
realtime apps. Though I was a good assembly programmer, it was 15
years ago and I learned on a VAX using VMS. The only thing left is a
scant memory of machine code programming. I also have COBOL nightmares
once in a while. As with most everything I do, I am for the most part
self taught (though the C++, Assembly and COBOL were taken in college
as a Comp Sci student... sadly the profs new less than the students in
most cases).
I can
send you some PIC code that will set up the PRT to make A/D samples at a
useful rate, for one channel, and also perform the necessary accumulation
and comparisons if you want to add a relay or LED output for an alarm. The
code I would provide would be for a PIC12F675, which is a little 8 pin IC
with an A/D. It is the same IC that is used in the Microchip PICKIT-2
evaluation kit, which has all you need to breadboard your circuit and
program the PIC, for about $30. You can then migrate to a more powerful
micro with more A/D and also a serial port or other features. I personally
like the PIC18F242 or the newer 18F2420, and I can help provide coding for
that. (It also can be used with a C compiler). There may be a PIC better
suited to your particular application, and they can be obtained as free
samples from the www.Microchip.com website, along with all kinds of app
notes and reference designs. Fear not the mighty PIC!

I have great plans to learn uC stuff, but sadly would like to use BASIC
(either PICBASIC or BASCOM-AVR). I suppose I need to learn the PIC,
but have become greatly interested in the ATMEGA128.

Looking at the Microchip website the PIC16F785 seems to be very well
suited to the task at hand.

So yes Paul, I would love to have some help writing code to support
your proposed circuit for this project. As I mentioned, it would be
nice if we could do this in PICBASIC so that I can follow along more
easily. I suppose you will make a good arguement for using C or even
Assembly though!
 
B

beananimal

John said:
You still have an LM324 op amp, which
1) has rather high offset voltage 2mv -- 5mv
2) can't get within 1.5V of Vcc,
1) 2mv doesn't sound like much at the full scale 200mv, but suppose you
have a lightly loaded motor that draws only 2A?


Yes I now understand that the offset in conjunction with the somewhat
poor linearity and overall accuracy will be poor at low primary
currents. I am open to other ApAmp considerations to help reign in
some of this error.
2) The Vcc - 15.V meands you still need the micro protection diodes,
since you'll have to have at least 7.2V for the op amp supply. Remember
my comment that 5V supply and rail-to-rail outputs avoid a lot of
problems?

I can supply the filters with whatever is best suited to reach the
desired goal here, that includes changing to +/- supplied filter if
need be.
Understandable. I'm not happy about your learning assembly language on
a weird monster like the PIC, but ...
As I mentioned in my reply to Paul, I would much rather use PICBASIC
to get started with PIC programming. Maybe that is a backwards idea
and will prevent me from leaving the VB mindset.... This is certainly
something to think about, but the added complexity gives me a headache!
Nothing like having to build a set of jigs to build a machine tool,
just to build a better set of jigs to build a better machine tool!

So you want to have a signal conditioner per CT. This explains your
reluctance to use the AD8551 -- this, and the fact that the 8551 is not
available in DIP, which I recall your having expressed a preference for
in an early post. So, we need to find a 5V supply, rail-to-rail I/O,
low offset op amp that won't cost an arm and a leg, and is easy to
solder to a board.

Yes DIP would make my life much easier, but I am aware that as time
passes DIP is becoming rather outdated. I suppose at some point I will
have to sharpen my soldering skills and get comfortable with SMT stuff.

When we are talking cost of OP-AMPS. I don't mind buying (6) quad amps
at a few bucks each. If we have to go with single amps, then we can,
and again if htey are a few bucks each that will be OK.

My basic interest in electronics has come from the audio side of
things. Over "there" the Burr-Browns are very popular for active
filtering for crossover networks and buffers.

Bill
 
J

John Popelish

beananimal said:
John Perry wrote:





Yes I now understand that the offset in conjunction with the somewhat
poor linearity and overall accuracy will be poor at low primary
currents. I am open to other ApAmp considerations to help reign in
some of this error.
(snip)
Take a look at:
http://ww1.microchip.com/downloads/en/DeviceDoc/21613b.pdf

It has a maximum 150 uV offset (about 20 times better than an LM324),
a common mode input voltage range from the negative rail (Vss) to .9
volts below the positive rail (Vdd -.9), rail to rail output swing (so
could do this job supplied by 5 volts) and runs about $2 per quad from
Digikey.
 
J

John Larkin

Hello John,
I do something similar to design digital filters, although pretty much
devoid of theory: I design an opamp-based analog filter, then "model"
it in uP code or in an FPGA. It seems to be not only easy to design,
it's usually is easier to code, in that the internal scalers seem to
be less outrageous than the factors you get when you use more
conventional IIR DSP filter design techniques.

That is an interesting method. Got to try that some time but now I am
going to be busy with a wireless project for a little.
.SBTTL . ANALOG LOWPASS FILTERS


; INPUT SAMPLES ARE TAKEN AT THE 139-HZ RATE AND SOFTWARE LOWPASS
; FILTERED. THE FILTER IS A 4-POLE, STATE-VARIABLE (INTEGRATOR-BASED)
; SORTA GAUSSIAN GADGET WITH A 'TRANSITIONAL' (EG, HOMEBREW) TRANSFER
; FUNCTION.


NODE 1 NODE 2 NODE 3 NODE 4
| | | |
IN --(+)-[K1:INT]--(+)--[K2:INT]->-(+)-[K3:INT]--(+)-[K4:INT]-->--OUT
| | | | | |
| | | | | |
| ^---(-1)--- | | ^---(-1)--- |
| | | |
| | | |
'------<----(-1)----------' '-------<------(-1)-------'


; THE FOUR LOWPASS FILTER INTEGRATION COEFFICIENTS ARE ALL EXPRESSED
; AS RIGHT-SHIFT COUNTS, AVOIDING POKEY MULTIPLIES.

; CAUTIONS: EVEN IF ALL INPUTS ARE POSITIVE NUMBERS, OCCASIONAL
; SLIGHTLY-NEGATIVE OUTPUT GLITCHES ARE POSSIBLE.

; BIG SAMPLE-TO-SAMPLE EXCURSIONS CAN CAUSE WILD END-AROUNDS, SO
; IT'S PRUDENT TO KEEP INPUT RANGE BELOW +- 0.25 FRACTIONAL.

; OK, HERE'S THE FILTER. WE USE REGISTERS D0-D6, AND ASSUME
; THAT A0 AIMS INTO A 4-NODE FILTER BLOCK.

; ON ENTRY, D0.L SHOULD HOLD THE FRESH FILTER INPUT.

; FOR SLOW ITEMS, WE USE A FILTER WITH RISETIME OF ABOUT 2 SECONDS,
; CORRESPONDING TO BANDWIDTH OF ABOUT 0.17 HZ. CONSTANTS ARE...

K1 = 7 ; 0.0078125
K2 = 5 ; 0.03125
K3 = 6 ; 0.015625
K4 = 5 ; 0.03125

Those coeffs are a bit on the small side. That is what I try to avoid. I
like them to be above 0.05 to maintain dynamic range but that will cost
extra stages.

Didn't quote the code but it made me curious: Which processor are you
using? Mine usually don't have a HW multiplier and the right and left
shift has to be done one step at a time. Looks like yours have a barrel
shifter.

This is an MC68332. Since all the registers are 32 bits, small
coefficients are not a problem. This is a 0.17 Hz filter clocked at
140 Hz, so the factors get small.

The '332 has a 32x32 multiply which wouldn't add a big speed penalty
to this filter. The step response has a small, slow tail as a result
of the ideal coefficients being rounded to right-shifts. It wasn't a
problem here (it's filtering a displayed, noisy thermocouple
temperature) but we had one application (weighing pills) where the
settling time mattered, so we changed one of the shifts to a multiply,
tweaked the value, and that snapped it right up.

This filter iteration executes in about 9 microseconds on a 16 MHz
CPU, as I recall.

John
 
J

Joerg

Hello John,

I do something similar to design digital filters, although pretty much
devoid of theory: I design an opamp-based analog filter, then "model"
it in uP code or in an FPGA. It seems to be not only easy to design,
it's usually is easier to code, in that the internal scalers seem to
be less outrageous than the factors you get when you use more
conventional IIR DSP filter design techniques.
That is an interesting method. Got to try that some time but now I am
going to be busy with a wireless project for a little.
.SBTTL . ANALOG LOWPASS FILTERS


; INPUT SAMPLES ARE TAKEN AT THE 139-HZ RATE AND SOFTWARE LOWPASS
; FILTERED. THE FILTER IS A 4-POLE, STATE-VARIABLE (INTEGRATOR-BASED)
; SORTA GAUSSIAN GADGET WITH A 'TRANSITIONAL' (EG, HOMEBREW) TRANSFER
; FUNCTION.


NODE 1 NODE 2 NODE 3 NODE 4
| | | |
IN --(+)-[K1:INT]--(+)--[K2:INT]->-(+)-[K3:INT]--(+)-[K4:INT]-->--OUT
| | | | | |
| | | | | |
| ^---(-1)--- | | ^---(-1)--- |
| | | |
| | | |
'------<----(-1)----------' '-------<------(-1)-------'


; THE FOUR LOWPASS FILTER INTEGRATION COEFFICIENTS ARE ALL EXPRESSED
; AS RIGHT-SHIFT COUNTS, AVOIDING POKEY MULTIPLIES.

; CAUTIONS: EVEN IF ALL INPUTS ARE POSITIVE NUMBERS, OCCASIONAL
; SLIGHTLY-NEGATIVE OUTPUT GLITCHES ARE POSSIBLE.

; BIG SAMPLE-TO-SAMPLE EXCURSIONS CAN CAUSE WILD END-AROUNDS, SO
; IT'S PRUDENT TO KEEP INPUT RANGE BELOW +- 0.25 FRACTIONAL.

; OK, HERE'S THE FILTER. WE USE REGISTERS D0-D6, AND ASSUME
; THAT A0 AIMS INTO A 4-NODE FILTER BLOCK.

; ON ENTRY, D0.L SHOULD HOLD THE FRESH FILTER INPUT.

; FOR SLOW ITEMS, WE USE A FILTER WITH RISETIME OF ABOUT 2 SECONDS,
; CORRESPONDING TO BANDWIDTH OF ABOUT 0.17 HZ. CONSTANTS ARE...

K1 = 7 ; 0.0078125
K2 = 5 ; 0.03125
K3 = 6 ; 0.015625
K4 = 5 ; 0.03125

Those coeffs are a bit on the small side. That is what I try to avoid. I
like them to be above 0.05 to maintain dynamic range but that will cost
extra stages.

Didn't quote the code but it made me curious: Which processor are you
using? Mine usually don't have a HW multiplier and the right and left
shift has to be done one step at a time. Looks like yours have a barrel
shifter.

This is an MC68332. Since all the registers are 32 bits, small
coefficients are not a problem. This is a 0.17 Hz filter clocked at
140 Hz, so the factors get small.

The '332 has a 32x32 multiply which wouldn't add a big speed penalty
to this filter. The step response has a small, slow tail as a result
of the ideal coefficients being rounded to right-shifts. It wasn't a
problem here (it's filtering a displayed, noisy thermocouple
temperature) but we had one application (weighing pills) where the
settling time mattered, so we changed one of the shifts to a multiply,
tweaked the value, and that snapped it right up.

That is a luxury processor when compared to pretty much any of the ones
I used.

This filter iteration executes in about 9 microseconds on a 16 MHz
CPU, as I recall.

Well, if I had a Ferrari Testarossa I could be at the next shopping
center in three minutes. Once...
 
J

John Larkin

That is a luxury processor when compared to pretty much any of the ones
I used.

Absolutely. I can't remember the last time I had to do an
add-with-carry operation!

John
 
J

Joerg

Hello John,
Absolutely. I can't remember the last time I had to do an
add-with-carry operation!

It can be even worse. You find the ideal filter shape and then after
lots of shuffling with CSD you discover that the total number of zeros
in the coefficients ain't sufficient so it all won't fit.
 
B

beananimal

The PIC programming is really not that hard, and the more knowledge you
acquire the better. As a programmer, the concepts should not be difficult,
although you may be more in tune with object oriented events driven
software, rather than low level concepts such as ISRs and real time
considerations, where a few microseconds can make a huge difference. I can
send you some PIC code that will set up the PRT to make A/D samples at a
useful rate, for one channel, and also perform the necessary accumulation
and comparisons if you want to add a relay or LED output for an alarm. The
code I would provide would be for a PIC12F675, which is a little 8 pin IC
with an A/D. It is the same IC that is used in the Microchip PICKIT-2
evaluation kit, which has all you need to breadboard your circuit and
program the PIC, for about $30. You can then migrate to a more powerful
micro with more A/D and also a serial port or other features. I personally
like the PIC18F242 or the newer 18F2420, and I can help provide coding for
that. (It also can be used with a C compiler). There may be a PIC better
suited to your particular application, and they can be obtained as free
samples from the www.Microchip.com website, along with all kinds of app
notes and reference designs. Fear not the mighty PIC!
Good luck,

Paul

Paul

I have decided to go with the PIC18F2420 or 4420 for this project and
interface it to the PC via a MAX232. As I mentioned I am interested in
learning how to do implement your ideas via the PIC as well as the
other circuit that Jim and John and John have helped me create. I will
be using PicBasic and have arranged to try a copy of the pro version at
a local school (sadly, there are no classes available for me to take or
I would). I have read the datasheet and worked out some of the basics.
I do have some serious questions regarding what type of Clock setting
to use, what A/D setting (TAD and FOSC) to use to ensure that I can
communicate with the PC and do the A/D etc.

I have ordered some parts for my prototypes and would like to start
working on the PIC portion of this project while I wait for them.

I am sure the uC portion of this project is not appropriate for this
group, so we can take it elsewhere or to private mail. Please let me
know what your preference is.

Thanks,
Bill
 
H

Homer J Simpson

As I mentioned I am interested in
learning how to do implement your ideas via the PIC as well as the
other circuit that Jim and John and John have helped me create.

Maybe

http://www.oshonsoft.com/pic.html
PIC Simulator IDE is powerful application that supplies PIC developers with
user-friendly graphical development environment for Windows with integrated
simulator (emulator), Basic compiler, assembler, disassembler and debugger.
PIC Simulator IDE currently supports the following microcontrollers from the
Microchip PICmicro 12F and 16F product lines: 12F629, 12F675, 12F683,
16F627, 16F627A, 16F628, 16F628A, 16F630, 16F648A, 16F676, 16F684, 16F685,
16F687, 16F688, 16F689, 16F690, 16F72, 16F73, 16F74, 16F76, 16F77, 16F737,
16F747, 16F767, 16F777, 16F83, 16F84, 16F84A, 16F87, 16F88, 16F818, 16F819,
16F870, 16F871, 16F872, 16F873, 16F873A, 16F874, 16F874A, 16F876, 16F876A,
16F877, 16F877A.

You are welcome to download the fully functional evaluation copy of the
software on the downloads page. PIC Simulator IDE requires a license to
operate after the evaluation period. Personal license for your home computer
available for only ?29. For more information please visit the licenses page.
 
P

Paul E. Schoen

beananimal said:
Paul

I have decided to go with the PIC18F2420 or 4420 for this project and
interface it to the PC via a MAX232. As I mentioned I am interested in
learning how to do implement your ideas via the PIC as well as the
other circuit that Jim and John and John have helped me create. I will
be using PicBasic and have arranged to try a copy of the pro version at
a local school (sadly, there are no classes available for me to take or
I would). I have read the datasheet and worked out some of the basics.
I do have some serious questions regarding what type of Clock setting
to use, what A/D setting (TAD and FOSC) to use to ensure that I can
communicate with the PC and do the A/D etc.

I have ordered some parts for my prototypes and would like to start
working on the PIC portion of this project while I wait for them.

I am sure the uC portion of this project is not appropriate for this
group, so we can take it elsewhere or to private mail. Please let me
know what your preference is.

Thanks,
Bill
I could post the PIC code as text but it would be better to send it as a
..TXT file, which you could change to .ASM to assemble using the MPLAB tools
supplied by Microchip. I don't know if you can set up ISRs using PICBASIC,
and if you can, it would have to be efficiently compiled to work properly.
All of my PIC code is in assembly, but it is fairly well commented. Much of
it is in the form of subroutines where you might put some data in file
registers or a buffer and then get data out (or have it sent out the serial
port). My code is for the PIC18F242, but I am setting up my new project
with a conditional assembly for both PICs.

My first project with this PIC is the Ortmaster. More details are on my
website at www.pstech-inc.com, and a downloadable version of the Windows
portion is available at www.Ortmaster.com. Basically, this project reads an
AC current anywhere from about 5 amps to 5000 amps, sampling it at 2400
times per second, and reads the true RMS value of that current as well as
its duration, to an accuracy of better than 1% and time to within about 1
mSec. A previous version used the parallel port in MSDOS to manipulate the
hardware. My new version, written in Borland Delphi 4, uses a serial port
(through a USB-USART bridge), and a smart board (with the PIC18F242) to
take the 10 bit readings through an RS232 port at 57.6 kBaud, in the form
of two characters with 5 bits of high-low data and two bits as a data check
mechanism.

My newer project is a smart SCR gate firing board which I have discussed in
previous posts.

I'll send you an email to get started.

BTW, you will need a way to program the PICs and run and debug the
software. I use the MPLAB ICD2, which I think is about $150. You can use
the PICKIT2 for simple programming of smaller PICs, but for the PIC18
series you will need something like the ICD2. There may be some less
expensive options, especially for just programming, but you will want a
debugger to set brealpoints and see what's happening. The software
simulator is good, but at some point you will need to get down to a
hardware level.

Paul
 
Top