You have a bit of mixtur of commands... hence the confusion.
This code will work. But, as the CCP duty constant is essentially a 8-bit number in the range of 0 to 100 I am not sure the revalance of the 16bit.
;Chip Settings#chip 16F1789,32
'cccp1 out
dir portc.2 out
#define PWM_Freq 10 'Frequency of PWM in KHz
#define PWM_Duty 50 'Duty cycle of PWM
PWMOn
Main:
goto Main
This device is not really 16bit PWM module, they simply compare a 16bit timer. There is is a specific 16bit PWM that is really 16bit. The 16f1789 is CCP fixed on the imer 2 - not a true 16bit PWM module.
For this device this works for variable PWM and duty.
'Main code'freq 40khz'variable duty from 0% to 100%do'Turn up brightness over 2.5 secondsForBright=1to255HPWM1,40,Brightwait10msnext'Turn down brightness over 2.5 secondsForBright=255to1HPWM1,40,Brightwait10msnextloop
end
Last edit: Anobium 2018-12-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
High-Performance PWM Controller:
• Four Programmable Switch Mode Controller
(PSMC) modules:
- Digital and/or analog feedback control of
PWM frequency and pulse begin/end times
- 16-bit Period, Duty Cycle and Phase
- 16 ns clock resolution
- Supports Single PWM, Complementary,
Push-Pull and 3-phase modes of operation
- Dead-band control with 8-bit counter
- Auto-shutdown and restart
- Leading and falling edge blanking
- Burst mode
Should read....not PWM but PSMC
High-Performance PSMC Controller:
• Four Programmable Switch Mode Controller
(PSMC) modules:
- Digital and/or analog feedback control of
PWM frequency and pulse begin/end times
- 16-bit Period, Duty Cycle and Phase
- 16 ns clock resolution
- Supports Single PWM, Complementary,
Push-Pull and 3-phase modes of operation
- Dead-band control with 8-bit counter
- Auto-shutdown and restart
- Leading and falling edge blanking
- Burst mode
As later in the datasheet .. it states...
Two Capture/Compare/PWM modules (CCP):
- 16-bit capture, maximum resolution 12.5 ns
- 16-bit compare, max resolution 31.25 ns
- 10-bit PWM, max frequency 32 kHz
No wonder.. people get confused.
Last edit: Anobium 2018-12-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And, in the very latest release we have included the PSMC software... so, if you have a year or two to learn PSMC then you could generate a 16bit PWM signal via the PSMC module.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all
i'm getting an 8 bit output but not 16bit.
`
`
Last edit: Anobium 2018-12-19
You have a bit of mixtur of commands... hence the confusion.
This code will work. But, as the CCP duty constant is essentially a 8-bit number in the range of 0 to 100 I am not sure the revalance of the 16bit.
This device is not really 16bit PWM module, they simply compare a 16bit timer. There is is a specific 16bit PWM that is really 16bit. The 16f1789 is CCP fixed on the imer 2 - not a true 16bit PWM module.
For this device this works for variable PWM and duty.
end
Last edit: Anobium 2018-12-19
Thanks for clearing up.
And, the datasheet is 100% incorrect.
Should read....not PWM but PSMC
As later in the datasheet .. it states...
No wonder.. people get confused.
Last edit: Anobium 2018-12-19
And, in the very latest release we have included the PSMC software... so, if you have a year or two to learn PSMC then you could generate a 16bit PWM signal via the PSMC module.
I tried the PSMC tool and got an exception error when I tried to change a value. Using Win 10
Will investigate further