View previous topic :: View next topic |
Author |
Message |
HOHOHAHA
Joined: 13 Apr 2007 Posts: 24
|
Variable PWM |
Posted: Sun Sep 16, 2007 5:09 pm |
|
|
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
|
|
Posted: Sun Sep 16, 2007 5:18 pm |
|
|
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
|
Not really |
Posted: Sun Sep 16, 2007 10:31 pm |
|
|
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
|
|
Posted: Mon Sep 17, 2007 2:32 pm |
|
|
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
|
My project |
Posted: Mon Sep 17, 2007 4:53 pm |
|
|
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. |
|
|
|