Menu

Millis() is ready for Release - Look for it soon on a forum near you

2019-04-04
2019-04-05
  • Chris Roper

    Chris Roper - 2019-04-04

    Great News - Change log entry: 615 New Millis Initial formal release of millis.h

    It is ready for real time (Pun Intended) and will be included in the upcoming release of Great Cow BASIC as a core Library.

    It has been extensively tested on all PIC (10,12,16,18) and AVR families supported by GCBASIC and example files will be included in the release.

    The holdup was caused by uncovering a couple of low level compiler errors which have now been fixed so, whilst Evan and I have been silent for the past few weeks, millis was never dead it was still being used as a debug tool to stress test the compiler.

    It has already proven useful in a couple of projects too so I expect to see more when it is formally released with the New Compiler and the community get to use it too.

    Here is a n example for the Arduino Mega to whet your appetites

    '
    ' 500mS flash for a 1Hz square wave on PIN13 (PORTB.7)
    '
    #chip mega2560,16         ' Declare the Target Processor and Speed
    #option explicit          ' Require Explicit declaration of Variables
    #include <millis.h>       ' Include the Library
    
      #define LED PORTB.7     ' Define the LED Pin - Digital Pin 2
      #define LEDRate 500     ' Flash rate in mS
      ' Setup
      Dir LED Out               ' Make the LED Pin an Output
      LED = 0
    
      Dim CurMs, LstMs as word  ' declare working variables
      ' Main                    ' This loop runs over and over forever.
      LstMs = 0
      CurMs = 0
    
      ' Main                    ' This loop runs over and over forever.
      Do
        CurMs = millis()
    
        if CurMs - LstMs >= LEDRate then  ' required Time has Elapsed
          LED = !LED                      ' So Toggle state of LED
          LstMs = CurMs                   ' And Record Toggle Time
        end if
    
      Loop
    
    END
    

    Cheers
    Chris

     

    Last edit: Chris Roper 2019-04-04
  • Moto Geek

    Moto Geek - 2019-04-04

    Chris, this is really awesome. I always envyed the millis function from arduino. When you say it will be part of core library, does that mean you don't have to use the include? It will be part of the compiler? Thanks again for your effort! Evan too of course!

     
  • Chris Roper

    Chris Roper - 2019-04-05

    Good question, I know that it will be distributed with the new release as "Millis.h" but I am not sure if it will be auto included or not. That would be up to Evan when he packages up the release.

     
    • Anobium

      Anobium - 2019-04-05

      millis.h and the demos will be in the next release.

      millis will always require #include <millis.h> as millis has depedencies in terms of the setting up the timer that requires the use of specific clock freqencies.</millis.h>

      millis supports PIC and AVR, and the widest set of frequencies. These frequencies are supported.

      But, the 'use case' of odd frequencies cannot be automatiically handled and therefore the user can #include and the set user constant to initialise the millis correctly.

      Summary: yes - in the release, no - not automatically included.

      @Chris. More to add?

       

      Last edit: Anobium 2019-04-08
  • Chris Roper

    Chris Roper - 2019-04-05

    Just to Clarify that in the Arduino Environment Millis only had to support one frequency, 16Mhz.
    But due to the wide range of frequencies supported by Microchip and the Use of Phase Locked Loops to derive the Clock bus in newer Devices, the GCBASIC version of Millis() was designed from the start to support any binary multiple Clock speed, i.e. 2Mh, 4MHz etc all the way up to 48Mhz and possibly higher.

    So if you get a warning that your speed is not supported just choose the nearest binary multiple in your #Chip Statement.

    I agree with Evan, as there is the possibility of a warning it should not auto include.

    Cheers
    Chris

    EDIT:
    For clarity Arduino Millis actually had to support 1, 2, 4, 8, 12, 16, 20 and 24 but had Issues with 12, 20 and 24Mhz. GCBASIC avoids the issue by sticking with the Binary progressions.

     

    Last edit: Chris Roper 2019-04-05

Log in to post a comment.