INTRO:
Certain PIC microcontrollers have 16-bit PWM peripherals. These include 12F/16F15xx, 16F17xx and 18FxxQxx microcontrollers and possibly a few others. Great Cow Basic only supports 16-bit PWM on the 12F/16F chips. So unfortunately, 16-Bit PWM is not supported by GCB on any of the 18F "Q" series chips. So you must "roll your own" on these chips if you want to use the dedicated PWM modules.
Why 16-Bit?:
16-Bit PWM allows for much better resolution in regards to both Frequency and Duty Cycle. For example, a 50Hz servo signal with a pulse width resolution of 1 us can be easily achieved. Another example would be precision positional control of a damper or valve.
"Q" Series PWM Module:
The PWM modules on "Q" Series microcontroller are different than the other 16Bit PWM modules as there is a "prescaler" that can be set anywhere between 1 and 255 allowing for very precise frequency and pulse width control at high resolution. For example a 50Hz Frequency with 1us resolution of the pulse width from 800us to 2200us. That's 1400 discrete steps (If the servo is capable).
CODE:
The attached code demonstrates a 6-channel high resolution servo controller at both 50Hz and 100Hz using a the 16-Bit "PWM1/2/3 " modules on a PIC 18F27Q43. These frequencies equate to frame rates of 20 ms and 10 ms respectively. ( 10ms/100Hz for digital servos). 200hz and 300hz can be added if needed.
I am finalizing the demo code now and will post it later today. What I need is someone with an 18F27Q43 or other "Q" series chip that is willing verify and test the code. You will need some 10K pots as well.
William
Last edit: William Roth 2022-08-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Note: This code is not a final solution for a 6-Channel servo controller. The frequency and pulse widths were hand crafted to give a pulse width from 800us to 2200us full range. This should work nicely on most servos. Hard coded to work at 32MHz. If you change the chip frequency it will not work properly.
A final version would have a script to calculate the pulse widths based chip frequency and user input. Many other features could be added as well.
Servo1 and 2 are on PWM1 and operate at 50Hz (Analog Servos)
Servo3 and 4 are on PWM2 and operate at 100Hz (Digital Servos)
Servo5 and 6 are on PWM3 and operate at 200Hz (Digital Servos)
Do not operate an analog servo at 100 or 200Hz as it could overheat and burn out
After running this for a while and comparing to other PICs with 8-bit and and 10-bit versions(PIC K42) I can say that this particular 8-bit PIC microcontroller generates the smoothest PWM of all I have tried over the years. The system frequency can be high providing fast instruction times while the PWM can be low (50, 100 ,200Hz) , giving a glitch free high resolution output.
William
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
INTRO:
Certain PIC microcontrollers have 16-bit PWM peripherals. These include 12F/16F15xx, 16F17xx and 18FxxQxx microcontrollers and possibly a few others. Great Cow Basic only supports 16-bit PWM on the 12F/16F chips. So unfortunately, 16-Bit PWM is not supported by GCB on any of the 18F "Q" series chips. So you must "roll your own" on these chips if you want to use the dedicated PWM modules.
Why 16-Bit?:
16-Bit PWM allows for much better resolution in regards to both Frequency and Duty Cycle. For example, a 50Hz servo signal with a pulse width resolution of 1 us can be easily achieved. Another example would be precision positional control of a damper or valve.
"Q" Series PWM Module:
The PWM modules on "Q" Series microcontroller are different than the other 16Bit PWM modules as there is a "prescaler" that can be set anywhere between 1 and 255 allowing for very precise frequency and pulse width control at high resolution. For example a 50Hz Frequency with 1us resolution of the pulse width from 800us to 2200us. That's 1400 discrete steps (If the servo is capable).
CODE:
The attached code demonstrates a 6-channel high resolution servo controller at both 50Hz and 100Hz using a the 16-Bit "PWM1/2/3 " modules on a PIC 18F27Q43. These frequencies equate to frame rates of 20 ms and 10 ms respectively. ( 10ms/100Hz for digital servos). 200hz and 300hz can be added if needed.
I am finalizing the demo code now and will post it later today. What I need is someone with an 18F27Q43 or other "Q" series chip that is willing verify and test the code. You will need some 10K pots as well.
William
Last edit: William Roth 2022-08-03
The code is attached.
Note: This code is not a final solution for a 6-Channel servo controller. The frequency and pulse widths were hand crafted to give a pulse width from 800us to 2200us full range. This should work nicely on most servos. Hard coded to work at 32MHz. If you change the chip frequency it will not work properly.
A final version would have a script to calculate the pulse widths based chip frequency and user input. Many other features could be added as well.
Servo1 and 2 are on PWM1 and operate at 50Hz (Analog Servos)
Servo3 and 4 are on PWM2 and operate at 100Hz (Digital Servos)
Servo5 and 6 are on PWM3 and operate at 200Hz (Digital Servos)
Do not operate an analog servo at 100 or 200Hz as it could overheat and burn out
William
Last edit: William Roth 2022-08-03
After running this for a while and comparing to other PICs with 8-bit and and 10-bit versions(PIC K42) I can say that this particular 8-bit PIC microcontroller generates the smoothest PWM of all I have tried over the years. The system frequency can be high providing fast instruction times while the PWM can be low (50, 100 ,200Hz) , giving a glitch free high resolution output.
William