![]() |
Forum Index : Microcontroller and PC projects : Setting multiple pins simultaneously
![]() ![]() |
|||||
Author | Message | ||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 382 |
Just being lazy really - the more features added anyway, the less BASIC as said above. Need to park my dirty Python habits, else I try list comprehension ;-) Soldering away now - prototype #1 Cheers G Entropy is not what it used to be |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7531 |
You may find something in this thread but it's an unofficial library and may or may not work. As it's not part of the MMBasic system any support is via Vincent, not Geoff or Peter. . Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 382 |
I saw that thread - interesting coincidence! For this, I'll stick with individual setpins - and easy to explain to others what its doing. Adding libraries brings me back to my Python comment ;-) I can achieve what I need in 7 lines of code + 4 for the SetPins -- not worth making it less. The fact that I can randomly select 1 from 4 LEDS using bit bashing and bit shifting is enough for me to explain to kiddos. The starting point is the SelectCase option which we can simplify - this is enough MMMagic for me. Entropy is not what it used to be |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2430 |
Something odd with the PORT Function. Reading the output of the PORT Command with Pin() works correctly but reading with the PORT Function only reads the 2 MS Bits in this example. PicoMite MMBasic RP2040 Edition V6.00.02RC22 Copyright 2011-2025 Geoff Graham Copyright 2016-2025 Peter Mather > setpin gp2,dout :setpin gp3,dout :setpin gp4,dout :setpin gp5,dout :setpin gp6,dout > m%=31 :PORT(GP2,5) = m% :? bin$(m%,5),pin(gp6);pin(gp5);pin(gp4);pin(gp3);pin(gp2), bin$(PORT(GP2,5),5) 11111 1 1 1 1 1 11000 > m%=7 :PORT(GP2,5) = m% :? bin$(m%,5),pin(gp6);pin(gp5);pin(gp4);pin(gp3);pin(gp2), bin$(PORT(GP2,5),5) 00111 0 0 1 1 1 00000 > Reducing the CPU speed to 133MHz makes no difference, nor does changing the number of pins. > setpin gp0,dout :setpin gp1,dout :setpin gp2,dout :setpin gp3,dout :setpin gp4,dout :setpin gp5,dout :setpin gp6,dout > m%=127:PORT(GP0,7) = m% :? bin$(m%,7),pin(gp6);pin(gp5);pin(gp4);pin(gp3);pin(gp2);pin(gp1);pin(gp0), bin$(PORT(GP0,7),7) 1111111 1 1 1 1 1 1 1 1100000 > Same behavior on PicoMiteVGA MMBasic RP2350A Edition V6.00.02RC19 Same behavior after setting the pins this way. > pin(gp5)=1:pin(gp4)=1:pin(gp3)=1:pin(gp2)=1:pin(gp1)=1:pin(gp0)=1 > m%=63:PORT(GP0,6) = m% :? bin$(m%,6),pin(gp5);pin(gp4);pin(gp3);pin(gp2);pin(gp1);pin(gp0), bin$(PORT(GP0,6),6) 111111 1 1 1 1 1 1 110000 > Edited 2025-05-13 13:16 by phil99 |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6223 |
The problem appears to be with setting the PORT. Reading is OK SETPIN GP2,DOUT :SETPIN GP3,DOUT :SETPIN GP4,DOUT :SETPIN GP5,DOUT :SETPIN GP6,DOUT 'm%=31 PORT(GP5,2) = 3 : PORT(GP3,2) = 3 : PORT(GP2,1) = 1 'print bin$(m%,5) PRINT PIN(GP6);PIN(GP5);PIN(GP4);PIN(GP3);PIN(GP2) PRINT BIN$(PORT(GP2,5),5) RUN 1 1 1 1 1 11111 Jim VK7JH MMedit |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2430 |
Curious. In my last edit above the pins are all set with pin(x)=1 and still only 2 are read. Edit Did a CPU Restart and it gives the same result you got, then set all the pins with m%=31:PORT(GP2,5) = m% then measured the pins. All are 3.3V but the port function still returns 11000. The port command triggers the problem but outputs the correct data. The port function then returns the wrong data. This continues until reset, no matter how the pin states are set. Edited 2025-05-13 13:53 by phil99 |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6223 |
The PORT command is working correctly as far as setting the pins. The PORT function reads the external state of the pins correctly. It is only when reading the (assumed) state of pins which have been set by the port command that is in error ' connect GP2 to GP7 etc SETPIN GP2,DOUT :SETPIN GP3,DOUT :SETPIN GP4,DOUT :SETPIN GP5,DOUT :SETPIN GP6,DOUT SETPIN GP7,DIN : SETPIN GP8,DIN : SETPIN GP9,DIN : SETPIN GP10,DIN :SETPIN GP11,DIN ' FOR m% = 0 TO 31 PORT(GP2,5) = m% PRINT BIN$(m%,5), PRINT BIN$(PORT(GP2,5),5), PRINT BIN$(PORT(GP7,5),5) NEXT m% RUN 00000 00000 00000 00001 00000 00001 00010 00000 00010 00011 00000 00011 00100 00000 00100 00101 00000 00101 00110 00000 00110 00111 00000 00111 01000 01000 01000 01001 01000 01001 01010 01000 01010 01011 01000 01011 01100 01000 01100 01101 01000 01101 01110 01000 01110 01111 01000 01111 10000 10000 10000 10001 10000 10001 10010 10000 10010 10011 10000 10011 10100 10000 10100 10101 10000 10101 10110 10000 10110 10111 10000 10111 11000 11000 11000 11001 11000 11001 11010 11000 11010 11011 11000 11011 11100 11000 11100 11101 11000 11101 11110 11000 11110 11111 11000 11111 > Tested on a RP2350A WEBmite VK7JH MMedit |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2430 |
Yes, that is it. Using small capacitors on the pins as a sample-&-hold and switching the pins to DIN gives correct results. > setpin gp0,dout :setpin gp1,dout :setpin gp2,dout :setpin gp3,dout :setpin gp4,dout :setpin gp5,dout : PORT(GP0,6) = 63 > ? bin$(PORT(GP0,6),6) 110000 > setpin gp0,din:setpin gp1,din:setpin gp2,din:setpin gp3,din:setpin gp4,din:setpin gp5,din:? bin$(PORT(GP0,6),6) 111111 > Edit. Just for fun removed the capacitors and tested how long the pin capacitance holds the pins up. It's about 50mS to 100mS. > for n=1 to 7: if n<>3 then :setpin n,dout :endif :next :PORT(GP0,6)=63 :? bin$(PORT(GP0,6),6) 110000 > for n=1 to 7: if n<>3 then :setpin n,din :endif :next :do:? bin$(PORT(GP0,6),6):pause 9:loop 111111 111111 111111 111111 111111 011111 011111 011111 000101 000100 000100 000000 Edited 2025-05-13 16:21 by phil99 |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4863 |
Does it help when you define the pins with (internal) pullup ? Can you do that with the PORT command? Then you should read immediately the right value (high). Volhout P.S. Nimue, have you seen this: nomis Edited 2025-05-13 16:47 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2430 |
Pullup works on DIN but the bug is on reading back the pin state of DOUT, which doesn't support pullup. Maybe there is something in Vincent Himpe's library of pin manipulators but haven't tried. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10075 |
The port command is for writing OUTPUT pins. The port function is for reading INPUT pins. |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7531 |
Hehe... subtle... A pin can't be both an input and an output simultaneously. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2430 |
I note in Vincent's library there is provision to read output pins directly. |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7531 |
That may change depending on your definition of "directly". :) On the RPxxxx there are pads in the way, GPIO latches don't connect to the pins and pad controls override them, which is why you can have SETPIN GPx OFF. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2430 |
In his library there appears to be provision to connect an input register to a pad even if an output register is already connected to that pad. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10075 |
I can fix it but it is yet another example of an issue raised with which I have a real conceptual problem as all it does is add extra code to the firmware. You set x to be y. Now you want extra firmware code to read x in order to tell you it is y. You set the bl..dy thing in the first place. Over and over this has been raised. Give me a function to tell me if I have set OPTION this or that etc. etc. Aaaaaaagh!!!! |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2430 |
Yes fair enough, it was confusing that it sort of works sometimes. As you say there is little point adding code that few will use. |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4004 |
As MMBasic is available on multiple CPU platforms, it may be best to define PORT (for input and separately for output) in a way that is the same on all of them. I suspect that is what we have now. I suppose with the proviso that some platforms might allow more, but you'd be best sticking to the common behaviour. John |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |