BASICchip IO ports

Questions about the BASICtools and MakeItC
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BASICchip IO ports

Post by YahooArchive »

> While I'm not suggesting it, I was curious how fast the brute force would be--

> while x
> y=(IN(39) and 128)+(IN(38) and 64)+(IN(37) and 32)+(IN(36) and 16)+(IN(35) and
8)+(IN(34) and 4)+(IN(33) and 2)+(IN(32) and 1)

====
Hi All,

The line above gets a value of the port by reading the bits in sequence, not in
one single read, so it is not a like-for-like comparison with a port-wide read.

If the port was connected to, say, a hardware counter of some kind, even a few
uS between reading two bits could give a false reading.

Port-wide reading is a must !.

Slightly OT, but in a similar vein, it was me who discovered the timer read flaw
in the PICAXE, another issue caused by piecewise reading a hardware counter.

Cheers,

Buzby



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BASICchip IO ports

Post by YahooArchive »

Did you get the code I sent you earlier today?

cp

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BASICchip IO ports

Post by YahooArchive »

Yep, and it works !.

Now onto next issue.

I've got a 0.5Hz squarewave coming in on P1(5), and the code you gave is reading
the full p1 port ( I think ).

My code here should print only when it sees a change on P1.

It prints a lot continuously, not just when the squarewave changes.

I think the problem is that TXD / RXD are part of P1, and that somehow one of
them is affecting the port read.

How do I mask out these bits ?

CODE ======================================

'Lets assume you want to use all of Port 1.

#include

'First you have to convert the A/D pins into Digital IO.

x = IO(11) ' make AD(0) an IO input
x = IO(32) ' make AD(1) an IO input
x = IO(33) ' make AD(2) an IO input
x = IO(34) ' make AD(3) an IO input
x = IO(35) ' make AD(4) an IO input
x = IO(36) ' make AD(5) an IO input
' Then fix the firmware bug!
IOCON_PIO1_4 = &H90 ' convert AD(5) to digital input
IOCON_SWDIO_PIO1_3 = &H90 ' AD(4)
IOCON_R_PIO1_2 = &H91 ' AD(3)
IOCON_R_PIO1_1 = &H91 ' AD(2)
IOCON_R_PIO1_0 = &H91 ' AD(1)
IOCON_R_PIO0_11 = &H91 ' AD(0)



WHILE 1


rw = IO(37) ' Read single pin
tt = GPIO1_DATA ' Read port


if tt <> oldtt then
oldtt = tt
print rw, tt
endif


if RXD(0)<>-1 then END
LOOP

CODE END =============================================

Cheers,

Buzby

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BASICchip IO ports

Post by YahooArchive »

Sorry, I just realised I could mask after the read, but it would be better if it
was masked during the read.

Also, how do I post code and retain the formatting ?

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BASICchip IO ports

Post by YahooArchive »

> I've got a 0.5Hz squarewave coming in on P1(5), and the code you gave is
reading the full p1 port ( I think ).
>
> My code here should print only when it sees a change on P1.
>

Did you mean P1.5? If so try:

> WHILE 1>
>
> rw = IO(37) ' Read single pin
> tt = GPIO1_DATA ' Read port >
>
> if rw <> oldrw then
> oldrw = rw
> print rw, tt
> endif

Reading IO(37) is can be replaced with rw = tt AND (1<<5)

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BASICchip IO ports

Post by YahooArchive »

Hi pompey,

The 0.5Hz signal was just to put a change on P1, any pin.

The real project will have multiple inputs on P1, and I will read them all in
one go.

The code I posted was just so I could see the value print when any P1 pin
changed state.

The surprise was that it prints more values than it should.
It looks like its something to do with RXD/TXD which I think are on the same P1
port. I'll just mask them out.

Cheers,

Buzby

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BASICchip IO ports

Post by YahooArchive »

Just noticed this in a previous post :

"In order to make it easier for 'axers to migrate I propose a customized version
of LPC11xx.bas (BasicChip.bas?) that has user friendly definitions ... "

I don't think this is needed. The platform is different, and trying to 'hide'
the differences will cause more trouble than it's worth.

Just document what it is, in a user-friendly way.

Post Reply