View previous topic :: View next topic |
Author |
Message |
saniat
Joined: 14 Mar 2015 Posts: 9
|
pwm problem in pic 18f84431 |
Posted: Sun Mar 15, 2015 11:54 am |
|
|
hello,
I am using pic 18f84431. I got this assignment that i have to generate a PWM signal which will start after 10us. Now i understand that i will wait for 10us then set the timer to zero (as setting the timer to zero starts the signal). But i don't understand how will i implement this in C.
PWM frequency can be 5khz with 50 duty cycle.
thanks
saniat |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sun Mar 15, 2015 1:41 pm |
|
|
Which PWM?.
For the standard PWM's: set_timer2(0); |
|
|
saniat
Joined: 14 Mar 2015 Posts: 9
|
|
Posted: Mon Mar 16, 2015 3:24 am |
|
|
this is a simple pwm using standard module. how can use the set_timer2(0) to have a 10us delay start a pwm signal?
Code: | #include <18F4431.h>
#device adc=10
#include <math.h>
#fuses XT,NOWDT,NOLVP
#use delay(crystal=20000000)
// this is a simple generation of PWm signal using the CCP1 modude(pin C2) using timer2 inturrupt.
void main()
{
setup_timer_2(T2_DIV_BY_4,255,1); // 20MHz clock, prescaler=1, resolution=4 *256=1024. formula: (20*1000)/(4*4*256)=4.88khz pwm frequency
setup_ccp1(CCP_PWM);
set_pwm1_duty(511L);// 50% duty cycle
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Mar 16, 2015 4:20 am |
|
|
delay_us(10);
set_timer2(0);
However do understand that the signal 'starts' as soon as you program the PWM. What setting the timer does is change where you are in the waveform. |
|
|
saniat
Joined: 14 Mar 2015 Posts: 9
|
|
Posted: Mon Mar 16, 2015 4:36 am |
|
|
so do i get a 10 us shift from the original signal?when i say the original signal i mean the signal without the 10us delay.
thank you
saniat |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Mar 16, 2015 5:03 am |
|
|
You get 10uSec, plus a couple of instruction times. The instructions the processor takes to load the timer. Nothing is ever 'instantaneous'.... |
|
|
saniat
Joined: 14 Mar 2015 Posts: 9
|
|
Posted: Mon Mar 16, 2015 5:57 am |
|
|
so if generate a power pwm and a standard pwm (both same frequency and duty), by this way i can show a phase shift between 1 power pwm signal and a standard pwm signal. am i right? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Mar 16, 2015 8:49 am |
|
|
Try searching the forum, rather than asking questions that have been answered before:
<http://www.ccsinfo.com/forum/viewtopic.php?t=53509>
Only a few weeks ago. |
|
|
|