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

any example to use PWM control for PIC16F877A

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



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

any example to use PWM control for PIC16F877A
PostPosted: Sun Nov 24, 2013 10:02 am     Reply with quote

Hello,

I want to use PIC16F877A pin C2 to control the brightness of the backround light of LCD display... with pulse width modulation.
I have FET connected to pin C2 and on/off control works fine.

Is there any example how to use PWM module for that purpose ?

I understand how pulse width modulation works in theory but I had no success to get it work though I tried it make to work in many ways ...
if you want please help me ...

I do not understand this ccs manual good example how to use it:
Code:

// For a 20 mhz clock, 1.2 khz frequency,
// t2DIV set to 16
// the following sets the duty to 50% (or 416 us).
long duty;
duty = 512; // .000416/(16*(1/20000000))
set_pwm1_duty(duty);

I'm very pleased for this good discussion forum ...

all the best for you all

-arto-
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Nov 24, 2013 12:53 pm     Reply with quote

you need to:
** setup timer 2 for frequency control

and then
** setup the pwm module for PWM output
per the ccs manual

CCS compiler will handle the TRIS for you

look at MR.T's code in this post

http://www.ccsinfo.com/forum/viewtopic.php?t=51167&highlight=pwm+setup
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 24, 2013 1:03 pm     Reply with quote

asmboy wrote:
you need to:
** setup timer 2 for frequency control

and then
** setup the pwm module for PWM output
per the ccs manual

CCS compiler will handle the TRIS for you

look at MR.T's code in this post

http://www.ccsinfo.com/forum/viewtopic.php?t=51167&highlight=pwm+setup


OK

very good ... but how I do it in practice ?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Nov 24, 2013 1:33 pm     Reply with quote

see figure 2 for a block diagram of a useful circuit

http://www.electronicsnews.com.au/features/power-converters-stretch-battery-budget
artohautala



Joined: 17 Nov 2011
Posts: 187

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 24, 2013 1:49 pm     Reply with quote

asmboy wrote:
see figure 2 for a block diagram of a useful circuit

http://www.electronicsnews.com.au/features/power-converters-stretch-battery-budget



maybe wrong link Wink
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Nov 25, 2013 7:47 am     Reply with quote

fig 2 is a simple block diagram of a buck modulator

which is a classic way to use PWM for adjusting the output power of a fixed supply. with a 5V dc input - substitute a P channel FET for the transistor, and direct drive the gate with the PIC PWM Output to vary the power sent to an LED back light and your problem is solved.
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