The first URL is discussing PWM options and not PWM/CCP in 10 bit mode.
The second URL URL is discussing PWM options across the range of PICs.
The PDF discusses 10Bit PWM on the 12F683 then disregards the 10bit option to use the 8bit PWM/CPP ( as 10 bit is not required) signal therefore it is not a 10bit implementation using CCPR1L and CCP1CON register two LSbs DC1B<1:0> . So, not a reference implementation.
As initially thought. Using 10bit PWM/CPP signals is very specific frequencies for specific MCU clock frequencies.
This information is not constrained by GCBASIC but the implementation of PWM/CCP in the MCU.
The specifics of PWM/CCP10bit range can be determined in the following table, derived from the Mister E PIC Multi-Calc tool ( which is an implemention of the datasheet).
MCU Freq
10bit PMW/CPP Freq Range
8
0 .489Khz > < 15.60Khz
4
0.245Khz> < 7.8Khz
2
0.123Khz> < 3.9Khz
1
0.062Khz> < 1.95Khz
So, theory resolved. There is a software tool to assist in the modelling!!
Back to a real implementation in GCBASIC.
Fixed Model PWM is using the two constants to control PWM frequency and Duty.
HPWM CCP is using HPWM command.
Examples
Code
Fixed Mode PWM
Min: #chip 12f683,8 #define PWM_Freq 0.489 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
Max: #chip 12f683,8 #define PWM_Freq 15.6 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
Min: #chip 12f683,4 #define PWM_Freq 0.245 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
Max: #chip 12f683,4 #define PWM_Freq 7.8 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
Min:#chip 12f683,2 #define PWM_Freq 0.123 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
Max: #chip 12f683,2 #define PWM_Freq 3.9 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
Min: #chip 12f683,1 #define PWM_Freq 0.062 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
Max: #chip 12f683,1 #define PWM_Freq 1.95 'Frequency of PWM in KHz #define PWM_Duty 50 'Duty cycle of PWM (%)
HPWM CCP Mode
Duty set to 127 equates to 50% Duty
Min: #chip 12f683,8 HPPWM 1, 1, 127
Max: #chip 12f683,8 HPPWM 1, 15, 127
Min: #chip 12f683,4 HPPWM 1, 1, 127
Max: #chip 12f683,4 HPPWM 1, 7, 127
Min: #chip 12f683,2 HPPWM 1, 1, 127
Max: #chip 12f683,2 HPPWM 1, 3, 127
Min: #chip 12f683,1 HPPWM 1, 1, 127
Max: #chip 12f683,1 HPPWM 1, 1, 127
The duty for Fixed Model PWM is 0% to 100% therefore the is a 7-bit calculation. There is nothing stopping a user from calculating the CCPR1L and CCP1CON register two LSbs DC1B<1:0> values for 10bit and setting using this code segment. See example below.
The range of HPWM CCP Mode is limited to 1KHz as GCBASIC uses an integer for parameter, hence, the constraints shown in the table above.
Now I know the ranges and the constraints I can test on a real chip.
A real 10bit implementation using OSC at 8 Mhz, PWM at 0.5 using a loop to control the 10bit control. It is nearly 10bit... as this would be 1016 increments where PR2 = 253
'Chip Settings #chip 12F683, 8 #option Explicit 'SetthedirectionoftheCCP1/PWMportDIRGP2Out#definePWM_Freq0.5'Frequency of PWM in KHz #define PWM_Duty 50 'DutycycleofPWM(%)//TurnonFixedModePWM/CPP1PWMON//ThemaximumdutyisfourtimesthePR2.So,wecancalcthatandassign.DimmaxdutyasWordmaxduty=[WORD](PR2)*4doDimdutyvalue,dutycalcasWordDimdutytransformedasWord//NeedtocastthecalctoensuretheWORDistheresultoftheBYTEcalculationfordutyvalue=0tomaxduty//Setthe10bitvalueusingCCPR1LandCCP1CONregistertwoLSbsDC1B<1:0>DC1B1=dutyvalue.1DC1B0=dutyvalue.0CCPR1L=dutyvalue/4//shiftthe10bitvaluerightwait1msnextfordutyvalue=maxdutyto0Step-1//Setthe10bitvalueusingCCPR1LandCCP1CONregistertwoLSbsDC1B<1:0>DC1B1=dutyvalue.1DC1B0=dutyvalue.0CCPR1L=dutyvalue/4//shiftthe10bitvaluerightwait1msnextloop
Enjoy
Last edit: Anobium 2023-12-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think I should make it clear. These old PWM/CPP chips are not 10bit PWM at all frequencies. They are capable of 10bit only at specific mcu frequencies and specfic PWM frequencies. An example is mcu at 4Mhz and PWM at 0.245Khz - these will give 1020 steps ( 10 bit value). Anything above mcu at 4Mhz and PWM at 0.487Khz is a 9-bit step.
For real 10bit PWM across all frequencies use a mcu with a true 10bit PWM ( not PWM/CPP).
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes Evan, I confirm, I needed also to add more calculation in my code PWM2Laser to be able to manage different resolutions according frequencies (see code examples in attached picture). Needed time to understand, debug and fix, and the solution is mostly a multiplicator :)
Anyone able to answer this for me. I am stumped.
A user has asked for 10Bit PWM/CCP1 on a 12F683. A reason request.
The datasheet explains 10bit operation, section 11.3 for the datasheet.
So, how do this work? I know it has something to do with CCPR1L and CCP1CON register two LSbs DC1B<1:0> .
But, I am stuck. How to operate in 10bit mode?
Below is the code for a 1Hz signal at 50% duty.
How to make this into a 10Bit duty cycle ?
What are the operating limits for a 10Bit duty cycle, in terms of chip freq and PWM freq ?
Thanks
Hi,
I found the following links and the attached file after a quick search. Hope it will help.
Regards,
Awais
https://microchipdeveloper.com/xwiki/bin/view/products/mcu-mpu/8bit-pic/peripherals/ccp/pwm/10-bit/
https://microchipdeveloper.com/xwiki/bin/view/products/mcu-mpu/8bit-pic/peripherals/ccp/pwm/
Thanks.
The first URL is discussing PWM options and not PWM/CCP in 10 bit mode.
The second URL URL is discussing PWM options across the range of PICs.
The PDF discusses 10Bit PWM on the 12F683 then disregards the 10bit option to use the 8bit PWM/CPP ( as 10 bit is not required) signal therefore it is not a 10bit implementation using CCPR1L and CCP1CON register two LSbs DC1B<1:0> . So, not a reference implementation.
However, I remember tools/software in https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/Interrupt_and_Timer_Solutions/Interrupt_Timed_examples There is a ZIP. In the ZIP is Mister E PIC Multi-Calc tool. The PWM option shows how to obtain a 10bit PWM/CPP signal.
As initially thought. Using 10bit PWM/CPP signals is very specific frequencies for specific MCU clock frequencies.
This information is not constrained by GCBASIC but the implementation of PWM/CCP in the MCU.
The specifics of PWM/CCP10bit range can be determined in the following table, derived from the Mister E PIC Multi-Calc tool ( which is an implemention of the datasheet).
So, theory resolved. There is a software tool to assist in the modelling!!
Back to a real implementation in GCBASIC.
Fixed Model PWM is using the two constants to control PWM frequency and Duty.
HPWM CCP is using HPWM command.
#chip 12f683,8
#define PWM_Freq 0.489
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Max:
#chip 12f683,8
#define PWM_Freq 15.6
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Min:
#chip 12f683,4
#define PWM_Freq 0.245
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Max:
#chip 12f683,4
#define PWM_Freq 7.8
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Min:
#chip 12f683,2
#define PWM_Freq 0.123
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Max:
#chip 12f683,2
#define PWM_Freq 3.9
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Min:
#chip 12f683,1
#define PWM_Freq 0.062
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Max:
#chip 12f683,1
#define PWM_Freq 1.95
'Frequency of PWM in KHz#define PWM_Duty 50
'Duty cycle of PWM (%)Min:
#chip 12f683,8
HPPWM 1, 1, 127
Max:
#chip 12f683,8
HPPWM 1, 15, 127
Min:
#chip 12f683,4
HPPWM 1, 1, 127
Max:
#chip 12f683,4
HPPWM 1, 7, 127
Min:
#chip 12f683,2
HPPWM 1, 1, 127
Max:
#chip 12f683,2
HPPWM 1, 3, 127
Min:
#chip 12f683,1
HPPWM 1, 1, 127
Max:
#chip 12f683,1
HPPWM 1, 1, 127
The duty for Fixed Model PWM is 0% to 100% therefore the is a 7-bit calculation. There is nothing stopping a user from calculating the CCPR1L and CCP1CON register two LSbs DC1B<1:0> values for 10bit and setting using this code segment. See example below.
The range of HPWM CCP Mode is limited to 1KHz as GCBASIC uses an integer for parameter, hence, the constraints shown in the table above.
Now I know the ranges and the constraints I can test on a real chip.
A real 10bit implementation using OSC at 8 Mhz, PWM at 0.5 using a loop to control the 10bit control. It is nearly 10bit... as this would be 1016 increments where PR2 = 253
Enjoy
Last edit: Anobium 2023-12-01
Reference code on GitHub.
https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/PWM_Solutions/Device_Specific_Examples/12F683_Family_PWM/60_legacy_ccp-pwm_10_bit_mode.gcb
I think I should make it clear. These old PWM/CPP chips are not 10bit PWM at all frequencies. They are capable of 10bit only at specific mcu frequencies and specfic PWM frequencies. An example is
mcu at 4Mhz and PWM at 0.245Khz
- these will give 1020 steps ( 10 bit value). Anything abovemcu at 4Mhz and PWM at 0.487Khz
is a 9-bit step.For real 10bit PWM across all frequencies use a mcu with a true 10bit PWM ( not PWM/CPP).
:-)
Yes Evan, I confirm, I needed also to add more calculation in my code PWM2Laser to be able to manage different resolutions according frequencies (see code examples in attached picture). Needed time to understand, debug and fix, and the solution is mostly a multiplicator :)
You may have to manual update registers. The basic PWM are there for the novice users.
It would be good to have your analysis also.