I am trying to sample a relatively slow signal to get
some rought idea of its frequency and so I thought
that rather than use the AD ports on a PIC16F877 I
might change the analog signal to digital
using a voltage comparator, and then I could read
the signal values at one of the PIC's digital IO pins.
Sounds great! I am just wondering what will happen
on the off chance(or not so off) that I go to read
the IO pin while it is going through a signal
transition. i.e what happens if the pin is rising
or falling and I read from it.
Nick Torenvliet
FieldStone Solutions
62 Longwood Road South
Hamilton Ontario
L8S 1S5
On Tue, Mar 06, 2001 at 11:53:40AM -0500, Nick Torenvliet wrote:
> Sounds great! I am just wondering what will happen
> on the off chance(or not so off) that I go to read
> the IO pin while it is going through a signal
> transition. i.e what happens if the pin is rising
> or falling and I read from it.
You'll get a one or a zero. If you look fast enough, you might even
see a mix; I'm sure I've seen that once or twice. You can calculate
from the clock frequency how frequently you will be sampling the input,
and then based on the low and high input voltage specifications of the
pin you can calculate what slope of line might cause this behaviour.
If you build your comparator with hysteresis, it won't oscillate at the
switching point. It will move fairly fast, and so the chances are that
you won't have to worry; it will be at Vdd or Vss, and rarely between.
> I am just wondering what will happen on the off chance(or not so
> off) that I go to read the IO pin while it is going through a
> signal transition. i.e what happens if the pin is rising or falling
> and I read from it.
> You'll get a one or a zero. If you look fast enough, you might
> even see a mix; I'm sure I've seen that once or twice.
I'm sure you haven't. The CPU doesn't read the voltage on the
I/O pin directly; there's at least one clocked buffer between the
pin and the PORTx register, so the value that the CPU reads is
guaranteed to be stable during the read cycle.
-Andy
=== Andrew Warren --- aiwspam_OUTcypress.com
=== IPD Systems Engineering, CYSD
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation
On Tue, Mar 06, 2001 at 03:20:45PM -0800, Andrew Warren wrote:
> and James Cameron <KILLspamPICLISTKILLspamMITVMA.MIT.EDU> replied:
> > You'll get a one or a zero. If you look fast enough, you might
> > even see a mix; I'm sure I've seen that once or twice.
>
> I'm sure you haven't. The CPU doesn't read the voltage on the
> I/O pin directly; there's at least one clocked buffer between the
> pin and the PORTx register, so the value that the CPU reads is
> guaranteed to be stable during the read cycle.
Yeah, sorry, I was inaccurate. I mean if you keep reading, many times,
you may see a mix of ones and zeros if the signal is oscillating or
moving too slowly. Each bit is being clocked in on the Q2 cycle of
each reading instruction.