Searching \ for '[PIC]: Frustration with TRISB' 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/devices.htm?key=pic
Search entire site for: 'Frustration with TRISB'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Frustration with TRISB'
2001\01\06@035545 by Peter L.

flavicon
face
I'm trying to program an alarm clock with a PIC16F84. Unfortunately I've had
some trouble getting my buttons to work.

Consider the simple code below. Each pin on portb is connected to a switch
that grounds that pin through a 2k2 resistor on user interaction, and a
suitable current limited LED (actually, part of a common-cathode
7-segment+dot display).

Please ignore the code before the start: label. FYI, The external circuitry
is such that the common-cathodes are grounded through raising bit0 on porta.

Now, the code is straightforward, here's what it's meant to do
a) Tristate PortB
b) Read the status of the switches (where a bit is low if the corresponding
switch is being     pressed)
c) Push that data back out onto the PortB latches
d) Reenable the output (un-tristate it), so the LED's are driven according
to the switches         (inverted)
e) Keep repeating forever

The problem seems to be that the switches don't get read properly unless not
one, but two nop's are executed after the tristate instruction before the
port is read.

I've tried decoupling the supplies, and the usual transient prevention
tricks, but to no avail.

Is it normal to have to wait before reading newly tristated pins?
The clock speed is 3.12Mhz.


Thanks for any info you can provide

BTW I'm new to this list, so please forgive me if I've broken any of your
protocols.


Peter L

spam_OUTnewmannzTakeThisOuTspamihug.co.nz

-------------------------

list p=16f84
include "p16f84.inc"

reg_1 equ 0Ch

   org  H'00'

setup:
   bsf STATUS,RP0
   bcf OPTION_REG,7    ;Enable portb pullups
   clrf TRISA  ;Set PORTA for output
   bcf STATUS,RP0

   movlw H'01'
   movwf PORTA  ;Select LED array

start:
   movlw B'11111111'
   tris PORTB  ;Set PORTB for input

   nop   ;****indispensable delay****
   nop

   movf PORTB,W  ;Read into W
   movwf PORTB  ;Write back to PORT (i.e. load output latches)

   movlw B'00000000' ;Return PORTB to output mode
   tris PORTB  ;(Release the latches)

   nop   ;Make the LED's brighter
   nop
   nop
   nop
   nop
   nop

   goto start
   end

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


2001\01\06@042740 by Andrew Warren

face
flavicon
face
Peter L. <PICLISTspamKILLspamMITVMA.MIT.EDU> wrote:

> Each pin on portb is connected to a switch that grounds that pin
> through a 2k2 resistor on user interaction
> ....
> [enable weak pullups on port B, then:]
> a) Tristate PortB
> b) Read the status of the switches (where a bit is low if the
> corresponding switch is being pressed)
> c) Push that data back out onto the PortB latches
> d) Reenable the output (un-tristate it), so the LED's are driven
> according to the switches (inverted)
> e) Keep repeating forever
>
> The problem seems to be that the switches don't get read properly
> unless not one, but two nop's are executed after the tristate
> instruction before the port is read.

Peter:

Put a scope on your port B inputs.  See how gently-sloped the edges
are? That's why you have to wait.

If you want the edges to be sharper, don't use the (weak) internal
pullups with external 2.2Ks to ground; instead, disable the internal
pullups, then reconfigure your resistors and switches so the external
2.2Ks are used as pullups and the switches pull the port B pins
directly to ground.

-Andy


=== Andrew Warren - .....fastfwdKILLspamspam.....ix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

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


2001\01\06@092554 by Drew Vassallo

picon face
>If you want the edges to be sharper, don't use the (weak) internal
>pullups with external 2.2Ks to ground; instead, disable the internal
>pullups, then reconfigure your resistors and switches so the external
>2.2Ks are used as pullups and the switches pull the port B pins
>directly to ground.

Good advice.  Though anything slower than a 4MHz clock can probably use a
4.7K or maybe even 10K as pull-ups to save current draw, depending on how
long/often the switches are used, without being so slow to pull down that
you have to wait another cycle.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

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


2001\01\06@172634 by Peter L.

flavicon
face
----- Original Message -----
From: "Andrew Warren" <@spam@fastfwdKILLspamspamIX.NETCOM.COM>
.....
> Peter:
>
> Put a scope on your port B inputs.  See how gently-sloped the edges
> are? That's why you have to wait.
>
> If you want the edges to be sharper, don't use the (weak) internal
> pullups with external 2.2Ks to ground; instead, disable the internal
> pullups, then reconfigure your resistors and switches so the external
> 2.2Ks are used as pullups and the switches pull the port B pins
> directly to ground.
>
> -Andy
>

I see. Thanks for the suggestion. Unfortunately I can't implement it,
because the port is shared between driving LED's and monitoring the bank of
switches. Connecting the portB pins directly to ground through a switch
would cause the output latches to be overloaded when a switch is pressed
while the port is set for output (to drive the LED's). Not to mention the
blanking of segments every time a switch connected to a corresponding bit is
pressed.

Something I can try, is the use of external 4k7 pullups on all eight port
lines. The switches would then act through grounded 330R resistors. - In
fact, because the outputs source current to drive the C-C LED's, it might be
better to constantly pull the pins down through 4k7's, and configure the
switches to pull-up through 330R's when pressed.

In the meantime though, I'm content with a bit of software delay. Not
elegant, but certainly workable.

Peter L.

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


2001\01\06@232833 by Alejandro

picon face
Only a suggestion.... why do not use a kind of port expansion?
It sounds like the PORTB is heavy used... perhaps a 4094 (or 74HC595)
can help to obtain extra outputs... or a 74HC161 can give extra inputs...


{Original Message removed}

2001\01\07@015335 by Roman Black

flavicon
face
I try and avoid switching pins between input
and output whenever I can. What I do prefer
is to matrix a bank of inputs and outputs,
so with 4 input pins and 7 output pins you
can run a 7 seg display and 28 pushbuttons.
Like most matrixing only one pushbutton can
be sensed at one time. However by adding
28 diodes you can have 28 switches which
can all be read at once, for dip switches
etc.

I have one product that has 16 dipswitches,
a 7 seg display, and a couple of input/outputs
all running off a 16F84 with no other chips.
And it doesn't switch pin states between
in/out. :o)
-Roman



Peter L. wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


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