Menu

A PulseInInv Command Would Be Nice

Help
CDRIVE
2017-05-07
2017-05-11
  • CDRIVE

    CDRIVE - 2017-05-07

    Since there's a PulseOutInv command I'm curious why there's no PulseInInv command. I think it would be equally useful.

    Thanks,
    CJ

     
  • William Roth

    William Roth - 2017-05-08

    There is. See Help > Misc Commands

     
  • William Roth

    William Roth - 2017-05-08

    What is nice about GCB is that if you need a special command or function you can easily build your own.

    Take PulseInInv for example. It is actually a macro located in stdbasic.h. But is has only basic functionality and does not wait for a transition from high to low to start measuring, so it will return partial pulse width values if the signal is already low when executes. Maybe I want a better more advanced command. So I just make a new one (as a macro) in this case.

    Note1: You cannot put a label such as "timeout:" within a macro. Any label placed between Macro and End macro will cause the compiler to hang up. So to allow a quick exit from the macro I placed the label in the main program loop instead.

    Note2:: GCB's macro based Pulsin and it variants (including my example below) cannot accurately measure pulses in microcseconds. There is simply too much accumlated overhead using a loop/delay/increment method to get accurate readings. For example. my macro below will read 32 microseconds when the pulse is actually 122 us. To measure microseconds accurately a timer based method is neceesary.

    This is what I came up with as an example. It waits for a high to low transistion and times out based upon the new timeout value parameter in the macro. I used 1000 in this example. This way the program will not stall for 65,535 ms if there is no pulse present.

     Dir PortB.7 IN
     Dim MyVal as WORD
    
    
    MAIN:
      Do
         PulseInInv_ALT (PortB.7, MyVal, ms, 1000)
         TIMEOUT2: ' wait to exit macro
         Locate 1,0 : Print MyVal : LCDSPACE 2
      Loop
    
    Macro PulseInInv_ALT (PulsePin, PulseTime as Word, TimeUnit, TimeOutTime)
       Dim Cntr as word
       cntr = 0
       PulseTime = 0
    
       Do while PulsePin  = 0
           wait 1 TimeUnit
           cntr++
           If cntr > TimeOutTime then Goto timeout2
       Loop
    
       cntr = 0         '// Reset the timeout counter
    
       Do  while PulsePin = 1   '// Wait for low pulse edge then start measurement
           wait 1 TimeUnit
           cntr++
           If cntr > TimeOutTime then Goto timeout2
         Loop
    
     '// now start measuring the low pulse
    
       Do While PulsePin = 0
           Wait 1 TimeUnit
           PulseTime++
           If PulseTime = 0 Then Exit Do
       Loop
    
    End Macro
    
     

    Last edit: William Roth 2017-05-08
  • CDRIVE

    CDRIVE - 2017-05-08

    Thank you for the reply. My GCB version doesn't include PulseInInv and I can't find a listing for it in the misc folder within the help files.

    I've been putting off downloading the latest GCB version because when I downloaded my current version I had to do it 4 or 5 times. Norton kept deleting it. I have no idea what GCB version I have because the version number is absent in Properties panel. I do know that the installer version is...

    Great Cow BASIC v0.95.010 Setup
    Downloaded 11/1/2016

    I really don't want to uninstall the version I have until I'm sure the latest version is stable & running smoothly. Can more than one version coexist? It's installed in the default address:
    C:\GCB@syn\GreatCowBasic\gcbasic.exe

    If I can I'll create a seperate folder for the newest version.

    On another note I want to thank you for the macro code but I think I should add that I may be trying to use PulseIn where I shouldn't. You see I'm not really trying to to measure pulse width. I thought I could use it to de-bounce a push-button switch input. Normally I'd just write something like this:

    #chip 12F629, 4
    #Config osc = int
    Dir GPIO.5 In
    
    'Simple Debounce proceedure for normally high input pin.
    If GPIO.5 = 0 Then Wait 200 mS  ' Pullup Resistor on GPIO.5
    If GPIO.5 = 0 Then
      '  do stuff
     Else
       '  do other stuff
    End If
    

    Why I didn't I have no idea.

    Thanks,
    CJ

     

    Last edit: CDRIVE 2017-05-08
  • William Roth

    William Roth - 2017-05-08

    You can have multiple installations of GCB, I have 4 (maybe 5?) .

    Just make sure the desktop shortcuts point to the correct versions, and that GCB source code files are associated with the version that you want to run when you click on a .gcb file

    And you should probably open the Windows Control Pannel > System > Advanced Settings > Environment Variables and remove any entries for GCB in user or system variables, This will make double sure that the correct Synwrite folder is updated with config setting changes.

     
  • CDRIVE

    CDRIVE - 2017-05-09

    William, thank you for the reply and great details. I'm curious though. When I followed the path that you gave me I see GCB@Syn listed there but that just tweeked more questions. What is it about GCB that lists it in there?

    Cheers,
    CJ

     
  • William Roth

    William Roth - 2017-05-10

    My best guess is that the ide.exe startup app uses one of these variable to determine the location of synwrite. I don't start the GCB/Synwrite IDE with ide.exe. Instead I use a shortcut to syn,exe

    Evan and Frank would know more about this than I do.

     
  • Anobium

    Anobium - 2017-05-10

    I can explain.

    During installation we call IDE.EXE. This loads the default files.
    Also, during the installation we create desktop icons that create the links to the ../GCB@Syn/Synwrite/syn.exe. As we can now call syn.exe without having to call ide.exe.

    The rational is easy. Calling ide.exe intially loads the default files and complete the installation. After the initial execution we can call, and should call, syn.exe directly.

     
    • Anobium

      Anobium - 2017-05-10

      Also note. Syn.exe is an adapted build of syn.exe and not the public build of syn.exe. You could use the public build of synwrite but our forked build supports the functionality we require.

       
  • CDRIVE

    CDRIVE - 2017-05-11

    Thanks for the additional info. So, is it general consensus that I can't do any harm be removing that reference?

    CJ

     

    Last edit: CDRIVE 2017-05-11

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.