Hi
I use a P16F1939 with Fosc=4MHz (internal module). I do like to configure three CCP outputs of it (it offers up to 5) to produce 3 PWM (or pulse streams) with period=15msec and duty cycle=33% (or ON=5msec and OFF=10msec). Using the PWM component provided by FlowCode i can obtain a max period=4msec and given the Fosc of micro (Tosc=Fosc/4 and then PrescalerMAX = 1:16) it is logical. Ihave checked it with scope on actual hardware, simulator shows wrong things unless i am missing something.
Have you any idea (or program instruction?) of how i can increase the period of PWM to 15msec under the given Fosc of micro? And to set the PWM duty cycle at 33% (i.e. 5msec). I need this to realize a power saving circuit for common type relays instead to use latching relays.
It should be noted that i can't minimize the micro Fosc of 4MHz to e.g. 1MHz - which can provide PWM with period of up to 16msec - because i want to be compatible with the RC5 receiver component macro.
Thanks for any help
Producing PWM with 15msec period
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Producing PWM with 15msec period
Hello,
Might not be possible using the PWM as the component should expose all the options possible.
However using a timer2 interrupt it should be possible.
Here is a example config to get a 1000Hz interrupt using timer 2 at 4MHz.
Might not be possible using the PWM as the component should expose all the options possible.
However using a timer2 interrupt it should be possible.
Here is a example config to get a 1000Hz interrupt using timer 2 at 4MHz.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- fotios
- Posts: 458
- Joined: Mon Feb 08, 2010 10:17 am
- Location: Greece
- Has thanked: 109 times
- Been thanked: 117 times
Re: Producing PWM with 15msec period
Hi Ben
My intention is to produce 3 individually activated pulses to drive 3 relays. Using 3 TMR interrupts to this could cause side effects. So i did some calculations to use 3 of the 5 CCP modules provided by P16F1939. The coil of relay must be powered for the less possible time so as to consume the less possible power without opening its contacts. I've tried the method you propose on one relay but its contacts produce an amazingly loud noise of 66.6Hz!
Then i tried a CCP module configured in its max possible period (Period Register = 255, Prescaler Divide = 1) which results - under the given Fosc of 4MHz - in a period of 256μsec ( F=3906.25Hz). I selected a Duty Cycle = 33% (84.48μsec). I've tried the code on actual hardware and the relay works nicely without any noise. Because i was bothering maybe this setting consumes more power i did a comparison of both period settings side by side per 1 second:
a) 15msec period pulse, 33% duty cycle:
The pulse is going ON for: 1sec / 15msec = 66.66 times. For 33% Duty cycle (5msec) current flows thru the coil of relay for: 66.66times X 5msec Duty cycle = 333.33msec per each second
b) 256μsec period pulse, 33% duty cycle:
The pulse is going ON for: 1sec / 256μsec = 3,906.25 times. For 33% duty cycle (84.48μsec) current flows thru the coil of relay for: 3,906.25times X 84.48μsec Duty cycle = 330msec per each second.
If my calculations are correct, in both cases the coil of relay is active for the same time, no maters how much is the period of pulse. So the main factor is only the duty cycle of pulses. For the same duty cycle, any pulse of any period provides the same ON and OFF time. Just for the record, the DC resistance of contacts when is used the above described power saving configuration is about 3.5Ω.
Please check the above and correct me if I am wrong.
Cheers
Fotis
My intention is to produce 3 individually activated pulses to drive 3 relays. Using 3 TMR interrupts to this could cause side effects. So i did some calculations to use 3 of the 5 CCP modules provided by P16F1939. The coil of relay must be powered for the less possible time so as to consume the less possible power without opening its contacts. I've tried the method you propose on one relay but its contacts produce an amazingly loud noise of 66.6Hz!
Then i tried a CCP module configured in its max possible period (Period Register = 255, Prescaler Divide = 1) which results - under the given Fosc of 4MHz - in a period of 256μsec ( F=3906.25Hz). I selected a Duty Cycle = 33% (84.48μsec). I've tried the code on actual hardware and the relay works nicely without any noise. Because i was bothering maybe this setting consumes more power i did a comparison of both period settings side by side per 1 second:
a) 15msec period pulse, 33% duty cycle:
The pulse is going ON for: 1sec / 15msec = 66.66 times. For 33% Duty cycle (5msec) current flows thru the coil of relay for: 66.66times X 5msec Duty cycle = 333.33msec per each second
b) 256μsec period pulse, 33% duty cycle:
The pulse is going ON for: 1sec / 256μsec = 3,906.25 times. For 33% duty cycle (84.48μsec) current flows thru the coil of relay for: 3,906.25times X 84.48μsec Duty cycle = 330msec per each second.
If my calculations are correct, in both cases the coil of relay is active for the same time, no maters how much is the period of pulse. So the main factor is only the duty cycle of pulses. For the same duty cycle, any pulse of any period provides the same ON and OFF time. Just for the record, the DC resistance of contacts when is used the above described power saving configuration is about 3.5Ω.
Please check the above and correct me if I am wrong.
Cheers
Fotis
Best Regards FOTIS ANAGNOSTOU
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Producing PWM with 15msec period
Hi Fotis,
Sorry if I have the wrong idea as not got much time to read post properly.
The flowchart can be created so all three pulses start at the same time, and all three variables and timer interrupt variable(e.g called count) is also reset.
Then you would increment each variable (including count) by 1, until variable has reached its desired value, then pulse will be off until interrupt variable ( count) reaches it's maximum value then as interrupt value is reset to zero all three pulses are on again.
Hope I have explained it ok?
Martin
Sorry if I have the wrong idea as not got much time to read post properly.
You don't require 3 timer interrupts, just one interrupt & 3 variables.fotios wrote:Using 3 TMR interrupts to this could cause side effects.
The flowchart can be created so all three pulses start at the same time, and all three variables and timer interrupt variable(e.g called count) is also reset.
Then you would increment each variable (including count) by 1, until variable has reached its desired value, then pulse will be off until interrupt variable ( count) reaches it's maximum value then as interrupt value is reset to zero all three pulses are on again.
Hope I have explained it ok?
Martin
Martin