Searching \ for '[PIC]: 16c73 RA4 as I/O will not work' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=i%2Fo
Search entire site for: '16c73 RA4 as I/O will not work'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 16c73 RA4 as I/O will not work'
2001\06\29@125846 by Roy Souther

flavicon
face
I added an external pullup resistor to it but it did not help.

Looking at it on the scope in does a saw tooth wave that peaks at about 1V
then a sharp drop.

I formated the subject wrong. I was notified that the : is required on the
subject line if I want the list to except it. Original message had the same
problem. Original message as follows.

I am having a very are time trying to get RA4 on a 73 to work as digital I/O.
What could be the problem? Here is my snipit of code that should work but
does not. I am using the Hi-Tech C compiler, 7.83 or so. My real program is
much larger then this and actualy does something but I need RA4 as an I/O
pin. I have tried 6 or so differnt chips and they all do the same thing.
Any ideas why this does not work?

void main()
{
  char TogelBit;

  OPTION = 0xC7;
  RBPU = 1; // Disable pullups on inputs, need to have put downs on them.
  T0CS = 0; // RA4 is an I/O pin

  ADON = 0; // Turn off ADC unit
  ADCON1 = 7; // Set Port A pins as I/O pins

  // Set the ports
  TRISA = 0x00;
  PORTA = 0;
  TRISB = 0xFF;
  TRISC = 0xFF;

 TogelBit = 1;
 while(1)
 {
     RA4 = TogelBit;

     if(TogelBit == 1)
     {
        TogelBit = 0;
     } else
     {
        TogelBit = 1;
     }
  }
}
--
Roy Souther <spam_OUTroyTakeThisOuTspamsilicontao.com>

01100010 10101110 11000110 11010110 00000100 10110010 10010110 11000110
01001110 11110110 11001110 00010110 10010110 00101110 10000100 10000100

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@132635 by Andrew E. Kalman

flavicon
face
Hi Roy.

Here's your problem:

>    char TogelBit;

You misspelled Toggle! ;-)

Seriously, though, simplify your code on the way to a solution. Use
this instead:

void main()
{
       /* initialization code  */

       while (1)
       {
               PORTA ^= 0x10;
       }
}
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   aekspamKILLspampumpkininc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@133318 by Spehro Pefhany

picon face
At 10:19 AM 6/29/01 -0600, Roy Souther wrote:
>I added an external pullup resistor to it but it did not help.
>
>Looking at it on the scope in does a saw tooth wave that peaks at about 1V
>then a sharp drop.

What kind of freqency response to you have on your scope? Is there an
optional low pass filter you can switch out? This should work, but the
times "on" and "off" will probably not be equal, and if you are running
at 20MHz, the times on/off will only be a microsecond or two.

Best regards,

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
EraseMEspeffspam_OUTspamTakeThisOuTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@133725 by Bob Ammerman

picon face
Roy,

This is a very fast toggle rate.

Since RA4 needs a pullup, you will need one of relatively low resistance to
drive the line up this quickly.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Original Message removed}

2001\06\29@134816 by Roman Black

flavicon
face
Spehro Pefhany wrote:
>
> At 10:19 AM 6/29/01 -0600, Roy Souther wrote:
> >I added an external pullup resistor to it but it did not help.
> >
> >Looking at it on the scope in does a saw tooth wave that peaks at about 1V
> >then a sharp drop.
>
> What kind of freqency response to you have on your scope? Is there an
> optional low pass filter you can switch out? This should work, but the
> times "on" and "off" will probably not be equal, and if you are running
> at 20MHz, the times on/off will only be a microsecond or two.


Getting 20MHz at RA4 is a bit of a feat, and with
most frequencies less than than you would expect more
of a square wave I bet.

Supplying more info re the freq and what he is driving
with the PIC pin will help quite a bit. The "sawtooth"
comment seems to imply that the load is too much for
the PIC pin, maybe just reducing the ohms value of the
pullup resistor might do it, or examination of the
capacitance of the load vs the freq etc.
-Roman

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@135843 by Spehro Pefhany

picon face
At 03:40 AM 6/30/01 +1000, you wrote:

>Getting 20MHz at RA4 is a bit of a feat, and with
>most frequencies less than than you would expect more
>of a square wave I bet.

It will be rectangular (rather than square) because the
program he wrote does not treat the two states symetrically,
in general. With a 20MHz MCU clock, you'd probably get a toggle
frequency in the hundreds of kHz.

But Bob hit the nail on the head, the capacitive loading
(of the scope probe, perhaps) combined with a too-high pullup
resistor on an open-drain output will lead to exactly this
sort of sawtooth behavior.

If this indicates a time constant of, say, 2 microseconds,
and the load capacitance is 20pF, then the pullup would
be something like 100K. With a 4.7K pullup, the results
should be quite different.

Best regards,


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
KILLspamspeffKILLspamspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@172954 by Andrew Warren

flavicon
face
Andrew E. Kalman <spamBeGonePICLISTspamBeGonespammitvma.mit.edu> wrote:

> Seriously, though, simplify your code on the way to a solution. Use
> this instead:
>
> void main()
> {
>         /* initialization code  */
>
>         while (1)
>         {
>                 PORTA ^= 0x10;
>         }
> }

Andrew:

Personally, I think that's a bad suggestion.

Explicitly writing 1's and 0's, as Roy originally did, ensures that
he's not having a read-mofdify-write problem... Which he WOULD have
had if he used your code with his original hardware (i.e., without a
pullup on RA4).

Without that pullup, RA4 would always read low, so your code would
just repeatedly write a 1 to the pin.  With a too-weak pullup, your
code would have the somewhat-interesting effect of auto-adapting his
toggle frequency to the time-constant of his resistor... But that
probably isn't what he wanted, and it would likely confuse him to see
a very asymmetrical waveform with a frequency much lower than he
expected.

-Andy


=== Andrew Warren --- TakeThisOuTaiwEraseMEspamspam_OUTcypress.com
=== IPD Systems Engineering, CYSD
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@181220 by Andrew E. Kalman

flavicon
face
Andy Warren notes:

>Explicitly writing 1's and 0's, as Roy originally did, ensures that
>he's not having a read-mofdify-write problem... Which he WOULD have
>had if he used your code with his original hardware (i.e., without a
>pullup on RA4).

etc.

All true -- I had not noticed that he was running at 20MHz, and at
those speeds the pin behavior of the PIC, coupled with RMW, becomes
an issue. In that case, better to do

while (1)
{
       imagePORTA ^= 0x40;
       PORTA = imagePORTA;
}

As an aside, though, does this code avoid the RMW issues?

while (1)
{
       PORTA |= 0x40;
       PORTA &= ~0x40;
}

Note that the HI-TECH compiler will use bcf and bsf instructions
(just two instructions total in the loop), and so I don't see how the
RMW issue crops up _with_respect_to_the_port_pin_in_question
(PORTA[4])_. Other pins on the port may not behave as one expects ...

Regards,
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   aekEraseMEspam.....pumpkininc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@181419 by Andrew E. Kalman

flavicon
face
Andy Warren wrote:

>Explicitly writing 1's and 0's, as Roy originally did, ensures that
>he's not having a read-mofdify-write problem... Which he WOULD have
>had if he used your code with his original hardware (i.e., without a
>pullup on RA4).

Actually, his code compiles to bcf and bsf instructions, too, which
are RMW instructions.  Perhaps that's the original source of his
problems?

Anything of the sort

Rn = 0;

or

Rn = 1;

compiles to a bcf or bsf instructions in HI-TECH., regardless of
optimization level.
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   RemoveMEaekEraseMEspamEraseMEpumpkininc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspam_OUTspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@190118 by Bob Ammerman

picon face
----- Original Message -----
From: "Andrew E. Kalman" <RemoveMEaekTakeThisOuTspamspamPUMPKININC.COM>
To: <EraseMEPICLISTspamspamspamBeGoneMITVMA.MIT.EDU>
Sent: Friday, June 29, 2001 6:12 PM
Subject: Re: [PIC]: 16c73 RA4 as I/O will not work


{Quote hidden}

Yes, but the bit being set or cleared is the one in question, so it can't
cause the typical RMW problem. The RMW problem with BCF/BSF happens on
_other_ bits within the same port.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@192254 by Andrew E. Kalman

flavicon
face
Bob Ammerman wrote:

>  > Actually, his code compiles to bcf and bsf instructions, too, which
>>  are RMW instructions.  Perhaps that's the original source of his
>>  problems?
>
>Yes, but the bit being set or cleared is the one in question, so it can't
>cause the typical RMW problem. The RMW problem with BCF/BSF happens on
>_other_ bits within the same port.

Good -- now that's cleared up in my mind.

To bad the PIC doesn't have a btf (bit toggle flag) instruction -- in
that case PORTA ^= 0x40 would be the perfect solution.
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   aekSTOPspamspamspam_OUTpumpkininc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservSTOPspamspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@231550 by Bob Ammerman
picon face
> To bad the PIC doesn't have a btf (bit toggle flag) instruction -- in
> that case PORTA ^= 0x40 would be the perfect solution.

The 18C _does_ have such an instruction

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2001\06\29@234417 by Andrew Warren

flavicon
face
Bob Ammerman <EraseMEPICLISTspamEraseMEmitvma.mit.edu> wrote:

> > To bad the PIC doesn't have a btf (bit toggle flag) instruction --
> > in that case PORTA ^= 0x40 would be the perfect solution.
>
> The 18C _does_ have such an instruction

   As do the PIC17 parts.

   -Andy


=== Andrew Warren --- @spam@aiw@spam@spamspam_OUTcypress.com
=== IPD Systems Engineering, CYSD
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...