Doubt on RAx pins

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Doubt on RAx pins

John Coppens
Hello all,

After I finally got the gpasm project into mplabx (thanks for the help
with the linker scripts and .cinit issues!), I have a problem with
PORTA not changing in the simulator, when using bsf instructions.

I checked this:

1- The A/D converters are configures as b'00000111' (ADCON1)
2- The output pins are TRISA'd with b'11100001'

Both of these values checked with the mplabx simulator.

Then executing a bsf PORTA,1 or ,2 seems to have no effect in the
simulator.

I read I/O Pin Issues (TB3009), but as this is the simulator hardware
related problems shouldn't influence the sim...

As I used macros to define the bits, I even disassembled the code to be
sure the right bsf's are generated:

0004fb:  1485  bsf      0x5, 0x1
0004fc:  1505  bsf      0x5, 0x2
0004fd:  1585  bsf      0x5, 0x3

Any suggestions?
John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
ivp
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

ivp
> I have a problem with PORTA not changing in the simulator,
> when using bsf instructions

I assume from your other thread that you're using something
other than a 12F or 16F. Try LATA. PORTA is input

Joe
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

John Coppens
On Mon, 20 Aug 2012 10:14:27 +1200
IVP <[hidden email]> wrote:

> > I have a problem with PORTA not changing in the simulator,
> > when using bsf instructions
>
> I assume from your other thread that you're using something
> other than a 12F or 16F. Try LATA. PORTA is input

Hi Joe.

Nope the processor is a simple 16f874. I am doubting if I did something
wrong, or if the mplabx simulator doesn't rightly simulate port A (which
I doubt)

John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

John Coppens
In reply to this post by John Coppens
On Sun, 19 Aug 2012 18:21:18 -0300
John Coppens <[hidden email]> wrote:

                processor pic16f874

                include P16F874.INC

                cblock 0x20
testvar
                endc

                org 0

                banksel TRISA
                movlw b'00000111' ; Tried both 6 and 7
                movwf ADCON1

                movlw b'00111001'
                movwf TRISA

                clrf TRISB


                banksel PORTA
                bsf PORTA,1 ; These seem to have no effect
                bsf PORTA,2

                bsf PORTB,3 ; This does work

                bsf testvar,2 ; This too, of course

                end
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
ivp
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

ivp
> banksel PORTA
> bsf PORTA,1 ; These seem to have no effect
> bsf PORTA,2

Does your bsfing work with a real chip ?
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

John Coppens
On Mon, 20 Aug 2012 13:42:03 +1200
IVP <[hidden email]> wrote:

> Does your bsfing work with a real chip ?

Sorry for the delay... Family presence was required...

Ok. Modified the code a little (added a loop) and yes, it works on the
PIC itself. Seems the simulator isn't doing so well after all.

I was hoping I had done something wrong as I now have to return to the
original (larger) project which doesn't work yet.

John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

Gál Zsolt
Hello,

I would say first, I never used mplabx simulator.
Your problem with example could be according the READ-MODIFY-WRITE
sequence. I used to define a shadow register in the shared area to
avoid this problem.
I had a lot of misterious problem before I started to use shadow
register. Here is a simple example to showing it:

...

SHADOWREGISTERS  UDATA_SHR

PORTAOUT   res 1

...

banksel PORTA

bsf    PORTAOUT,0
movf  PORTAOUT,w
movwf PORTA

bsf    PORTAOUT,1
movf  PORTAOUT,w
movwf  PORTA

...
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

Jan-Erik Söderholm
When it comes to RMW, it should only be a problem with
regards to pins configed as analog input. They always
(also in SIM) reads as "0". SIM doesn't have any timing
issues as when you have a pin connected to something
physical that delays the switch (capacitive load). I do
not think that SIM can simulate capacitive loads.

The code as-is simulates perfectly well in MPLAB8/MPSIM.

For clearity and to not have to check the datasheet, it
it better to use the correct register to banksel :

...
banksel TRISA
movlw   b'00000111'   ; Tried both 6 and 7
movwf   ADCON1
...

In this case TRISA and ADCON1 happends to be in the
same bank. Maybe you knew that, I didn't and had to
check with the datasheet...

 > > I had a lot of misterious problem...

RMW issues can always be explained. :-)


Jan-Erik.


Gál Zsolt wrote 2012-08-20 09:38:

> Hello,
>
> I would say first, I never used mplabx simulator.
> Your problem with example could be according the READ-MODIFY-WRITE
> sequence. I used to define a shadow register in the shared area to
> avoid this problem.
> I had a lot of misterious problem before I started to use shadow
> register. Here is a simple example to showing it:
>
> ...
>
> SHADOWREGISTERS  UDATA_SHR
>
> PORTAOUT   res 1
>
> ...
>
> banksel PORTA
>
> bsf    PORTAOUT,0
> movf  PORTAOUT,w
> movwf PORTA
>
> bsf    PORTAOUT,1
> movf  PORTAOUT,w
> movwf  PORTA
>
> ...
>
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

John Coppens
On Mon, 20 Aug 2012 10:34:17 +0200
Jan-Erik Soderholm <[hidden email]> wrote:

> The code as-is simulates perfectly well in MPLAB8/MPSIM.
>
> For clearity and to not have to check the datasheet, it
> it better to use the correct register to banksel :
>
> ...
> banksel TRISA
> movlw   b'00000111'   ; Tried both 6 and 7
> movwf   ADCON1
> ...
>
> In this case TRISA and ADCON1 happends to be in the
> same bank. Maybe you knew that, I didn't and had to
> check with the datasheet...
>
>  > > I had a lot of misterious problem...
>
> RMW issues can always be explained. :-)

Jan-Erik, Gál:

Yes, I had read about the RMW. I also read that in fact all operations
on the ports are implemented as RMW. But I considered this was not an
issue here as the pins were pure digital I/O, and I didn't consider
capacitive loading in the simulator.

The banksel has the wrong instruction, because at the last moment, I
switched the ADCON1 and TRISB initialization to do a test in that order.
The larger code is somewhat time-critical, and I am quite aware about
the banks, and try to limit the bankswitching to a minimum.

The problem is that the simulator doesn't show the bits set in port A,
so I can't debug my original project which seems to have a error there.
Maybe this is a Linux-specific problem, or a 64-bit problem... Here's
the movie (~1.5MB):

http://jcoppens.com/misc/test-0000.mpeg

(I used F8 to step, as the button is covered with the PC/Status info)

John


--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

John Coppens
On Mon, 20 Aug 2012 11:37:26 -0300
John Coppens <[hidden email]> wrote:

> The problem is that the simulator doesn't show the bits set in port A,
> so I can't debug my original project which seems to have a error there.
> Maybe this is a Linux-specific problem, or a 64-bit problem...

Anyway, I'm sure enough I didn't do any large mistakes, so I submitted
a ticket at Microchip #234645.

John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

RE: Doubt on RAx pins

David Meiklejohn
In reply to this post by John Coppens
You probably need to disable comparator inputs as well as ADC.  Comparator
inputs will read as '0', regardless of what you're outputting on the digital
pin.  I.e. pin goes high externally, but internally a port read will return
a '0' on enabled analog inputs, whether they are ADC or comparator.

I think you'll find that the simulator is correctly showing what a port read
would return.


Regards,
David Meiklejohn



John Coppens wrote

> Sent: Monday, 20 August 2012 11:09 AM
> To: [hidden email]
> Subject: Re: [PIC] Doubt on RAx pins
>
> On Sun, 19 Aug 2012 18:21:18 -0300
> John Coppens <[hidden email]> wrote:
>
> processor pic16f874
>
> include P16F874.INC
>
> cblock 0x20
> testvar
> endc
>
> org 0
>
> banksel TRISA
> movlw b'00000111' ; Tried both 6 and 7
> movwf ADCON1
>
> movlw b'00111001'
> movwf TRISA
>
> clrf TRISB
>
>
> banksel PORTA
> bsf PORTA,1 ; These seem to have no effect
> bsf PORTA,2
>
> bsf PORTB,3 ; This does work
>
> bsf testvar,2 ; This too, of course
>
> end
> --
> http://www.piclist.com PIC/SX FAQ & list archive View/change your
> membership options at http://mailman.mit.edu/mailman/listinfo/piclist

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

RE: Doubt on RAx pins

David Meiklejohn
Ah - silly me!  Should check first and write later, not the other way
around!  There's no comparator on the 16F874...
It seems that you're doing everything you need to, to disable analogs.
Sorry!


I wrote:

>
>
> You probably need to disable comparator inputs as well as ADC.
> Comparator inputs will read as '0', regardless of what you're
> outputting on the digital pin.  I.e. pin goes high externally, but
> internally a port read will return a '0' on enabled analog inputs,
> whether they are ADC or comparator.
>
> I think you'll find that the simulator is correctly showing what a port
> read would return.


--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

John Coppens
On Tue, 21 Aug 2012 10:26:01 +1000
"David Meiklejohn" <[hidden email]> wrote:

> Ah - silly me!  Should check first and write later, not the other way
> around!  There's no comparator on the 16F874...
> It seems that you're doing everything you need to, to disable analogs.
> Sorry!

:-)  Thanks anyway, David!

The fact is that in the actual chip, the program works, but not in the
simulator... Still no feedback from the bug list though.

John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

RE: Doubt on RAx pins

David Meiklejohn
John Coppens wrote:

>
> On Tue, 21 Aug 2012 10:26:01 +1000
> "David Meiklejohn" <[hidden email]> wrote:
>
> > Ah - silly me!  Should check first and write later, not the other way
> > around!  There's no comparator on the 16F874...
> > It seems that you're doing everything you need to, to disable
> analogs.
> > Sorry!
>
> :-)  Thanks anyway, David!
>
> The fact is that in the actual chip, the program works, but not in the
> simulator... Still no feedback from the bug list though.

The reason I (mistakenly) pointed to comparators is that I've been caught by
what looks like a similar issue - where the PIC's outputs are demonstrably
changing on actual hardware (e.g. LEDs are blinking), but the simulator
shows the same pins stuck on '0'.  But when I've scratched my head over
that, I've found that actually the simulator was correct - the pin was
reading 0, despite working correctly as a digital output and the output
being high.  Not due to RWM, nor external pin loading, but because when
configured as a comparator input it will read as '0', as per the data sheet.

Anyway, good luck with it!


David


--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Doubt on RAx pins

John Coppens
On Tue, 21 Aug 2012 12:20:51 +1000
"David Meiklejohn" <[hidden email]> wrote:

> The reason I (mistakenly) pointed to comparators is that I've been caught by
> what looks like a similar issue - where the PIC's outputs are demonstrably
> changing on actual hardware (e.g. LEDs are blinking), but the simulator
> shows the same pins stuck on '0'.  But when I've scratched my head over
> that, I've found that actually the simulator was correct - the pin was
> reading 0, despite working correctly as a digital output and the output
> being high.  Not due to RWM, nor external pin loading, but because when
> configured as a comparator input it will read as '0', as per the data sheet.

David,

There is actually a very complete document on possible pin issues in
the Microchip library (TB3009). It describes the comparator, AD and
several others.

I wish I had know about that info about a year ago when I bashed my
head with the A/D being default on part A issue.

John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist