I am using a 16F737 with PBP 2.46
There's an example in this thread for controlling all three channels on this
PIC. http://www.picbasic.co.uk/forum/show...highlight=hpwm
I suggest you do it the way BRUCE suggested. set them manually, by setting the registers yourself. here is an example for the 5khz case for the pic16f737 that I made, just for you: you may need to tweak it a bit to adjust the frequency by changing the PR2 value. (Dont forget that the value for the duty variable has to be 4x the PR2 value.) So if you change your PR2 Value... make sure you change the value of the duty varaible accordingly.
Enjoy,
Srig
-----------------------------------------------------------------
Duty1 var Byte 'Variable for controlling the PWM in CCP1
Duty2 Var Byte 'Variable for controlling the pwm in CCP2
Duty3 Var Byte 'Variable for controlling the PWM in CCP3
CCP1CON = %00001100 'Using CCP1 as PWM Mode Register 9-1 in Datasheet
CCP2CON = %00001100 'Using CCP2 as PWM Mode Register 9-1 in Datasheet
CCP3CON = %00001100 'Using CCP3 as PWM Mode Register 9-1 in Datasheet
T2CON = %00000101
TRISC.2 = 0 'Setting the CCP1 PIN as OUTPUT
TRISC.1 = 0 'Setting the CCP2 PIN as OUTPUT
TRISB.5 = 0 'Setting the CCP3 PIN as OUTPUT
Duty1 = 0
Duty2 = 0
Duty3 = 0
' Fosc = Clock Frequency (4MHz)
' PS = Timer2 Prescale Value (T2CON<1:0>)
' Freq = PWM output frequency
' Duty% = Duty cycle (20% = 0.2)
' formulas:
' PR2=(Fosc/(4*PS*Freq))-1
' CCPR1L:CCP1CON<5:4>=(PR2+1)*4*Duty%
PR2 = 50 with prescalar of 4 in Timer2
For i = 0 to 200
Duty1 = Duty1 + 1
CCP1CON.4 = Duty1.0
CCP1CON.5 = Duty1.1
CCPR1L = Duty1 >> 2
Pause 17
Next i
For i = 0 to 200
Duty2 = Duty2 + 1
CCP2CON.4 = Duty2.0
CCP2CON.5 = Duty2.1
CCPR2L = Duty2 >> 2
Pause 17
Next i
for i = 0 to 200
Duty3 = Duty3 + 1
CCP3CON.4 = Duty3.0
CCP3CON.5 = Duty3.1
CCPR3L = Duty3 >> 2
Pause 17
Next i
---------------------------------------------
Last edited by Srigopal007; - 7th March 2006 at 17:11.
thanks for the post.
I am understanding some of this, but since I am still at a novice level, some parts and variables aren't clicking yet. In my user interface, the user is able to use the up and down buttons to change the color level from 0 to 255. Mathmatically, how would I incorporate that into this configuration?
Thank you for all your help so far. I dont mean for you to do all the work for me. I am sifting through manuals and datasheets trying to wrap my mind around some of this.
Also, in my haste to post, I mixed up my PIC #, its actually a 767.
Last edited by docwisdom; - 7th March 2006 at 18:11.
The code which I gave you, should work for any of the PIC16F737/767/777 product of family.
I would love to help you out, but I cannot do all the work for you, or else you will not learn. Why dont you go ahead and try things out first, and then come back if you have any more errors/ problems. I think the code which I have posted in my previous post should get you started.
Thanks for all the help so far, and sorry for the long gap between posts.
This code works, and it works beautifully. Now all I need is to make a little more user friendly. As it stands right now, value 0 is 100%, and 204 is 0%. Somehow I need to make a calculation so my user sees 0 to 100% not 204 to 0. I also need to make limit blocks at 0 and 100.
I am working on the stops right now, but the code I have tried to divide and invert the numbers just isnt working right.
thanks
-brian
Bookmarks