CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Please kindly help about half bridge PWM - ECCP unit 16F887

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
phamngockienbp



Joined: 14 Aug 2019
Posts: 9

View user's profile Send private message

Please kindly help about half bridge PWM - ECCP unit 16F887
PostPosted: Sat Aug 24, 2019 9:27 am     Reply with quote

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: 6808
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 24, 2019 9:49 am     Reply with quote

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: 20759

View user's profile Send private message

PostPosted: Sat Aug 24, 2019 7:48 pm     Reply with quote

Use the CCS forum's search page:
http://www.ccsinfo.com/forum/search.php
Put the following text into the search box:
Quote:
CCP_PWM_HALF_BRIDGE 16F88*

Select the following tick box:
Quote:
[x] Search for all terms

Then click the search button. You will find sample code.

Example of sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=45399&start=11
phamngockienbp



Joined: 14 Aug 2019
Posts: 9

View user's profile Send private message

PostPosted: Sun Aug 25, 2019 12:04 am     Reply with quote

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: 14625

View user's profile Send private message

PostPosted: Sun Aug 25, 2019 12:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Aug 25, 2019 2:04 am     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group