On the pic71 I want to use an external clock to increment the RTCC.
Logic says that you set the RTCC pin as an input, tell the pic that
the RTCC signal source is on RA4 and hey presto it's supposed to work.
Well this had me baffeled for around two weeks because it did'nt work.
I could see because at every count of 50 a led was to be turned on
and off. The external clock was from an opto isolator, being pulled
up with a 4.7k resistor. When the pic was run the RA4 pin was pulling
the opto output to ground.
OK thought I, lets do the opposite.
Looking at the block diagram of the RA4 pin as shown in the PIC16C71
data sheet ( page 25).I set the pin as an output and then sent a '1'
to that pin, guess what, that led started flashing. The only way I
could get an external clock to the RTCC was to set the pin as an
output (not an input ) and then write a '1' to disable the open
collector output transistor. O.K so I thought I had it sussed.
But no, it would'nt work on mpsim. I was originaly using ver 3.*
and applying a simulas file, but it would'nt simulate an external
clock on the simulator.
Then I got mpsim ver 5.0, It lets you apply a clock to any pin with a
predefined mark space ratio. Did it simulate my external clock. No it
just sat there and didnt change. Ok said I lets reset that RA4 pin as
an input for the simulator, and yes it worked.
Have I got something wrong, I can get it to work on the pic but not
on the simulator, or I can get it to work on the simulator but not on
the pic. I could remember and change the option register for
simulation and then (if I don't forget) change it back before I
program the pic BUT.....!
IS THERE ANOTHER WAY OF DOING IT.......?I've seen things you people would'nt
believe,
Attack ships on fire of the shores of Orion,
I watched sea beams,glitter in the darkness at ten houser gate,
All these moments will be lost,
In time,
like tears in the rain
>On the pic71 I want to use an external clock to increment the RTCC.
>Logic says that you set the RTCC pin as an input, tell the pic that
>the RTCC signal source is on RA4 and hey presto it's supposed to work.
>Well this had me baffeled for around two weeks because it did'nt work.
>....
>I set the pin as an output and then sent a '1' to that pin, guess
>what, that led started flashing.
>....
>IS THERE ANOTHER WAY OF DOING IT.......?
Kenny:
The problem you're seeing is the result of a bug in the "rev A"
16C71's. The simulator models the parts as they should have been
produced; that's why it behaves differently than your PIC. The
problem's been fixed in the "rev B" parts.
You can tell what rev you have by looking at the face of the 16C71;
it'll say something like:
PIC16C71
/JW-S1
9352 CAT
or
PIC16C71-04/P
9404 CAA TAIWAN
The middle letter of that three-letter "CAT" or "CAA" designation is
the chip's revision letter.
>On the pic71 I want to use an external clock to increment the RTCC.
>Logic says that you set the RTCC pin as an input, tell the pic that
>the RTCC signal source is on RA4 and hey presto it's supposed to work.
>Well this had me baffeled for around two weeks because it did'nt work.
>I could see because at every count of 50 a led was to be turned on
>and off. The external clock was from an opto isolator, being pulled
>up with a 4.7k resistor. When the pic was run the RA4 pin was pulling
>the opto output to ground.
>OK thought I, lets do the opposite.
>Looking at the block diagram of the RA4 pin as shown in the PIC16C71
>data sheet ( page 25).I set the pin as an output and then sent a '1'
>to that pin, guess what, that led started flashing. The only way I
>could get an external clock to the RTCC was to set the pin as an
>output (not an input ) and then write a '1' to disable the open
>collector output transistor. O.K so I thought I had it sussed.
>But no, it would'nt work on mpsim. I was originaly using ver 3.*
>and applying a simulas file, but it would'nt simulate an external
>clock on the simulator.
>Then I got mpsim ver 5.0, It lets you apply a clock to any pin with a
>predefined mark space ratio. Did it simulate my external clock. No it
>just sat there and didnt change. Ok said I lets reset that RA4 pin as
>an input for the simulator, and yes it worked.
>Have I got something wrong, I can get it to work on the pic but not
>on the simulator, or I can get it to work on the simulator but not on
>the pic. I could remember and change the option register for
>simulation and then (if I don't forget) change it back before I
>program the pic BUT.....!
>
>IS THERE ANOTHER WAY OF DOING IT.......?I've seen things you people would'nt
> believe,
>Attack ships on fire of the shores of Orion,
>I watched sea beams,glitter in the darkness at ten houser gate,
>All these moments will be lost,
>In time,
>like tears in the rain
>
>Remember now, watch out for the Fairies......!
Doug Sellner
Beach Tech
4131 Vincent Avenue South
Minneapolis MN 55410
Doug Sellner said:
I had the same problem, but with the port b change interrupts.
I solved it by properly saving the status and W registers during interrupts.
I found that during a few interrupts the tris regs were changed.
------------------
So I want to sum up some general notes about interrupt programming:
Always begin an interrupt routine with saving the W and then the STATUS
register.
If you are using Port-B interrupts or have to read from/write to ports, clear
the RP0-flag in the STATUS to access the Port latches, not the corresponding
tris-registers! It took me several hours to find that bug in my PIC-based modem
switch box.
And if you use indirect addressing both in your main program and in the
interrupt routine, do not forget to save and restore the FSR and IND registers.
In general, save and restore is necessary for all registers that are used in
an independent way in the main and the interrupt routine! Although this seems
quite obvious, it is forgotten more often than many would expect.
Of course, at the end of the interrupt routine the interrupt flags have to be
cleared and the saved registers to be restored, at last the STATUS and then
the W register, using adequate SWAP-commands not to change the Z-flag in
STATUS.
>> Of course, at the end of the interrupt routine the interrupt flags have to be
>> cleared and the saved registers to be restored, at last the STATUS and then
>> the W register, using adequate SWAP-commands not to change the Z-flag in
>> STATUS.
>Could someone post a code fragment for this? I *think* mine is
>working, but I'm wondering if there's a better way.
>Chris
Be carefull with the page bits at entry of the interrupt. If you use them
in your code, you must set the right value inside the interrupt. At exit,
the old values are restored.
Sigfried Grob said:
> And if you use indirect addressing both in your main program and in the
> interrupt routine, do not forget to save and restore the FSR and IND
> registers.
In general you should *NOT* save the IND register on entry to an interrupt,
since it is really just the register pointed to by the FSR. The whole point
of saving and restoring the FSR in an interrupt routine is so that you can
use indirect addressing to access something other than what the non-interrupt
code was accessing.
In a pathological case, the non-interrupt code might point the FSR at an I/O
port that causes side effects if you read and write it as would happen with
a save/restore.
In article: <9506270151.aa14818spam_OUTpunt3.demon.co.uk> @spam@fastfwdKILLspamix.netcom.com writes:
:
: Kenny Baby <KILLspamMCTKEAWKILLspamMH1.MCC.AC.UK> wrote:
:
: >On the pic71 I want to use an external clock to increment the RTCC.
: >Logic says that you set the RTCC pin as an input, tell the pic that
: >the RTCC signal source is on RA4 and hey presto it's supposed to work.
: >Well this had me baffeled for around two weeks because it did'nt work.
:
: Kenny:
:
: The problem you're seeing is the result of a bug in the "rev A"
: 16C71's. The simulator models the parts as they should have been
: produced; that's why it behaves differently than your PIC. The
: problem's been fixed in the "rev B" parts.
Thank you !
I'd just spent most of today trying to figure out a very similar problem. The
program would work fine on the simulator but the damn thing was just pulling
the RA4 line low when on the board.
Will Microchip replace this expensive windowed EPROM 16C71 'rev A' chip
(shipped with my PICSTART-16B kit) for one that does as it is supposed to ?