View previous topic :: View next topic |
Author |
Message |
phamngockienbp
Joined: 14 Aug 2019 Posts: 9
|
Please kindly help about half bridge PWM - ECCP unit 16F887 |
Posted: Sat Aug 24, 2019 9:27 am |
|
|
Hi everyone
I would like to use half bridge pwm from ECCP unit of pic 16F887.
My code is as below:
Code: |
setup_timer_2(T2_DIV_BY_1,199,1);
setup_ccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_H);
set_pwm1_duty(100); // 50% duty cycle. |
With this code, pic will generate pwm at pin P1A and then pwm at pin P1B will vary in accordance with duty cycle of pin P1A.
I wonder if there is any way to reverse pwm at pin P1A and P1B
Please kindly help me in this regard. Thank you! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sat Aug 24, 2019 9:49 am |
|
|
IF you change the mode from 'active-high' to 'active-low' that may do what you want.
I can't test my idea today though...not 'on the bench'.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
phamngockienbp
Joined: 14 Aug 2019 Posts: 9
|
|
Posted: Sun Aug 25, 2019 12:04 am |
|
|
Hi
Thank you for your help.
What I mean is: I wonder if we can set spwm at pin P1B ( P1B will be at high level first ) and then pwm at Pin P1A will vary accordance with duty cycle from P1B.
Example: If I set 60 % duty cycle at P1B so P1B will be at high level 60% and P1A will be at high level at the rest 40 %...
I'm not so good at writing in English. Hope you can guest what I mean.
Thank you! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Sun Aug 25, 2019 12:40 am |
|
|
Temtronic's suggestion should do this.
Understand:
PWM 'A' 10% _________-
PWM 'A' 20% ________--
etc.
Now if you select 'active low' instead, you get:
PWM 'A' 10% ---------_
PWM 'A' 20% --------__
The output is inverted.
Now the PWM 'B' output is the inverted version of 'A' (except if you start
using 'deadband'), is inverting both, gives you the waveform that would
normally be on 'A', on the 'B' pin, and the waveform that would normally
be on 'B' on the 'A' pin.
In the data sheet, look at the diagram entitled
"EXAMPLE PWM (ENHANCED MODE) OUTPUT RELATIONSHIPS
(ACTIVE-HIGH STATE)",
and compare with the next diagram entitled:
"EXAMPLE ENHANCED PWM OUTPUT RELATIONSHIPS (ACTIVE-LOW
STATE)".
CCP_PWM_L_L gives this. |
|
|
phamngockienbp
Joined: 14 Aug 2019 Posts: 9
|
|
Posted: Sun Aug 25, 2019 2:04 am |
|
|
Hi Temtronic, PCM programmer and Ttelmah
Thank you very much for your kindly help! I had changed my code same as what you suggested and then testing it with the real PCB. It worked really well as expected.
Thank you once again!
Have a nice weekend! |
|
|
|