Page 1 of 1

16F1507 problem with PWM channel 4 in V7

Posted: Mon Nov 14, 2016 6:26 pm
by stylo
I have constructed a 4 channel PWM colour changing program in V7
My understanding is that the 16F1507 has 4 identical 10 bit PWM channels
but in my program channels 1,2, and 3 are fine and work in10 bit but the fourth channel appears to work only in 8 bit.
Am I missing something, any help most appreciated.
Stylo

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Mon Nov 14, 2016 6:40 pm
by QMESAR
stylo wrote: My understanding is that the 16F1507 has 4 identical 10 bit PWM channels
but in my program channels 1,2, and 3 are fine and work in 10 bit but the fourth channel appears to work only in 8 bit.
Am I missing something, any help most appreciated.
Can you post your flowchart that we can see the code also how do you determine that the CH4 is only 8 Bits ?

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Tue Nov 15, 2016 12:40 pm
by stylo
Hi Peter
Thanks for responding
It may help if I explain the program.
The program takes a 4 bit input from a radio connected 15 button remote.
Each number 1 to 16 places a pre programed 4 channel lighting set up (including a fade speed)
Into the PIC Chip 16F1507 the program then either lowers or lifts each of the 4 lighting channels, by comparing each channel with its previous setting.
The four channels are all set up the same (10 bit ) but only channels 1,2 and 3 work at 10 bit (1024 count) the fourth channel runs in 8 bits (256 count) and rolls over 4 times when counting from 1 to 1024.
Have attached my UNFINISHED flow chart

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Tue Nov 15, 2016 12:54 pm
by QMESAR
Hi stylo,

I will try to look into this as I have a interest in these small pic's ,I am no way and expert with them yet that being the reason I ask your FC Flowchart to see if I can understand the problem or find how to get all channels running the same, I will be back this might take a day or 3 :D

Will be happy if one of the more experienced people will shed light on this in the mean time

good luck hope we solve this soon

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Tue Nov 15, 2016 1:39 pm
by QMESAR
Hi stylo,

Looking at the Flowchart my thinking at the moment is
1 I have used similar devices and all PWM's work exactly the same and I would expect the 1507 not to be different
2 if the FC componet run PWM 1,2 and 3 Correctly it is unlikely that the FC component is the problem on PWM4

I would do the Following

I would make a simply Flowchart with the 4 PWM and set then to the exact same duty cycle and measure the duty cycle if this show a 25% difference between PWM4 and the others then it could be the FC component on PWM4 if they are the same then it up to debug the variables that you use to set the Duty cycle ,

I unfortuenately can not run this test as I am far away from my lab and will only be at my lab after 30 Nov 2016 however I would like to see the results from such a test

maybe you try this and inform us :D

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Tue Nov 15, 2016 8:10 pm
by Benj
Hi Stylo,

A couple of comments on things I've spotted in your program.

The PWM components are all set to timer 2 but PWM1 has a different prescaler setting to the other PWM components, you will get the prescaler you enable last unless you assign a different timer.

Second the PWM enable macros are inside the loop, these should ideally be before the loop or you're constantly re-initialising the module every cycle.

I'm not sure if either of these are to do with the weirdness on PWM channel 4. I've looked at the code and it seems like it should be working fine.

Code: Select all

	#if (MX_PWM_CHANNEL_X == 3)
			PWM3DCH = duty >> 2;			//8MSB HHHHHHHH
			PWM3DCL = duty << 6;			//2LSB LL000000
	#endif

	#if (MX_PWM_CHANNEL_X == 4)
			PWM4DCH = duty >> 2;			//8MSB HHHHHHHH
			PWM4DCL = duty << 6;			//2LSB LL000000
	#endif

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Thu Nov 17, 2016 11:27 am
by stylo
Thanks guys,
I have taken your observations on board; will now go and hopefully sort the problem out.
I think benj’s comment to make a separate SIMPLE PWM test program and work on that first is always an excellent idea.
I will keep you posted, but it may be a day or two as I have other commitments.
Thanks again
stylo

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Tue Nov 22, 2016 11:42 am
by stylo
Hi Guys
Problem solved. My fault!, I think?http://ww.matrixmultimedia.com/mmforums ... 6b12dc9336#
The fourth channel “Ch_4” had Byte instead of Integer (pre fix “B” instead of “Z”) in the “Properties Macro”……..”Set duty cycle 10 bit” changed it by going to “Expression”……..“Ch_4”…….. “Edit” and changed It to “Int”
Should it have automatically put in int when I chose 10 bit in the 4th channel in my original program?
Thanks again for all your help,
Stylo

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Tue Nov 22, 2016 11:58 am
by QMESAR
Great news :D

Re: 16F1507 problem with PWM channel 4 in V7

Posted: Tue Nov 22, 2016 12:14 pm
by stylo
Sorry about the garbage in the first line of my email. Brain disengaged :(
Stylo