Searching \ for '[PIC]: PORTA output troubles!' 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=output
Search entire site for: 'PORTA output troubles!'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: PORTA output troubles!'
2002\06\24@210715 by Nick Veys

flavicon
face
Ok I'm guessing this is a painfully obvious, 5 second fix, but it's had
me stumped for 2 evenings.

I have the following code:

--------snip-------------------------------------------------

TRISA = 0b00000000;

while(1)
{
 RA2 = RA3 = RA4 = RA5 = 0;
 DELAY_MS(250);
 RA2 = RA3 = RA4 = RA5 = 1;
 DELAY_MS(250);
}

--------snip--------------------------------------------------

Which should simply blink the LEDs I have hooked up to PORTA[5:2].  No
luck.  With the above code, RA2 will blink, the rest do nothing.  If I
change the order, say from RA5 = RA4 = ... = 0; and the same for the =
1; part, RA5 will blink, and the rest do nothing.  So it appears the 1st
one in the list works.  Odd.  Now if I take that line apart into:

RA2 = 0;
RA3 = 0;

...

etc, same thing happens, RA2 blinks, the rest do nothing.

I thought maybe it was a speed thing, so I put NOPs between, nothing
happens, and I doubt that would do anything because, well, I've never
experienced anything like that before.

So I tried to do it in assembly, this project is basically a HiTech PICC
test anyways...

So I have this:

------snip-----------------------------------------

MAIN
 _BANK 1
 movlw b'00000000'
 movwf TRISA
 _BANK 0

loopage
 bsf PORTA,2
 bsf PORTA,3
 bsf PORTA,4
 bsf PORTA,5
 DELAY_MILLI 250
 bcf PORTA,2
 bcf PORTA,3
 bcf PORTA,4
 bcf PORTA,5
 DELAY_MILLI 250
 goto loopage

end

------snip---------------------------------------

But here, I get just !!!!!RA5!!!!! blinking.  I'm thoroughly confused.

Ideas?  Please tell me I'm dumb and need to set a bit somewhere! :)

Gracias in advance.

spam_OUTnickTakeThisOuTspamveys.com | http://www.veys.com/nick

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


2002\06\24@211807 by Tony Nixon

flavicon
picon face
Nick Veys wrote:

> loopage
>   bsf PORTA,2
>   bsf PORTA,3
>   bsf PORTA,4
>   bsf PORTA,5
>   DELAY_MILLI 250
>   bcf PORTA,2
>   bcf PORTA,3
>   bcf PORTA,4
>   bcf PORTA,5
>   DELAY_MILLI 250
>   goto loopage
>
>  end

The BSF instruction first reads PORTA, sets bit_X and then writes the
data back to PORTA.

If RA2,3,4 are read by the processor as being logic 0, then logic 0 is
written back to the PORTA. Thus RA2,3,4 for the most part stay = 0, and
only RA5 is ON.

If you connect all the LEDs to the VCC rail instead of GND, you may find
that they all stay on except RA5.

Please note that RA4 is open collector and will only work the LED if it
connected to VCC.

Try...

Loop    movlw b'00111100'               ; LEDs = OFF
       movwf PORTA
       DELAY_MILLI 250

       clrf PORTA                      ; LEDs = ON
       DELAY_MILLI 250
       goto Loop

This assumes all LEDs are connected to VCC via resistor to PORTA.

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
salesspamKILLspambubblesoftonline.com

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


2002\06\24@213805 by Nick Veys

flavicon
face
{Quote hidden}

This would work only I need individual control of each line.  I've used
BSF/BCF operations to do bit-banged SPI on a 16F84 before, and that
worked just fine, it's hard to believe that I can't simply toggle some
lines using those commands!

Should I use some kind of shadow register, set the bit in there and then
move it to PORTA?  Sounds extremely backwards and kludgy.

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


2002\06\24@214541 by tundra

flavicon
face
Nick Veys wrote:

> This would work only I need individual control of each line.  I've used
> BSF/BCF operations to do bit-banged SPI on a 16F84 before, and that
> worked just fine, it's hard to believe that I can't simply toggle some
> lines using those commands!

You can.  It sounds to me like you have not properly set up the TRISA
register for the bits in question ...


------------------------------------------------------------------------------
Tim Daneliuk
tundraspamspam_OUTtundraware.com

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


2002\06\24@214844 by David Duffy

flavicon
face
part 1 979 bytes content-type:text/plain; x-avg-checked=avg-ok-45CD04; charset=us-ascii; format=flowed (unknown type 8bit not decoded)

Nick wrote;
>This would work only I need individual control of each line.  I've used
>BSF/BCF operations to do bit-banged SPI on a 16F84 before, and that
>worked just fine, it's hard to believe that I can't simply toggle some
>lines using those commands!

You can but you have the read-modify-write problem to deal with
if you use consecutive bsf/bcf instructions to the same I/O port.
Most times, a NOP or two between the bsf/bcf is all you need.

>Should I use some kind of shadow register, set the bit in there and then
>move it to PORTA?  Sounds extremely backwards and kludgy.

That's exactly the work-around a lot of programmers use.
Regards...

___________________________________________
David Duffy        Audio Visual Devices P/L
U8, 9-11 Trade St, Cleveland 4163 Australia
Ph: +61 7 38210362   Fax: +61 7 38210281
New Web: http://www.audiovisualdevices.com.au
___________________________________________


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


2002\06\24@215048 by Matt Pobursky

flavicon
face
You're probably getting bit by the "read-modify-write"
gotcha because you are operating directly on the PORTA output
register.If your LED circuit is loading the output pins so that
the logic level read by the bsf PORTA instruction reads a logic
zero on that pin -- well that's your answer.

Operating with bsf and bcf instructions directly on port pins is
always a potential problem (or at least the port loading and
timing has to be carefully considered). A better solution is to
keep a shadow register of the port contents, operate on them,
then write the whole shadow register to the port.

C compilers can sometimes obscure the fact that you are operating
directly on the port output register. This is another good reason
for using a shadow register. It's a tad slower (you have to read,
then write the shadow to the port register), but it's always
safe.

My guess is that in your case, the logic levels of the output
port pins are right at the transition level from logic '1' and
logic '0'. Of course this will vary from PIC to PIC and with
temperature, exact load conditions, etc. which makes the
result quite unpredictable!

If you try something like:

TRISA = 0b00000000;
PORTA_Shadow = 0;   // setup PORTA_Shadow as a struct of bits
PORTA = PORTA_Shadow;

while (1)
{
PORTA_Shadow.2 = 0;
PORTA_Shadow.3 = 0;
PORTA_Shadow.4 = 0;
PORTA_Shadow.5 = 0;
PORTA = PORTA_Shadow;
DELAY_MS(250);
PORTA_Shadow.2 = 1;
PORTA_Shadow.3 = 1;
PORTA_Shadow.4 = 1;
PORTA_Shadow.5 = 1;
PORTA = PORTA_Shadow;
DELAY_MS(250);
}

It should work.

Matt Pobursky
Maximum Performance Systems

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


2002\06\24@215507 by Nick Veys

flavicon
face
>> This would work only I need individual control of each line.  I've
>> used BSF/BCF operations to do bit-banged SPI on a 16F84 before, and
>> that worked just fine, it's hard to believe that I can't
>simply toggle
>> some lines using those commands!
>
>You can.  It sounds to me like you have not properly set up
>the TRISA register for the bits in question ...

This is what I was thinking as well, but in the PICC, I simply have:

---

TRISA = 0b00000000;

---

Hopefully I can rely on that... :/  I've also tried just simply TRISA =
0; to eliminate the possible misuse of the 0b.

And in assembly I have:

---

_BANK 1
movlw b'00000000'
movwf TRISA ^ 0x80

---

The _BANK macro is one I've used in plenty of other projects.  But just
in case, here it is:

---

_BANK macro X                           ; Switch banks
if X == 0
 bcf STATUS, RP1                               ;
 bcf STATUS, RP0                               ; RP[1:0] = 0  ==> Bank
0
endif
if X == 1
 bcf STATUS, RP1                               ;
 bsf STATUS, RP0                               ; RP[1:0] = 1  ==> Bank
1
endif
if X == 2
 bsf STATUS, RP1                               ;
 bcf STATUS, RP0                               ; RP[1:0] = 2  ==> Bank
2
endif
if X == 3
 bsf STATUS, RP1                               ;
 bsf STATUS, RP0                               ; RP[1:0] = 3  ==> Bank
3
endif
 endm

---

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


2002\06\24@215907 by Matt Pobursky

flavicon
face
On Mon, 24 Jun 2002 20:36:16 -0500, Nick Veys wrote:
>>Nick Veys wrote:
>This would work only I need individual control of each line.
>I've used
>BSF/BCF operations to do bit-banged SPI on a 16F84 before, and
>that
>worked just fine, it's hard to believe that I can't simply
>toggle some
>lines using those commands!

The difference is that you were probably driving logic inputs
when you bit banged that serial interface -- a very light load --
and the LED's load down the output pin because of the much
heavier output current. Big difference there!

>Should I use some kind of shadow register, set the bit in there
>and then
>move it to PORTA?  Sounds extremely backwards and kludgy.

Actually, it's the PIC's output port structure that's backwards
and kludgy. ;-)

Actually, it's a 6:1, half dozen the other scenario. There are
times when being able to read the actual port pin level vs. the
output register logic level can come in handy. You just have to
always be aware you are reading the output PIN level, not the
output register logic level.

Matt Pobursky
Maximum Performance Systems

P.S. More people have been skewered by this pitfall than probably
any other in the PIC world. Myself included...

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


2002\06\24@220534 by Nick Veys

flavicon
face
{Quote hidden}

Ok, everything everyone has said is starting to make sense, and you're
right, I was driving logic inputs...  Thanks everyone for the help, no I
just gotta wrap my mind around a good solution to this! :)  Thanks.

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


2002\06\25@010153 by Scott Dattalo

face
flavicon
face
On Mon, 24 Jun 2002, Nick Veys wrote:

> Ok I'm guessing this is a painfully obvious, 5 second fix, but it's had
> me stumped for 2 evenings.

Which PIC are you using? PORTA is multiplexed with the comparators/A2D
converters on those devices that are equipped with them. By default, the
analog peripheral takes precedence.

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu


2002\06\25@011417 by Pic Dude

flavicon
face
Nick,

I just plugged this into the sim, and got the same
problem with only RA5 blinking.  However, I added
these 2 code lines and it worked properly...

       movlw   B'00000110'
       movwf   ADCON1          ; Port A all digital

Cheers,
-Neil.



{Original Message removed}

2002\06\25@012653 by Nick Veys

flavicon
face
Hmm, that's odd, but I'll remember that...  I fixed it by the
suggestions I got before w/the shadow register but I saved my previous
code and will give that quick-fix a try.

EraseMEnickspamveys.com | http://www.veys.com/nick

{Quote hidden}

>{Original Message removed}

2002\06\25@013700 by Pic Dude

flavicon
face
Still had that window open, so I'll save you some typing...
BTW, I generally use shadow registers as well -- this code
was just a quick test.

       LIST P=16F872
       INCLUDE "p16f872.inc"
       ERRORLEVEL -224
       __CONFIG _PWRTE_ON & _LP_OSC & _WDT_OFF & _LVP_OFF


       cblock  H'20'
         Delay1
         Delay2
       endc

MAIN:
       ;----- Bank 1 -----
       bcf     STATUS,RP1
       bsf     STATUS,RP0
       movlw   B'00000110'
       movwf   ADCON1          ; Port A all digital
       movlw   b'00000000'
       movwf   TRISA

       ;----- Bank 0 -----
       bcf     STATUS,RP0

loopage:
       bsf     PORTA,2
       bsf     PORTA,3
       bsf     PORTA,4
       bsf     PORTA,5

       movlw   D'2'
       movwf   Delay1
Loop1:
       decfsz  Delay1,F
       goto    Loop1

       bcf     PORTA,2
       bcf     PORTA,3
       bcf     PORTA,4
       bcf     PORTA,5

       movlw   D'2'
       movwf   Delay2
Loop2:
       decfsz  Delay2,F
       goto    Loop2

       goto    loopage

       end




{Original Message removed}

2002\06\25@035543 by Pic Dude

flavicon
face
Nick,

Found it... I usually setup everything explicitly in
my code, so I was not familiar with the power-on
defaults, but I just checked the 16F872 datasheet
and found the answer...

Table 2-1, in the Bank 1 section, shows that the
power-on default for ADCON1 is '0--- 0000'.  The
lowest 4 bits being the A/D setup of the PORT A
pins.  On page 80, the ADCON1 register setup page
shows '0000' for bits 3-0 to be Port A setup as all
analog.

I still can't explain why RA5 was different, but I
can see why the incorrect results.

Cheers,
-Neil.



{Original Message removed}

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