16F737 10bit PWM CH2 duty is bugged?

Moderator: Benj

Post Reply
medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

16F737 10bit PWM CH2 duty is bugged?

Post by medelec35 »

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.
Martin

medelec35
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?

Post by medelec35 »

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.
Duty test.JPG
Duty test.JPG (27.39 KiB) Viewed 6434 times
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

medelec35
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?

Post by medelec35 »

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 8)
Thanks.
Duty test 0x51 duty .JPG
Duty test 0x51 duty .JPG (26.96 KiB) Viewed 6416 times
Duty test 0x59 duty .JPG
Duty test 0x59 duty .JPG (27.13 KiB) Viewed 6415 times
As you can see with the 2nd picture, with Duty set at 0x59 CCP2 duty =0%.
CCP1 is still working normally
Martin

medelec35
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?

Post by medelec35 »

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 :P
Some how the V3 10bit PWM channel bug got pased on to V4 uncorrected.
Ben did say:
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.
Duty test 0x59 duty V3 Flowcode .JPG
Duty test 0x59 duty V3 Flowcode .JPG (28.4 KiB) Viewed 6394 times
This is from V3 with corrected PWM_Code.c file, with duty on both 10bit channels set at 0x59.
Last edited by medelec35 on Mon Jun 29, 2009 10:15 pm, edited 1 time in total.
Martin

Sean
Valued Contributor
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?

Post by Sean »

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:
PIC_PWM.c
(7.57 KiB) Downloaded 416 times

medelec35
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?

Post by medelec35 »

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!
Martin

Post Reply