Maker Pro
Maker Pro

LCD controlling with comparators

D

Danny T

Jan 1, 1970
0
Anthony said:
When an interrupt occurs, the GIE flag is cleared. This prevents the
scenario you described. When the ISR returns, it uses a retfie
instruction which sets the GIE bit again so that another interrupt can
occur. If you forget to clear the flag for the interrupt that you just
processed, then you'll be processing it again as soon as you execute the
retfie. ;-) This is a common mistake for newbies.

Well, I've gotten stuck already... Posted in alt.microsomething.8bit (TB
usefully says a.m.8bit) if you'd care to look :-(
 
A

Anthony Fremont

Jan 1, 1970
0
Danny T said:
What's that do?

It listens to a pendulum clock ticking and measures the time between the
ticks and tocks. I've got it working pretty well right now. It's got
two LEDs that ping-pong in sync with the tick-tock for a visual
reference that it's working. It also prints the time between beats to
an LCD for balancing the beat. I'm going to have it calculate the
number of beats per hour to help speed up pendulum length adjustments.
I have one old clock that keeps time with an accuracy of a few seconds
per week. Not bad for something on the order of 125 years old, huh?

I'm going to solder it up and add support for an optical detector or
two. I'm basically making something similar to this: (not for sale,
just for me ;-)
http://www.bmumford.com/microset.html
I collect old clocks, most of which don't work when I get them,
otherwise I couldn't afford them. Proper tools are hard to come by and
usually quite expensive. Brian's device is quite sophisticated and well
worth what he wants for it, but it's too expensive and too much of a
luxury for my blood. I don't need all the features, just a couple would
be nice. The ability to count the beats in one revolution of the minute
hand would be a huge timesaver for fitting a new pendulum, that's where
the optical sensor comes in. You just let the clock tick off an hour
(takes about 5 minutes with no pendulum attached) while you count the
number of ticks (optically or acoustically). This gives you the beats
per hour for that particular movement (timepiece). You then fit a
pendulum and adjust it in real time while looking at a real time beats
per hour display. Finally, adjust the length until it's right on with
what was calculated earlier. A job that used to consume days of trial
and error tinkering can now be done way less than two hours.

You should check out the rest of his website as he has some interesting
information about timekeeping in general, including studies he did of AC
mains frequency accuracy.
I'm the same with software... I've written about 30,000 "personal"
websites, and none of them ever make it to the web, because by the time
I've finished, I've thought of a better way to do it... It's good for
learning, but gets me a reputation!! I've decided if I can do this clock
properly (replace these 4 pics with cheap shift registers or something)
with alarm, I might start using it - just because I can! :)

Yeah, it's kinda neat to actually be able to use your projects.
I meant in a more general sense. From looking at shift registers, they
seemed to have clock and latch - clock seemed to be to set data (for
serial use), and latch was to move the collected input to the output
pins... I guess mine's a combi! ;)

From the receiving point of view, CLOCK tells you when to look at the
data line for valid information. You could think of your RB5 pin as a
latch pin since it tells the slave pick when to capture the information.
Hmmm, I wasn't aware of this - and everything seems to work without a
resistor. What are the implications - what difference would I see in
high/low with and without an external resistor?

Without the pull-up resistor, the pin can't actively drive anything.
IOW, it can't put out +5V. It can only act as a current sink. It may
be that the segment you have it connected to doesn't draw any
significant current (very likely) and that the pin floats high enough to
make it happy. It would never be able to supply enough +5V juice to
turn on an LED.
As well as holding the "enable" pin for 10 cycles, to be safe (if it
where 10), I'd also have to hold the "enable" pin low while maintaining
the same data to be "safe". Imagine if I hold the enable pin high for
100 cycles, we know my chip has read the data successfully, so I then
drop *all* pins down to 0. Since my "shift register" is running very
quickly, all it takes is for this moment (when all pins go low) to be
between the "is enable pin high" and "move input to output" and 0h would
be copied to my output!

Does that make sense?

Yes, that's why you need a data hold time. This is the time spent
continuing to present valid data on the port even after you bring the
enable pin low. As long as it's a predictable value, the slave PIC can
safely accept data from the master without worry. You'll see this value
specified in applicable datasheets where data is being exchanged via
I2C, SPI, etc...
 
D

Danny T

Jan 1, 1970
0
Anthony said:
It listens to a pendulum clock ticking and measures the time between the
ticks and tocks. I've got it working pretty well right now. It's got
two LEDs that ping-pong in sync with the tick-tock for a visual
reference that it's working. It also prints the time between beats to
an LCD for balancing the beat. I'm going to have it calculate the
number of beats per hour to help speed up pendulum length adjustments.
I have one old clock that keeps time with an accuracy of a few seconds
per week. Not bad for something on the order of 125 years old, huh?
<snip>

Sounds interesting, though I'm an 80s child, so I'd probably rig the
clock to be controlled by something digital and leave the pendulum for
show ;-)

Without the pull-up resistor, the pin can't actively drive anything.
IOW, it can't put out +5V. It can only act as a current sink. It may
be that the segment you have it connected to doesn't draw any
significant current (very likely) and that the pin floats high enough to
make it happy. It would never be able to supply enough +5V juice to
turn on an LED.

I see - so if I noticed the segments attached to those pins didn't
light, putting a resistor between 5V and the pins would correct it?

What would be the correct (or possible) ways to attach an LED to this
port? Would it just a resistor from +5V to the pin, connected to the
LED, or would it make more sense to attach the LED from +5V to the pin,
and let it sink? Does the chip need to be told if it's sinking or
sourcing, since I imagine they'd need to be hooked up rather differently?

Yes, that's why you need a data hold time. This is the time spent
continuing to present valid data on the port even after you bring the
enable pin low. As long as it's a predictable value, the slave PIC can
safely accept data from the master without worry. You'll see this value
specified in applicable datasheets where data is being exchanged via
I2C, SPI, etc...

Excellent, I was worried the electronics world was pumping out dodgey
electronics for a while then! Though I do find it strange this value is
specified, rather than the "reading" component reading data off into a
buffer, then processing from there - this way it's always perfect. We
only update *if* the clock is on, with the data we *know* was present
with the clock :)
 
A

Anthony Fremont

Jan 1, 1970
0
Danny T said:
Yep, I just popped out to get caps, realising I didn't have any small
enough... Those I came back with (a lucky bag!) include 10pF and some
that I believe are 15pF (they're brown, unlike most of my small blue
ones!) and have "15J" written on them. The datasheet says 15pF are fine,
though that's not optimised, and I've seen other quotes of 10pF. If the
datasheet isn't clear, how am I supposed to know which is best?

The ones that are best will be the ones that make your crystal oscillate
at exactly the right frequency, and start-up every time you apply power.
;-) You will probably want to use two 22pF ceramic caps.
And while we're on the subject, can someone please explain capacitors to
me... I've been reading The Art of Electronics, and gotten confused. As
I understood (before and after reading), caps hold charge (like a
buffer?)... I guessed that the cap recommended across Vdd and Vss on my
pic just "swallowed" up any little spikes, and sent them back to ground,
rather than through the pic. What would a cap on each leg of the crystal
do - to me, it looks like the whole thing would just go to ground
(They're very very small caps!) and the pin would see hardly anything?
Do I misunderstand? :(

Very small caps are best at passing thru only the highest freqencies.
Glitches on the power line are usually at quite high frequencies. And
yes some of your oscillator is being leaked to ground. It's ok,
otherwise the crystal might fracture under the stress of too much
feedback.
Sounds fair enough - my only worry now, is getting into the realms of
"threading"... Like the "random" failure I described before - not having
anything in my code assuming a register x instructions further up holds
the same value, since an interrupt may have fired in between and changed
it!!

Well, the interrupt routine must not save and restore the W, STATUS and
possibly FSR and PCLATH when it executes. Otherwise things go to pieces
in a big hurry. Preventing "collisions" between the ISR and main level
is not that hard.
Right, even easier to remember! :)



I read about that... I'm sure I won't make that mistake...
(well, I won't post it here when I do, at least ;-))

Yeah you will, you just won't know that's what's happening. You will be
certain that the processor is not executing instructions properly. ;-)
 
D

Danny T

Jan 1, 1970
0
Anthony said:
The ones that are best will be the ones that make your crystal oscillate
at exactly the right frequency, and start-up every time you apply power.
;-) You will probably want to use two 22pF ceramic caps.

Grrr...!

*looks in bag*

Why the hell can't they label caps properly?! My 100n caps are labelled
"10", and the 1u are labelled "105"... Is there a nice big table
somewhere that'll tell me all the possible things 22pF caps could be
labelled as? (and why did you say 22?)

Very small caps are best at passing thru only the highest freqencies.
Glitches on the power line are usually at quite high frequencies. And
yes some of your oscillator is being leaked to ground. It's ok,
otherwise the crystal might fracture under the stress of too much
feedback.

Right :)

Well, the interrupt routine must not save and restore the W, STATUS and
possibly FSR and PCLATH when it executes. Otherwise things go to pieces
in a big hurry. Preventing "collisions" between the ISR and main level
is not that hard.

Check my code in a.m.8bit - doesn't seem to work :-(

Yeah you will, you just won't know that's what's happening. You will be
certain that the processor is not executing instructions properly. ;-)

I'm certain it's not, but I am using RETFIE and clearing my interrupt
flag first :(
 
D

Danny T

Jan 1, 1970
0
Danny said:
Grrr...!

*looks in bag*

Why the hell can't they label caps properly?! My 100n caps are labelled
"10", and the 1u are labelled "105"... Is there a nice big table
somewhere that'll tell me all the possible things 22pF caps could be
labelled as? (and why did you say 22?)


I was wrong, they're 104 (100n) and 105 (1u). Those marked 10 are 10pF.
I *think* those marked 15J are 15pF. I've also got them marked...

102J COG63
6n8S
8
33n
33n
47nS 32V
n56
68j
8.2

Nice and consistant :(

Btw, you said the best ones makr my crystal accurate - does this mean if
my clock loses time, I need to change the caps? Can you tell which
direction? (eg. if my clock loses a minute a day, what do I do?)
 
A

Anthony Fremont

Jan 1, 1970
0
Danny T said:
<snip>

Sounds interesting, though I'm an 80s child, so I'd probably rig the
clock to be controlled by something digital and leave the pendulum for
show ;-)

I always wanted to put a pic, a lithium battery, a hall sensor (or MEMS
accelerometer to be really cool) and a column of LEDs into a pendulum
bob. Then the swinging column of LEDs could strobe out the date/time in
a format suitable for people that have problems with analog dials and
hands. ;-) I really have to get this done.
I see - so if I noticed the segments attached to those pins didn't
light, putting a resistor between 5V and the pins would correct it?

Yes, you would pick your resistor size so that enough current could be
supplied to the device being switched on and off.
What would be the correct (or possible) ways to attach an LED to this
port? Would it just a resistor from +5V to the pin, connected to the
LED, or would it make more sense to attach the LED from +5V to the pin,
and let it sink? Does the chip need to be told if it's sinking or
sourcing, since I imagine they'd need to be hooked up rather
differently?

You can do it either way you prefer. Many CMOS parts are better at
sinking current than sourcing it, but the PICs have the same limit
either way (usually 25mA per pin)

When the PIC is outputing a 0, then it is actively driving the pin low
and can sink current. When it is outputing a 1, it is actively driving
the pin high (except RA4) and can source current. If you hook two PICs
together and try to have a dualing outputs contest, one of the pins will
not survive. Always use a current limiting resistor between pins that
might try to do this.
Excellent, I was worried the electronics world was pumping out dodgey
electronics for a while then! Though I do find it strange this value is
specified, rather than the "reading" component reading data off into a
buffer, then processing from there - this way it's always perfect. We
only update *if* the clock is on, with the data we *know* was present
with the clock :)

The hold time is just to give the receiving device enough time to detect
the clock and get the data. The data is held on the output device for a
small (but specified) period of time so that the window of opportunity
that you are concerned about gets closed.
 
D

Danny T

Jan 1, 1970
0
Anthony said:
I always wanted to put a pic, a lithium battery, a hall sensor (or MEMS
accelerometer to be really cool) and a column of LEDs into a pendulum
bob. Then the swinging column of LEDs could strobe out the date/time in
a format suitable for people that have problems with analog dials and
hands. ;-) I really have to get this done.

Sounds like fun! Just make sure you're not posessed to get Blue LEDs...
Can we say tacky? :)

Yes, you would pick your resistor size so that enough current could be
supplied to the device being switched on and off.

I believe one resistor would do all the pins.. I'm not sure how that
would work though, given I'd end up with different currents depending on
how many pins where high/low!

You can do it either way you prefer. Many CMOS parts are better at
sinking current than sourcing it, but the PICs have the same limit
either way (usually 25mA per pin)

When the PIC is outputing a 0, then it is actively driving the pin low
and can sink current. When it is outputing a 1, it is actively driving
the pin high (except RA4) and can source current. If you hook two PICs
together and try to have a dualing outputs contest, one of the pins will
not survive. Always use a current limiting resistor between pins that
might try to do this.

Do you mean having the output of a pic fed to the input of another? Like
I need for my clock? Should I put resistors between them?

Oh, and each output from my "driver" is connected to 4 inputs (one from
each of the other pics) - anything I should be careful of there - 4
inputs probably draw 4 times as much current - is there a problem here?
 
A

Anthony Fremont

Jan 1, 1970
0
Danny T said:
Grrr...!

*looks in bag*

Why the hell can't they label caps properly?! My 100n caps are labelled
"10", and the 1u are labelled "105"... Is there a nice big table
somewhere that'll tell me all the possible things 22pF caps could be
labelled as? (and why did you say 22?)

They usually have the cryptic value of "22" printed on them, plus the
size is kind of a giveaway. ;-) I said 22, because that's what I've
always used and it works. But a better reason would be that the
datasheet calls for 15 to 33pF of capactance for each cap. The real
determining factor is whatever the crystal manufacturer calls for to
bring the crystal to the right frequency. 22pF works pretty well in
practice. It's only really critical when you are trying to keep
precision time over a long period.
Right :)



Check my code in a.m.8bit - doesn't seem to work :-(

Check my reply, you need to make changes. ;-)
;-)

I'm certain it's not, but I am using RETFIE and clearing my interrupt
flag first :(

Your code looks ok in this respect.
 
A

Anthony Fremont

Jan 1, 1970
0
Danny T said:
Sounds like fun! Just make sure you're not posessed to get Blue LEDs...
Can we say tacky? :)



I believe one resistor would do all the pins.. I'm not sure how that
would work though, given I'd end up with different currents depending on
how many pins where high/low!

You only have to worry about pin RA4, the others are fine.
Do you mean having the output of a pic fed to the input of another? Like
I need for my clock? Should I put resistors between them?

It wouldn't hurt for you to do that (1k should work fine), but it's
important when you have pins that flip from being input to output on the
fly when trying to communicate bidirectionally. Eventually something
leads to things being out of sync and then you have battling outputs.
When one pin is *outputting* a 1 and the the other is *outputting* a 0,
it's a short circuit.
Oh, and each output from my "driver" is connected to 4 inputs (one from
each of the other pics) - anything I should be careful of there - 4
inputs probably draw 4 times as much current - is there a problem
here?

CMOS inputs draw very miniscule amounts of current, almost 0.
 
A

Anthony Fremont

Jan 1, 1970
0
Danny said:
I was wrong, they're 104 (100n) and 105 (1u). Those marked 10 are 10pF.
I *think* those marked 15J are 15pF. I've also got them marked...

102J COG63
6n8S
8
33n
33n
47nS 32V
n56
68j
8.2

Nice and consistant :(

Btw, you said the best ones makr my crystal accurate - does this mean if
my clock loses time, I need to change the caps? Can you tell which
direction? (eg. if my clock loses a minute a day, what do I do?)

If your clock was losing a minute per day, then you would likely need to
fix the bug in your code. ;-) If, however, the crystal was running
slow and you were losing a few seconds per day, that would mean you have
too much capacitance. IOW, the bigger the caps the slower the crystal
will run (to a point).
 
D

Danny T

Jan 1, 1970
0
Anthony said:
It wouldn't hurt for you to do that (1k should work fine), but it's
important when you have pins that flip from being input to output on the
fly when trying to communicate bidirectionally. Eventually something
leads to things being out of sync and then you have battling outputs.
When one pin is *outputting* a 1 and the the other is *outputting* a 0,
it's a short circuit.

I see. I'll leave bi-directional stuff for now ;-)
 
D

Danny T

Jan 1, 1970
0
Anthony said:
If your clock was losing a minute per day, then you would likely need to
fix the bug in your code. ;-)

*the*? Do you just mean one of them? ;P

If, however, the crystal was running
slow and you were losing a few seconds per day, that would mean you have
too much capacitance. IOW, the bigger the caps the slower the crystal
will run (to a point).

Righto :)
 
D

Danny T

Jan 1, 1970
0
Anthony said:
They usually have the cryptic value of "22" printed on them, plus the
size is kind of a giveaway. ;-) I said 22, because that's what I've
always used and it works. But a better reason would be that the
datasheet calls for 15 to 33pF of capactance for each cap. The real
determining factor is whatever the crystal manufacturer calls for to
bring the crystal to the right frequency. 22pF works pretty well in
practice. It's only really critical when you are trying to keep
precision time over a long period.

That's fine then... If, over a year, I start getting into work later and
later, I think I can live with that :)

What did you say - bigger caps mean work later? ;)

Check my reply, you need to make changes. ;-)

Thanks, but I've managed to still do it wrong 0:)

Your code looks ok in this respect.

You're likely reading it wrong ;-)
 
J

John Fields

Jan 1, 1970
0
I see (oops)... What I don't understand though, if "com" is for the
backplane - what about ground? :-\

---
There _is_ no hard ground required, it's like this:

INn------------------------------------------+
|
INb----------------------+ |
| |
INa---+ | |
| | |
+--A +--A +--A
EXOR Y------+ EXOR Y------+ EXOR Y------+
INBP>-+--B | +--B | +--B |
| | | | | |
+------------|-----+------------|------+ |
|COM a| b| n|
+-|------------|------------------|-------------------|----+
| | | | | |
| | [SEGa] [SEGb] [SEGn] |
| | | | | |
| +------------+------------------+---------//--------+ |
| DISPLAY GLASS |
+----------------------------------------------------------+

Where the EXORs are part of the external drive circuitry, the "DISPLAY
GLASS" is the display itself, and SEGa, SEGb, and SEGn represent the
inherent capacitances between the various segment electrodes and the
backplane.
 
D

Danny T

Jan 1, 1970
0
John said:
I see (oops)... What I don't understand though, if "com" is for the
backplane - what about ground? :-\


---
There _is_ no hard ground required, it's like this:

INn------------------------------------------+
|
INb----------------------+ |
| |
INa---+ | |
| | |
+--A +--A +--A
EXOR Y------+ EXOR Y------+ EXOR Y------+
INBP>-+--B | +--B | +--B |
| | | | | |
+------------|-----+------------|------+ |
|COM a| b| n|
+-|------------|------------------|-------------------|----+
| | | | | |
| | [SEGa] [SEGb] [SEGn] |
| | | | | |
| +------------+------------------+---------//--------+ |
| DISPLAY GLASS |
+----------------------------------------------------------+

Where the EXORs are part of the external drive circuitry, the "DISPLAY
GLASS" is the display itself, and SEGa, SEGb, and SEGn represent the
inherent capacitances between the various segment electrodes and the
backplane.

Righto. I'll leave it as it is while I get my other chip working, then I
might play about with changing it as you suggest! :)
 
J

John Fields

Jan 1, 1970
0
John said:
You have what's called a "static" display, and the pins marked "com"
are connected to the backplane, which is the transparent electrode
which forms one side of the capacitor comprising each segment and the
backplane. MOST static LCD displays aren't designed to be driven by
DC, and what will happen is that the ITO will plate out of either the
backplane or the segment and migrate to the opposite electrode, with
the eventual result that the capacitor will be destroyed and the digit
will become unreadable. The proper way to drive static LCDs is with
square wave AC; the backplane and the segment being driven in phase
when the segment isn't supposed to be displayed, and out of phase when
it is, like this for the segment to be off:

__ __ __ __ __ __
SEGOFF__| |__| |__| |__| |__| |__|

__ __ __ __ __ __
BP __| |__| |__| |__| |__| |__|


and like this for it to be on:

__ __ __ __ __ __
SEGON |__| |__| |__| |__| |__| |__

__ __ __ __ __ __
BP __| |__| |__| |__| |__| |__|


This task _can_ be accomplished with a µC and a longish shift register
By EXORring the backplane and the segments at about 30Hz., but it's
often done with a device like a National MM5483 so all you have to do
is shift data into it and strobe the output registers without any
extra software overhead.

http://cache.national.com/ds/MM/MM5483.pdf

If you've got a 3-1/2 digit seven-segment display, that's 23 segments,
and the 5483 can drive 32 segments and a backplane, so that leaves you
with nine extra segment drivers for decimal points, annunciators, or
the colon if you're doing a clock. Best of all, Digi-Key's got them
in 40-pin DIP packages for about five bucks.

I see (oops)... What I don't understand though, if "com" is for the
backplane - what about ground? :-\


---
There _is_ no hard ground required, it's like this:

INn------------------------------------------+
|
INb----------------------+ |
| |
INa---+ | |
| | |
+--A +--A +--A
EXOR Y------+ EXOR Y------+ EXOR Y------+
INBP>-+--B | +--B | +--B |
| | | | | |
+------------|-----+------------|------+ |
|COM a| b| n|
+-|------------|------------------|-------------------|----+
| | | | | |
| | [SEGa] [SEGb] [SEGn] |
| | | | | |
| +------------+------------------+---------//--------+ |
| DISPLAY GLASS |
+----------------------------------------------------------+

Where the EXORs are part of the external drive circuitry, the "DISPLAY
GLASS" is the display itself, and SEGa, SEGb, and SEGn represent the
inherent capacitances between the various segment electrodes and the
backplane.

Righto. I'll leave it as it is while I get my other chip working, then I
might play about with changing it as you suggest! :)

---
OK. One thing I didn't mention is that INBP should be a square wave
and that INa, INb, and INn should be logic level highs or lows; high
to make the corresponding segment visible and low to make it
invisible. Also, be aware that all this circuitry is internal to the
5483, so all you need to do is set the frequency of its internal RC
oscillator, then treat it like a 32 bit shift register and it'll do
the rest of the work for you.

If you want to play around with it and do it with 8 bit serial-in
parallel-out shift registers (with output latches) you'll need three
of them plus six quad EXORs.
 
Top