Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Webmite Port Command/Function Query
Author | Message | ||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
Hi there Thanks for accepting me onto the forum. I hope I'm posting this correctly. On the Webmite v5.07.07 the Port() function appears not to read pins set to Output. Port(24,4)=&B1111 has the expected result with SetPin 24, DOUT etc. before hand. However Print Port(24,4) results in an Error : Invalid input pin. The Webmite Manual version 3 clearly states "...This function will also return the state of a pin configured as an output..." Is it just me being stupid or is there something I'm missing? Any guidance would be appreciated. Thanks Carl Cheers Carl Retirement is tough on Hobbies without a day job |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
Tested WebMite MMBasic Version 5.07.08b9 and the PicoMite MMBasic Version 5.07.08b9 but got a different result reading individual pins. They both do this. > setpin 1,dout Reading the pins individually is ok but the Port Function is not.> setpin 2,dout > setpin 4,dout > setpin 5,dout > Port(1,4)=&B1111 Error : Invalid output pin > Port(gp0,4)=&B1111 > ? pin(1) 1 > ? pin(gp1) 1 > The command and function seem to need GP numbers. Edited 2023-08-09 17:38 by phil99 |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9128 |
from the manual PORT function The manual has two contradictory phrases. The code is the same across all variants of MMbasic and currently errors on an output. I'll change the code in the next beta and remove the inconsistency in the next manual update The result you see is correct. GP0, GP1, GP2, GP3 are consecutive 1,2,4,5 are not so use either port(1,2,4,2) or port(gp0,4) Edited 2023-08-09 17:44 by matherp |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
It's never a good idea to use the hardware pin numbers as it breaks compatibility with other platforms. The GPn numbers are what the RP2040 uses so they can be used on any hardware platform that uses that chip. I know it's a little more typing, but it's worth it in the long run. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
LouisG Senior Member Joined: 19/03/2016 Location: AustraliaPosts: 124 |
Hi all, I've been using pin numbers all along so far and successfully. I understood the concept and reason for GP numbers but they raised question marks. Are they integers? Is it legal to write FOR i = GP4 TO GP11 when setting pins? I didn't encounter any examples in the manual though there could be. Also there's nothing under Variables or Integers regarding GP numbers. I will, however, have a fresh look at them in light of Matherp's comments above. ... Louis - |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
Not quite that simple. > for i=4 to 11:setpin (mm.info(pinno ("GP"+Str$(i)))), dout:next > port(gp4,8)=255 > ? pin(gp4),pin(gp11) 1 1 > removed some brackets > for i=4 to 11:setpin mm.info(pinno "GP"+Str$(i)), dout:next > port(gp4,8)=255 > for i=4 to 11 : p=mm.info(pinno "GP"+Str$(i)) : ? pin(p), :next 1 1 1 1 1 1 1 1 > Edited 2023-08-09 22:52 by phil99 |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
Phil, I don't see what your code proves... seemingly nothing... John |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9128 |
It is how you can set up and/or read/write multiple pins by gpno in a loop |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
Only does one per loop, right? Nothing wrong with that but what is the point & why two versions? John |
||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
Thank you all for your comments and support, it is truly appreciated. The benefit to me of the Port command/function is the ability to drive a sequential tap changer on an excess PV diversion to geyser. I have implemented this on an ESP32 about 2 years ago using Visual Studio. My version control leaves somewhat to be desired and the code, compile, upload, run, fix, ... development cycle does not make coming back after 2 years to fix a few non-critical bugs very pleasant. The code, run, fix, ... development cycle on the Webmite is far more preferable. Besides it harks back to my first pukka computer, a Radio Shack TRS-80 with a whole 16K of memory. The tap changer, a bunch of relays, is in the secondary of a specially wound transformer. To change taps I first have to open all the relays and wait 30ms for the contacts to open - mechanical relays and the joy thereof. A more elegant approach would be to write to the port, wait 30ms, and then write the new tap changer position to the port. The sequence of the tap changer is either up one step or down one step at a time so it would be nice to be able to read the port and bit shift to drive the tap changer. On the ESP32 I've had to implement a loop to open all the relays in sequence and then wait 30ms before setting the correct tap changer pin. matherp - Thanks for the comments and giving my brain some reprieve :) I look forward to the update. Hopefully the fix will allow the reading of the state of the output pins in parallel. In my sample i'm using GP18, GP19, GP20 and GP21 specifically because the PIN numbers are sequential. I tried Print Port(GP18,4) but still get the Error : Invalid input pin. Changing the DOUT to DIN resulted in the correct parallel read of the 4 pins and an appropriate Print value. Mixtel90 and LouisG - Tried the For GP18 to GP21 loop but that gives an Error : Pin 0/NULL is reserved on startup. I'm guessing GP18 is not reserved and being seen as a variable... Phil99 - I was wondering how to set sequential GPnn with PIN numbers being non-sequential, pesky ground pins scattered regularly throughout :). What an elegant piece of code. May I nominate this as a code snippet for The Fruits of the Shed? matherp - Maybe Phil99's elegant piece of code can make it into the manual as an example of dealing with programmatically assigning sequential GPnn. Once again thank you everybody for your rapid response and guidance, it is much appreciated. Maybe somebody can point me to an example of using the webmite to interrogate a Sunny Island and Sunny Boy using Modbus TCP? I live in hopes :) Cheers Carl Cheers Carl Retirement is tough on Hobbies without a day job |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
That's interesting. Pins GP18-GP21 are free on the ordinary PicoMite but not on the PicoMite VGA, which uses them for the VGA display. In theory they should be free on the WebMite too, I think, but I've never used one. Incidentally, I wouldn't consider allocating port pins in any other way than directly. Then I'd use sub to write to the port and a function to read it. That way it's very easy to change pin allocation for different setups. pwrite 12 a=pread() '---------------------- SUB PWRITE(value) port(GP0,4,GP7,4)=value end sub FUNCTION PREAD() pread=port(GP0,4,GP7,4) end function Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
@Carl, Perhaps some bits and pieces like this could do it. > LIST Dim integer i, p, read.port, Up, Down For i=4 To 11 SetPin MM.Info(pinno "GP"+Str$(i)), dout Next Port(gp4,8) = &B00010000 For i = 11 To 4 Step -1 p = MM.Info(pinno "GP"+Str$(i)) Print Pin(p), read.port = (read.port << 1) + Pin(p) Next Print " Port Pins" Print "read.port = "; Bin$(read.port, 8) Up = read.port << 1 Port(gp4,8) = 0 Pause 30 Port(gp4,8) = Up Print "Up = "; Bin$(Up, 8) Down = read.port >> 1 Port(gp4,8) = 0 Pause 30 Port(gp4,8) = Down Print "Down = "; Bin$(Down, 8) > > RUN 0 0 0 1 0 0 0 0 Port Pins read.port = 00010000 Up = 00100000 Down = 00001000 > |
||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
Thanks Phil99 I will have a look at the code. Cheers Carl Retirement is tough on Hobbies without a day job |
||||
Print this page |