Menu

Does the GC Basic compilation limit the PIC chip speed

2022-04-17
2022-05-24
1 2 3 > >> (Page 1 of 3)
  • Keith Renecle

    Keith Renecle - 2022-04-17

    Hi All, To explain my question, I need to give you an example. If I write a short program to run a model servo which requires a pulse width of between 1.0 and 2.0 mS and a frame rate of 20 mS, and I try to step the pulse width by 1 uS at a time on a PIC with a clock speed of 4 MHz then when I compile the program, it gives an error. If I use a higher clock speed then all is fine. I used a PIC16F684 in one project and I needed to add an external crystal to get it to work. A friend with much experience of processor chips told me that if I program in C for example, then the 4 MHz clock is enough to generate steps of 1 uS.

    Is this correct, and is the problem with the compiler using up too much of the chip speed, and will a language like C work with the same chip at 4 MHz? Thanks very much.

    Keith R

     
    • GCBASIC

      GCBASIC - 2022-04-17

      The short answer is No. The language is not the determinating factor. The specific implementation of a language could be a 'good' or 'bad' implementation in terms of a specific microcontroller.

      As Great Cow BASIC is essentially as close to ASM as you can get... comparing to Arduinio C implementation is meaningless. They are like pears and apples - both are fruit but very different implementation of the same concept.

      So, that said. What are have you tried to implement your solution?

       
  • Keith Renecle

    Keith Renecle - 2022-04-17

    Thanks for the quick reply. For that project I added a 20 MHz crystal but I would like to update the project and get rid of the crystal if possible. I also found out now since the great semiconductor shortage, that this 16F684 has been made obsolete and Microchip recommends that I use the 16F18324 which has the sin pin configuration and higher speed, more memory etc.

    I was just curious to know if the limiting factor for my 1uS steps was GC Basic or the 4 MHz clock speed.

     
    • Anobium

      Anobium - 2022-04-17

      Neither should be constraints but it all depends on how you implement your pulses.

       
  • stan cartwright

    stan cartwright - 2022-04-17

    pulseout is turn a port on for xxuS then turn off.
    I use a 18f25k22 at 64MHz and thought 10uS as lowest pulseout.

    You could try
    set port.x on
    set port.x off
    maybe that takes 1uS
    so if pic runs at 4MHz then that's an instruction every 4 clocks so that's an instruction every 1MHZ
    ie every 1uS...... I don't use pics, I use avr that does instructions every clock so 16MHz avr same as 64MHz pic.
    I could be wrong though.

    I think nop would take 1uS at 4MHz so maybe

    set port.xx on
    for counter = 1 to uSecs
        nop
    next
    set port.xx off
    

    but you'd have to take how many clocks for- next takes into account
    for counter = 1 to uSecs-(counter * for-next time)

     

    Last edit: stan cartwright 2022-04-17
  • mmotte

    mmotte - 2022-04-17

    Stan,
    The range on servos is 1 to 2 ms not microsec

     
    • stan cartwright

      stan cartwright - 2022-04-17

      Mike, I was thinking of Keith's post about uS pulses and it's 0.75 to 2.25mS on my rc servos
      seems I used pulseout xxx 10uS
      I use a timer0 - 50Hz interrupt for rcservos like Keith ie every 20ms.
      https://www.youtube.com/watch?v=k3cwF1ddRs8
      https://www.youtube.com/watch?v=riaFvlKl1kE

      edit. Why Keith wanted to use increase pulseout uS for rcservo ??

       

      Last edit: stan cartwright 2022-04-17
  • Keith Renecle

    Keith Renecle - 2022-04-18

    Thanks for all the replies. Stan, I mentioned the servo control but what I'm doing is to use that 1.0 to 2.0 mS range to control the throttle on an electric brushless motor system with an electronic speed controller or ESC, I need fine rpm control and the minimum of 10 uS on my PIC is too high because I need around 4 uS per rev. I then achieve rpm steps in the 100 rpm range which is fine for what I'm doing.
    I see that if I program the newer PIC16F18324, then I can use the internal clock at 12MHz and then GC Basic accepts code for 1 uS. Maybe my issue is, as Anobium suggests, in the way that I implement my pulse width code.

     
    • Anobium

      Anobium - 2022-04-18

      Keith - it would be best if you share your code.

      The 16F18324 does not support 12mHz from the internal clock and why not use 32mHz?
      With the right chip you could use CLC. PMW/CCP, PMW and a host of options.

       
    • stan cartwright

      stan cartwright - 2022-04-18

      I have 2 ebikes I made using mid drive 3 phase brushless motors and they have throttle but it's just a thumb controlled potentiometer... very noisy are pots and not good for small increments. It seems an odd way of speed control??? imho. all the servo stuff??

       
  • Anobium

    Anobium - 2022-04-18

    I have just spotted, and corrected, the chip frequencies for the 16F18324 were incorrect. They are now correct. Please obtain a release of GCStudio that is after the date of this post ( 18th April 2022 )

     
  • Keith Renecle

    Keith Renecle - 2022-04-19

    Hi Stan & Anobium, my project that I do have working is from quite a few years ago and it is a governor or constant rpm feedback system for control line model planes. I was just curious to know if the reason why I can't get uS resolution below about a 12 MHz clock is the compiler or just the way the PIC's work, Here is the basic servo cycle program that I used before:

    (#chip 12F675, 4
    (#config Osc = Int
    (#define ServoPin GPIO.1
    (#define ServoMin 100
    (#define ServoMax 200

    Dir ServoPin Out
    Do
    For Inc = ServoMin to ServoMax
    PulseOut ServoPin, Inc 10us
    Wait 20 ms
    Next
    For Inc = ServoMax to ServoMin
    PulseOut ServoPin, Inc 10us
    Wait 20 ms
    Next
    Loop

    I see that I need to use a "(" before the "#" or else the text goes huge!

     
    • stan cartwright

      stan cartwright - 2022-04-19

      Put code between ~~~ then code then ~~~

      code
      

      and it prints to the forum normal size not showing ~~~

      I had a control line diesel plane 50+ years ago. It made me dizzy :)

       
      • Keith Renecle

        Keith Renecle - 2022-04-19

        I still have some C/L diesel planes! I flew in world champs competition with an 8.0 cc diesel for a few years before going to electric power. I actually converted an existing glow engine to diesel by changing the head to one with a compression piston in it. It flew very much like a governed electric power model. Ether for the fuel then became really expensive and e-power is more reliable, especially in bad or changing weather.

         
        • stan cartwright

          stan cartwright - 2022-04-19

          Nostalgia for me Keith. Electric is better and the speed control I now understand.
          I switched to a diesel 2 channel 27MHz rudder only glider I made out of balsa and doped tissue paper.
          Now I got a cheap quad copter with a wi fi cam to my phone but it's no wind only as it blows away. More fun with old stuff like a tow line glider.

           
  • Anobium

    Anobium - 2022-04-19

    oh... are you referring to 12 MHz frequency measured at the port ( as in the case of your code the port gpio.1) ?

     
    • Keith Renecle

      Keith Renecle - 2022-04-19

      No, I was referring to the clock speed or internal oscillator if you like. The code above was running on a 4 MHz internal clock, and I can't get any lower than 10 us. If I set the clock speed in GCB up and try to compile the program I need to get to 12 MHz before the error goes away. That's why I mention 12 MHz I used a 20 MHz external crystal oscillator in my project,
      On the 16F684 it can run up to 8 MHZ without a crystal, so I was just wondering why the 4 or 8 Mhz clocks could not be used to generate pulses lower than 10 us?

       
      • Anobium

        Anobium - 2022-04-20

        @Keith Renecle

        Are you referring to this message ? Warning: Inaccurate microsecond delay due to use of variable at the current clock speed

        If yes, it is a warning and as therefore you can accept if you can assure (in your code) that the variable > 0

         
        • Keith Renecle

          Keith Renecle - 2022-05-16

          This is interesting. I tried a short test program using a PulseOut 1000 us interval and the Wait 20 ms statement. I got the warning and used it anyway. The result is that it works but the pulse width is around 1.5 ms. If I change the 1000 to 650, then it produces a 1.0 ms pulse width. So I guess that I'm stuck with using a 20 MHz crystal until I finish my stock of my 16F684 chips.

           
          • Anobium

            Anobium - 2022-05-16

            As explained. Using a variable is the cause. If you use the Select-Case with constants then I think this will be what you need.

             
  • William Roth

    William Roth - 2022-04-19

    Evan Posted:

    Please obtain a release of GCStudio that is after the date of this post ( 18th April 2022 )

    Perhaps I have not been keeping up. But nowhere do I see where anyone can download something called "GCStudio". I see GreatCow Basic release candidate ( Patch) but not GCStudio.

    Perhaps a link could be provided to this release of GCStudio?

     

    Last edit: William Roth 2022-04-19
  • William Roth

    William Roth - 2022-04-20

    Back on topic ......

    @Anobium,

    I see that you updated the 16F18323 dat file. This corrected entries for memory and OSC. However the new datfile shows "ADC=15".

    I believe this should be "ADC=11" as this is a 14-pin chip and could not possibly have 15 ADC's


    @Keith

    Since you are using PulseOut for the servo signal, you will get the best resolution if you operate the 16F18323 at 32 MHz. 16MHz should also be more than adequate with slightly less power consumption.

    PulseOut is simply a macro and can be seen in stdbasic.h . It looks like this:

    macro Pulseout (Pin, Time)
          Set Pin On
          WaitL1 Time
          Set Pin Off
    end macro
    

    William

     

    Last edit: William Roth 2022-04-20
1 2 3 > >> (Page 1 of 3)

Log in to post a comment.