Searching \ for 'Problem with CLRF PORTB istruction ...' 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/ios.htm?key=port
Search entire site for: 'Problem with CLRF PORTB istruction ...'.

Truncated match.
PICList Thread
'Problem with CLRF PORTB istruction ...'
1998\08\19@113052 by Alessandro Marzini

flavicon
face
Hello!

I would to know if this code:

LOOP

       bsf     PORTB,0
       bsf     PORTB,1
       bsf     PORTB,2
       bsf     PORTB,3
       bsf     PORTB,4
       bsf     PORTB,5
       bsf     PORTB,6
       bsf     PORTB,7

       <delay routine>

       bcf     PORTB,0
       bcf     PORTB,1
       bcf     PORTB,2
       bcf     PORTB,3
       bcf     PORTB,4
       bcf     PORTB,5
       bcf     PORTB,6
       bcf     PORTB,7

       <delay routine>

       goto    LOOP

..is the same of this:

LOOP
       movlw   0xFF
       movwf   PORTB

       <delay routine>

       clrf    PORTB

       <delay routine>

       goto    LOOP

...because in the first codes all works well, is the second codes, I have
problem with time of delay, time of LED OFF is not equal of time LED ON...

Some one can help me???

Thank you!

---

Alessandro Marzini    Amiga Group Italia - LIVORNO
                     -------------------------------------------
Email  a.marzini      A3000T PPC604@233 040@40 78Mb RAM
Phone  0347 7687788   Rom 3.1 Super Buster 11
                     Cybervision 64 3D -
                     Peggy Plus - PhonePak GVP - DKB4091
                     Scanner Epson GT-9000 - CDR Plexwriter 4/12
                     CDROM Plextor 12x - ZIP 100Mb - USR 33.6K
                     Epson Stylus Color 500 - 2 HD SCSI 1Gb
                     -------------------------------------------

--

1998\08\19@130122 by Jan Derogee

flavicon
face
Hello Thomas,
your first example is slower then the second (with the clrf) only use this
instruction if you realy want to change the state of each bit individually.
Second if you want to make a smaller program use the second example its also
is easier to read. If you want to tune your timing use NOP instructions.
NOP means N OPeration it is a one cycle instruction that does nothing but
consume one cycle of your CPU-time. By the way in a PIC almost al instr.
are one cycle.


You wrote :
{Quote hidden}

1998\08\19@174822 by Dmitry Kiryashov

flavicon
face
Hello Alessandro Marzini.

> LOOP
>         movlw   0xFF
>         movwf   PORTB

2 clocks are carring out

>         <delay routine>
>
>         clrf    PORTB

1 clock is carring out and zero flag in STATUS is set


>         <delay routine>
>
>         goto    LOOP

Carefully check your delay routine code. Probably you test zero
flag within it and second case with zero on input result to less/
/greater delay. For the other hand you may substitute second

       clrf    PORTB

with
       movlw   0
       movwf   PORTB

and check the result.

WBR Dmitry.

PS. Using bsf/bcf instructions on real i/o port is definitly not
   recommended. In situation with mixing in and out pins on the
   same port it may result to writing to port undesirable value.
   This also related to any Read/Modify/Write_back commands.
   It will be better to use shadow register and only write to
   port output value with reading from shadow.

1998\08\19@175010 by andre

flavicon
face
Alessandro Marzini wrote:

{Quote hidden}

sure.

in your first example you used 8 BSF   and  8 BCF
since I do not know your delay time
assuming you are using 4 Mhz clock and there is no delay
4000000/4=1000000/(8+8)=62500 microseconds
4000000/4=1000000/(2+1)=33333 microseconds
your positive and negative duty cycle ( on and off time) is the same.
but second example  for positive you used 2 cycle and negative 1 cycle only.
To
fix this assuming you want to make it like first one add 6 NOP after movwf
portb
and 7 NOP after clrf portb. then you all set.


Andre  Abelian


> Thank you!
>

1998\08\19@180302 by paulb

flavicon
face
Hello Alessandro.

 As has been stated, the obvious difference is that your second code
has less delay, so the assymetry in timing is more evident.  It very
much depends on your delay routine.  BTW, are you *sure* you wrote the
same delay routine in both halves? ;-)

{Quote hidden}

 Here, both the extra "movlw $FF" and the "goto LOOP" are delaying the
same half of the routine.  If I wanted symmetry; I would write it as:

LOOP
       movlw   $0
       call    pbdelay
       goto    $+1

       movlw   $FF
       call    pbdelay
       goto    LOOP

pbdelay movwf   PORTB
    <delay stuff>
       ret

 .. which is, incidentally, shorter!
--
 Cheers,
       Paul B.

1998\08\20@050513 by Alessandro Marzini

flavicon
face
>> LOOP
>>         movlw   0xFF
>>         movwf   PORTB
>>         <delay routine>
>>
>>         clrf    PORTB
>>         <delay routine>
>>
>>         goto    LOOP

>Carefully check your delay routine code. Probably you test zero
>flag within it and second case with zero on input result to less/
>/greater delay. For the other hand you may substitute second

This is my delay routine...Can you correct me where I wrong?

DEL2MS
       movf    RTCC,0
       btfss   STATUS,Z    <----Is this the problem?
       goto    DEL2MS
       movlw   128
       movwf   RTCC
       return

DELXMS  movwf   XMS
DELOOP  call    DEL2MS
       decfsz  XMS
       goto    DELOOP
       return

Thank you very much!
Bye.


---

Alessandro Marzini    Amiga Group Italia - LIVORNO
                     -------------------------------------------
Email  a.marzini      A3000T PPC604@233 040@40 78Mb RAM
Phone  0347 7687788   Rom 3.1 Super Buster 11
                     Cybervision 64 3D -
                     Peggy Plus - PhonePak GVP - DKB4091
                     Scanner Epson GT-9000 - CDR Plexwriter 4/12
                     CDROM Plextor 12x - ZIP 100Mb - USR 33.6K
                     Epson Stylus Color 500 - 2 HD SCSI 1Gb
                     -------------------------------------------

--

1998\08\20@050715 by Alessandro Marzini

flavicon
face
part 0 1826 bytes

{Quote hidden}

Well, I exchange

       clrf    PORTB
with
       molw    0
       movwf   PORTB

but a strange thing happen....

LEDs flash in the same manner only if I cortocircuit the 10K resistor on the
MCLR PIN to +5 V. If not, LEDs flash but with no correct delay as described in
my routine... WHY ?!?!

If I use bcf and bsf to flash on/off my LEDs, all work well...WHY ?!?!

I attached a .jpg scheme of my little project, can you help me?

Thank you.


---

Alessandro Marzini    Amiga Group Italia - LIVORNO
                     -------------------------------------------
Email  a.marzini      A3000T PPC604@233 040@40 78Mb RAM
Phone  0347 7687788   Rom 3.1 Super Buster 11
                     Cybervision 64 3D -
                     Peggy Plus - PhonePak GVP - DKB4091
                     Scanner Epson GT-9000 - CDR Plexwriter 4/12
                     CDROM Plextor 12x - ZIP 100Mb - USR 33.6K
                     Epson Stylus Color 500 - 2 HD SCSI 1Gb
                     -------------------------------------------

--

Attachment converted: wonderland:LED.jpg (JPEG/JVWR) (000142B7)

1998\08\20@053656 by Mike Ghormley

flavicon
face
Alessandro Marzini wrote:

> LEDs flash in the same manner only if I cortocircuit the 10K resistor on the
> MCLR PIN to +5 V. If not, LEDs flash but with no correct delay as described in
> my routine... WHY ?!?!

It is *very* late here but when I glanced at your JPG the first thing that jumpe
d
out at me is the unconnected pins.  As you probably already know, CMOS devices c
an
have unexpected behavior with a floating input pin.  I would check for this firs
t.

Just a thought.  I hope it helps.

Michael

*************************************************************************
When the way of the Tao is forgotten, kindness and ethics must be taught.
Men must learn to pretend to be wise and good.  --  Lao Tzu
*************************************************************************

1998\08\20@072632 by John Haggins

picon face
I'm only a beginner, but I notice you don't have any resistors on pins
1,2,17,18 - this will cause problems if these pins are inputs. All inputs
need to be connected to the power (via resistor like you've done on pin 3)
Alternatively, make the pins outputs to avoid using resistors.

John

At 10:57 AM 8/20/98 +0100, you wrote:
{Quote hidden}

described in
{Quote hidden}

1998\08\20@081526 by mjb

flavicon
face
> >LEDs flash in the same manner only if I cortocircuit the 10K resistor on the
> >MCLR PIN to +5 V. If not, LEDs flash but with no correct delay as
> described in
> >my routine... WHY ?!?!
> >
> >If I use bcf and bsf to flash on/off my LEDs, all work well...WHY ?!?!
> >
> >I attached a .jpg scheme of my little project, can you help me?

A very important thing that is missing is the decoupling capacitor across the
power pins on the PIC.  Because of the way CMOS works, it requires huge slugs
of current when switching, but for very small times.

What size? That can be a difficult question to answer, since it depends
on a lot of different factors, such as the clock speed and the type of
capacitor you are using.  I usually use a good quality .1 or .22 uF
soldered directly to the pins of the socket, making sure the wires to
the capacitor are as short as possible.


-----------------------------
Matt Bennett                |
spam_OUTmjbTakeThisOuTspamhazmat.com              |
http://www.hazmat.com/~mjb/ |

1998\08\20@083535 by paulb

flavicon
face
Alessandro Marzini wrote:

> This is my delay routine...Can you correct me where I wrong?

 Looks fine as fas as I can see, *presuming* that you are loading
the same value into W *each time* before you call DELXMS.  If you called
DELXMS from the code you posted before, it would enter one time with the
value $FF from the "set" PORTB routine, and the other with the $80 from
the previous DEL2MS invocation.

 Since your timing is locked to the RTCC, the previously discussed
differences in the machine cycles are insignificant.

{Quote hidden}

 Ah!  That«s easy.  If you use individual BCF and BSFs, the distributed
capacitance coupling to the MCLR pin is only that of individual port
pins.  If you use the movlw PORTB, all port pins change at once and the
distributed capacitance is over eight times greater.

 A common trick on timing programs which appear to work but in a
bizarre fashion is that a particular step in the program is capacitively
resetting the MCLR.

 *Epecially* on a solderless breadboard with high inter-pin cpacitance.
I only just proved this to myself with my first breadboarded experiment
with the AVR AT90S1200.  Terminate MCLR always, set unused pins as
outputs.
--
 Cheers,
       Paul B.

1998\08\20@115329 by Dmitry Kiryashov

flavicon
face
Hello Alessandro Marzini.

> This is my delay routine...Can you correct me where I wrong?
>
> DEL2MS
>         movf    RTCC,0
>         btfss   STATUS,Z    <----Is this the problem?
>         goto    DEL2MS
>         movlw   128
>         movwf   RTCC
>         return
>
> DELXMS  movwf   XMS
> DELOOP  call    DEL2MS
>         decfsz  XMS
>         goto    DELOOP
>         return

Very impressive code ;-)
Why not to rewrite this code to the following one:
(seems to be you apply no prescaler for RTCC ? )

DELXMS:
       movlw   D'125'  ;125 + 2 + 1 = 128
       movwf   RTCC    ;don't forget about 2 cloocks delay
                       ;after loading the RTCC - read RTCC
                       ;datasheet section more carefully
       goto    $+1     ;delay for RTCC update

       incfsz  RTCC,W
       goto    $-1
       return


{Quote hidden}

Probably I misunderstand something .. Did you told me that you don't
pullup MCLR
pin to +5 and your device is still working ? ;-) Another thing I don't
see in your
schematic is capacitors between +5 and gnd. Try to add two of it.
One is 0.1 - 0.22 mkF (ceramic) to cancel HF noises and second is 100.0
mkF .

You should tell youself that you device switch the current consumption
from 5 ma
upto 125 ma when all LD are on. For this reason check also power supply
circuit.

Also I misunderstood which for 10K resistor between TOCKI and +5 is
applied ?
If you don't plan to use this pin as output you don't need this
resistor.

WBR Dmitry.

1998\08\20@191721 by Tony Nixon

flavicon
picon face
Alessandro Marzini wrote:

> I attached a .jpg scheme of my little project, can you help me?

I looked at your jpg file. I would change the 220R resistors to
something a little higher like 2K2. You are sourcing 22mA into each LED
which are normally rated at 20mA.

Have you got the WatchDog enabled?

>        movf    RTCC,0
>        btfss   STATUS,Z    <----Is this the problem?
>        goto    DEL2MS

I don't know what TMR0 prescaler value you have but you may miss RTCC =
0 on occassion.

Why not use this instead.

WaitHere    BTFSS INTCON,T0IF
           GOTO WaitHere

           BCF INTCON,T0IF

           Do Flashy stuff here

           GOTO WaitHere

Hope this helps.

--
Best regards

Tony

Multimedia 16F84 Beginners PIC Tools.
**New PicNPrac**

http://www.picnpoke.com
Email .....picnpokeKILLspamspam@spam@cdi.com.au

1998\08\21@163330 by Alessandro Marzini

flavicon
face
>> LEDs flash in the same manner only if I cortocircuit the 10K resistor
>> on the MCLR PIN to +5 V. If not, LEDs flash but with no correct delay
>> as described in my routine... WHY ?!?!

>> If I use bcf and bsf to flash on/off my LEDs, all work well...WHY ?!?!

>  Ah!  That4s easy.  If you use individual BCF and BSFs, the distributed
>capacitance coupling to the MCLR pin is only that of individual port
>pins.  If you use the movlw PORTB, all port pins change at once and the
>distributed capacitance is over eight times greater.

>  A common trick on timing programs which appear to work but in a
>bizarre fashion is that a particular step in the program is capacitively
>resetting the MCLR.

>  *Epecially* on a solderless breadboard with high inter-pin cpacitance.
>I only just proved this to myself with my first breadboarded experiment
>with the AVR AT90S1200.  Terminate MCLR always, set unused pins as
>outputs.

YES!

I use for my experiment a solderless breadboard!
Infact if I connect MCLR pin direct to +5V, all work well also with clrf
PORTB!

Thanks a lot to this!

Bye

---

Alessandro Marzini    Amiga Group Italia - LIVORNO
                     -------------------------------------------
Email  a.marzini      A3000T PPC604@233 040@40 78Mb RAM
Phone  0347 7687788   Rom 3.1 Super Buster 11
                     Cybervision 64 3D -
                     Peggy Plus - PhonePak GVP - DKB4091
                     Scanner Epson GT-9000 - CDR Plexwriter 4/12
                     CDROM Plextor 12x - ZIP 100Mb - USR 33.6K
                     Epson Stylus Color 500 - 2 HD SCSI 1Gb
                     -------------------------------------------

--

1998\08\21@163339 by Alessandro Marzini

flavicon
face
{Quote hidden}

Ehm...sorry...But I'm a beginner... :-|

> Another thing I don't see in your schematic is capacitors between +5 and
> gnd. Try to add two of it. One is 0.1 - 0.22 mkF (ceramic) to cancel HF
> noises and second is 100.0 mkF .

YEAH! After I added one capacitors (104.0 mkF ceramic) between GND and +5V all
work well also with clrf PORTB !!

Can you explain to me with simple words what a decoupling is? Thank you...


>You should tell youself that you device switch the current consumption
>from 5 ma
>upto 125 ma when all LD are on. For this reason check also power supply
>circuit.

5ma when LEDs are off?

(15ma x 8) + 5ma when LEDs are all on?

...so one single LED consumes 15ma?

>Also I misunderstood which for 10K resistor between TOCKI and +5 is
>applied ?
>If you don't plan to use this pin as output you don't need this
>resistor.

Done!

>WBR Dmitry.

Thank you a lot for your info!!

bye.

---

Alessandro Marzini    Amiga Group Italia - LIVORNO
                     -------------------------------------------
Email  a.marzini      A3000T PPC604@233 040@40 78Mb RAM
Phone  0347 7687788   Rom 3.1 Super Buster 11
                     Cybervision 64 3D -
                     Peggy Plus - PhonePak GVP - DKB4091
                     Scanner Epson GT-9000 - CDR Plexwriter 4/12
                     CDROM Plextor 12x - ZIP 100Mb - USR 33.6K
                     Epson Stylus Color 500 - 2 HD SCSI 1Gb
                     -------------------------------------------

--

1998\08\21@163345 by Alessandro Marzini

flavicon
face
>> >LEDs flash in the same manner only if I cortocircuit the 10K resistor on
>> >the MCLR PIN to +5 V. If not, LEDs flash but with no correct delay as
>> described in
>> >my routine... WHY ?!?!
>> >
>> >If I use bcf and bsf to flash on/off my LEDs, all work well...WHY ?!?!
>> >
>> >I attached a .jpg scheme of my little project, can you help me?

>A very important thing that is missing is the decoupling capacitor across the
>power pins on the PIC.  Because of the way CMOS works, it requires huge slugs
>of current when switching, but for very small times.

>What size? That can be a difficult question to answer, since it depends
>on a lot of different factors, such as the clock speed and the type of
>capacitor you are using.  I usually use a good quality .1 or .22 uF
>soldered directly to the pins of the socket, making sure the wires to
>the capacitor are as short as possible.

Well, thank you very much for the info!

Infact now all works perfectly with a capacitors of 104!

Can you explain me how decoupling process is? I'm a beginner... :-|

Thank you very much again, bye!

---

Alessandro Marzini    Amiga Group Italia - LIVORNO
                     -------------------------------------------
Email  a.marzini      A3000T PPC604@233 040@40 78Mb RAM
Phone  0347 7687788   Rom 3.1 Super Buster 11
                     Cybervision 64 3D -
                     Peggy Plus - PhonePak GVP - DKB4091
                     Scanner Epson GT-9000 - CDR Plexwriter 4/12
                     CDROM Plextor 12x - ZIP 100Mb - USR 33.6K
                     Epson Stylus Color 500 - 2 HD SCSI 1Gb
                     -------------------------------------------

--

1998\08\21@165143 by William Chops Westfield

face picon face
   Can you explain me how decoupling process is? I'm a beginner... :-|

When gates within a chip switch states, there are momentary and very short
periods of time where much higher than normal "operating current" is
required.  The frequencies are such that the wires that connect the chip to
its power supply begin to look like "significant" inductors, which do not
permit a rapid change in current flow in time.  Ie - the chip needs more
power for a nanosecond or two, and it can't get "all the way from the power
supply" in time to prevent voltage drops and erratic behavior.

A bypass capacitor NEAR the chip provides the needed current pulses, and
recharges in between them - a sort of local "tank" for extra power.
Traditionally, caps are somewhere between 0.01uF and .1uF for "normal"
chips, although I think there are multi-page application notes written on
the bypassing requirements for big chips with high power consumption (like
you pentiums and such.)

BillW

1998\08\21@170443 by Mike Keitz

picon face
On Fri, 21 Aug 1998 11:21:39 +0100 Alessandro Marzini <a.marzinispamKILLspamIOL.IT>
writes:

>Can you explain to me with simple words what a decoupling is? Thank
>you...

A decoupling capacitor is a capacitor from the power supply to ground.
In operation, the various devices on the power supply line draw varying
amounts of current.  Becuase of resistance and inductance inherent in the
power and ground wiring, varying load current tends to cause an AC
voltage to appear on the power supply lines.  If this voltage gets high
enough, the circuit will malfunction.  A capacitor shunts this voltage to
ground, resulting in a "cleaner" power supply.  For best results, many
capacitors are used, with each one located as close to a load (IC chip)
as possible so that the resistance and inductance of the wiring don't
diminish it's effect.

The advice to use two values of capacitors in parallel is because
(inexpensive) large capacitors often have a lot of internal inductance,
thus a high impedance to high frequency signals.  A small capacitor
combined with a large one extends the frequency range of signals that
will be effectively suppressed (passed to ground).  Since the large
capacitor is only for low frequency signals, the inductance of the wiring
doesn't affect it as much.  Only a few large capacitors are needed per
circuit board, combined with many small capacitors placed near the ICs.

The name "decoupling capacitor" is likely derived from the capacitor's
ability to prevent undesired signals from coupling from one part of the
circuit to another through the power supply.


_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

1998\08\21@172356 by Dmitry Kiryashov

flavicon
face
Alessandro Marzini wrote:

> Can you explain to me with simple words what a decoupling is? Thank you...

I'll try. Every  wire  has  inductance.  PCB  wires has inductance too.
When  current  consumption  is changed  rapidly it may  result to local
voltage  spike  that  will  put  the  PIC out of  normal voltage range.
To prevent  this  you need to  apply  ceramic  capacitor  because  this
capacitor  has  low inductance and able to  compensate  voltage spikes.
You  need  to  place  this  capacitor  as  tight  as possible  to power
supplying pins of PIC.  To prevent  low frequency  changes of supplying
voltage  you  should apply also another capacitor.  Practically ceramic
capacitor is placed on every CMOS chip while large capacitor is applied
on every 10..20 of CMOS devices. To learn this question more please
read any literature about CMOS devices.


> 5ma when LEDs are off? (15ma x 8) + 5ma when LEDs are all on?
> ...so one single LED consumes 15ma?

(5v - 1.8v )/220R ~= 15 mA

where 1.8v is LD drop voltage ( red light LD , in case of green LD this
voltage is equal approx. to 2.2 - 2.4v)

BTW you may reduce the current through LD. For this purpose apply
greater
resistors for instance from 1KOhm upto 3.3KOhm range. All LDs has
approx.
equal light emission for the some initial current. If you'll increase
the
current the brightness will be not increased too.

WBR Dmitry.

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