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

pwm problem in pic 18f84431

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



Joined: 14 Mar 2015
Posts: 9

View user's profile Send private message

pwm problem in pic 18f84431
PostPosted: Sun Mar 15, 2015 11:54 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 15, 2015 1:41 pm     Reply with quote

Which PWM?.
For the standard PWM's: set_timer2(0);
saniat



Joined: 14 Mar 2015
Posts: 9

View user's profile Send private message

PostPosted: Mon Mar 16, 2015 3:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 16, 2015 4:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 16, 2015 4:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 16, 2015 5:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 16, 2015 5:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 16, 2015 8:49 am     Reply with quote

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.
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