Because the duty cycle control bits are spread across two registers, it confused me too, but Henrik helped me on this, here 's a little sub routine that I put into my program based on what I gleaned from Henrik....
(it's not specific to the 12f683 & I've not checked, but it shows you the approach)
Code:
change_hpwm:
CCP1CON.4 = Duty.0 'Bit 0
CCP1CON.5 = Duty.1 'Bit 1
CCPR1L = Duty >> 2 'Bit 2-7
return
...just remember to declare duty variable as a word, therefore
So now, to change the duty cycle, it's as simple as for example...
Code:
duty = 253
gosub change_hpwm
(btw I used to use 12f683, but for a few cents more...buy the 12F1822, it's much more flexible)
Bookmarks