PWM settings are:
Period register =249
Clock source = clk/4
Clock speed 4.0MHz
period = 1000.0us
Frequency = 1.0KHz
C Code: osccon = 0x60;
Config = 0x2007,0x3f98
Using SetDutyCycle 10bit
so if I set nldx = 2
nDuty(INT) = 80
On real hardware CCP2 (pin 12) PWM duty is measured at 1.6%
Channel 1 (CCP1 pin 13) is measured at 8%
I would suspect CCP1 is correct, since both Flowcode simulator and 12F615 hardware both show duty is 8%
Would you mind checking if flowcode is at fault or not please.
I will also obtain another 16F737, since hardware fault is possible.
16F737 10bit PWM CH2 duty is bugged?
Moderator: Benj
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 16F737 10bit PWM CH2 duty is bugged?
I have created a simple duty test program. Since I already have a pot connected to hardware,
Duty increases when pot is near minimum, and decreases when near maximum. (it was done this was since ADC channels disconnect which resets ADC0 to 0 in simulator) It can be annoying but it must have been done that way for a reason?
I have just used a different simulator. Loaded with generated hex code. Same variable used for both PWM1 and PWM2.
Both duties on Flowcode simulator are same, however they are not the same on this other simulator.
So I don’t believe it is hardware fault. Above is Duty for both set at 0x52
Note: short time of 100us is used since simulation time is much slower than real time. If using on real hardware, then this time will need to be inreased
Duty increases when pot is near minimum, and decreases when near maximum. (it was done this was since ADC channels disconnect which resets ADC0 to 0 in simulator) It can be annoying but it must have been done that way for a reason?
I have just used a different simulator. Loaded with generated hex code. Same variable used for both PWM1 and PWM2.
Both duties on Flowcode simulator are same, however they are not the same on this other simulator.
So I don’t believe it is hardware fault. Above is Duty for both set at 0x52
Note: short time of 100us is used since simulation time is much slower than real time. If using on real hardware, then this time will need to be inreased
- Attachments
-
- Duty Test.fcf
- (7 KiB) Downloaded 354 times
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 16F737 10bit PWM CH2 duty is bugged?
The picture in previous post was not the best example. So here are some more.
If this can be sovled I will be really greatful, since I have nearly finished my project
Thanks. As you can see with the 2nd picture, with Duty set at 0x59 CCP2 duty =0%.
CCP1 is still working normally
If this can be sovled I will be really greatful, since I have nearly finished my project

Thanks. As you can see with the 2nd picture, with Duty set at 0x59 CCP2 duty =0%.
CCP1 is still working normally
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 16F737 10bit PWM CH2 duty is bugged?
I had the same issue with V3. See: http://www.matrixmultimedia.com/mmforum ... =23&t=5222
Ben posted a file which sorted that problem out. I just created a V3 test and both pwm channels are working as they should be.
V4 does not have the same PWM_Code.c, and ocx editing is not my strong point
Some how the V3 10bit PWM channel bug got pased on to V4 uncorrected.
Ben did say:
Ben posted a file which sorted that problem out. I just created a V3 test and both pwm channels are working as they should be.
V4 does not have the same PWM_Code.c, and ocx editing is not my strong point

Some how the V3 10bit PWM channel bug got pased on to V4 uncorrected.
Ben did say:
This is from V3 with corrected PWM_Code.c file, with duty on both 10bit channels set at 0x59.Benj wrote: The C code in the component was actually correct however due to some small inconsistencies with the BoostC compiler statements such as
var1 &= var2
var1 |= var2
do not work properly. Replacing these statements with
var1 = var1 & var2
var1 = var1 | var2
made the problems go away. Thats why it took me a while to spot the problem as the statements were working for channel 1 but for some reason not for channel 2.
Last edited by medelec35 on Mon Jun 29, 2009 10:15 pm, edited 1 time in total.
Martin
-
- Valued Contributor
- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
Re: 16F737 10bit PWM CH2 duty is bugged?
I have found and corrected the fault in the C file for the PWM component.
If you copy this file into the components folder of your Flowcode V4 installation, it should resolve the problem:
If you copy this file into the components folder of your Flowcode V4 installation, it should resolve the problem:
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: 16F737 10bit PWM CH2 duty is bugged?
Thanks sean, I was in the process of renaming file ben posted, then placing that in V4 components directory.
Just saw your post in time!
Edit* All working now. Thanks again!
Just saw your post in time!
Edit* All working now. Thanks again!
Martin