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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 )
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Small Update Released 99.02.21
0000159: [GCstudio] Cancel cvs download now open GC Studio, in case server is busy or unavailable. (angel-spartan)
0000157: [Chip Definition Files] 16F18324 internal OSC not correct. (evanvennn)
0000160: [GCstudio] Small UI tweaks. (angel-spartan)
0000158: [GCstudio] Reset Programmer Preferences option added on config panel (angel-spartan)
Not seen it William? It's tidy. Not much learning curve, I suggested a few things as a tester user and the suggestions were implemented so it's like gcb@Syn. Buttons for hex/flash, etc. so gcb users could adapt easy. The auto update is better than rc and patches, imho.
The more users then more ideas would be implemented but nice if it was easy to do by yourself.
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:
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
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?
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.
Neither should be constraints but it all depends on how you implement your pulses.
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
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
Stan,
The range on servos is 1 to 2 ms not microsec
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
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.
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.
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??
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 )
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!
Put code between ~~~ then code then ~~~
and it prints to the forum normal size not showing ~~~
I had a control line diesel plane 50+ years ago. It made me dizzy :)
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.
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.
oh... are you referring to 12 MHz frequency measured at the port ( as in the case of your code the port gpio.1) ?
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?
@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
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.
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.
Evan Posted:
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
Small Update Released 99.02.21
0000159: [GCstudio] Cancel cvs download now open GC Studio, in case server is busy or unavailable. (angel-spartan)
0000157: [Chip Definition Files] 16F18324 internal OSC not correct. (evanvennn)
0000160: [GCstudio] Small UI tweaks. (angel-spartan)
0000158: [GCstudio] Reset Programmer Preferences option added on config panel (angel-spartan)
Installer:
https://www.gcbasic.com/reps/stagebuild/setup/GCstudioSetup.exe
Full Change Log:
https://www.gcbasic.com/bugtracking/changelog_page.php
Road Map
https://www.gcbasic.com/bugtracking/roadmap_page.php
Report a Bug!
https://www.gcbasic.com/bugtracking/bug_report_page.php
Not seen it William? It's tidy. Not much learning curve, I suggested a few things as a tester user and the suggestions were implemented so it's like gcb@Syn. Buttons for hex/flash, etc. so gcb users could adapt easy. The auto update is better than rc and patches, imho.
The more users then more ideas would be implemented but nice if it was easy to do by yourself.
Last edit: stan cartwright 2022-04-19
See Stans post above, or, see the General Announcement https://sourceforge.net/p/gcbasic/discussion/579125/thread/d9a0d4a3b8/?limit=25#b2ab
Last edit: Anobium 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:
William
Last edit: William Roth 2022-04-20
Any idea what the correct ADC value is? With the correct value then the master file in GutHub ( see https://github.com/GreatCowBASIC/DATFileGenerator/blob/main/chipdata/16f18324.dat ) can be updated.