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 CCS Technical Support

Variable PWM

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



Joined: 13 Apr 2007
Posts: 24

View user's profile Send private message AIM Address

Variable PWM
PostPosted: Sun Sep 16, 2007 5:09 pm     Reply with quote

hello,

Can any one suggest me if at all is it possible to generate PWM of the range 35KHz to 37kHz with 0.1kHz increase within an infinite loop where I would be checking some o/p from my sensor is high or not. I use PIC 16f877A and 20Mhz crystal. My compiler version is 4.023.

If any one can show me some example it would be appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 16, 2007 5:18 pm     Reply with quote

Normally, PWM means the frequency of the signal is constant, but the
"duty cycle" (duration) of the positive pulse changes.

Look at the image half-way down this page:
http://www.embedded.com/story/OEG20010821S0096
It shows timing diagrams of 10%, 50%, and 90% duty cycle for
the PWM waveform.

This is probably what you really want.
HOHOHAHA



Joined: 13 Apr 2007
Posts: 24

View user's profile Send private message AIM Address

Not really
PostPosted: Sun Sep 16, 2007 10:31 pm     Reply with quote

Code:

setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
setup_timer_2(T2_DIV_BY_16, 255, 1);   // Setup for 1465 Hz     
set_pwm1_duty(128);                    //  50% duty cycle


Let this be the code .. then line number 2 decides what the freuency would be set to ? right ? ( I am a bit confused after viewing your reply)

the next line
Code:
set_pwm1_duty(128); 
sets the PWM duty cycle, I thought the duty cycle usually denoted the average voltage that is going to be provided by the PIC, it it is 255 for 5V and 0 for 0V.

Till today what I understood is :

let a PIC have been configured for certain freuency, the the duty cycle will define the voltage that will be provided when the o/p is high( as it is varying due to set frequency)

I am throughly confused please explain
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 17, 2007 2:32 pm     Reply with quote

Tell us what your project is. Tell us what you want to use PWM for.
Is it to run a motor ? Is it to control the brightness of an LED ?
Post details about the project.
HOHOHAHA



Joined: 13 Apr 2007
Posts: 24

View user's profile Send private message AIM Address

My project
PostPosted: Mon Sep 17, 2007 4:53 pm     Reply with quote

In India we don't have any good distance ranging sensor. So I use TSOP1738 IR sensor to detect the IR radiated with modulated frequency of 35 to 40 KHz. Now the TSOP1738 responses to a greater range to 38KHz modulation about a distance of 2m but when I modulate it to 35.5Khz it gives me a range of 10cm, hence by changing(without again reprogramming) the generated frequency I want to detect the distance of the object placed away from the sensor.
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