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

timer2 period program
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 18, 2010 5:38 pm     Reply with quote

You want us to design the timer parameters for you.
Instead, I suggest that you use an online PIC Timer2 calculator.
http://eng-serve.com/pic/pic_timer.html

Edit the Oscillator Frequency box so it uses your Oscillator frequency,
which I believe is 20 MHz (20000000).

Then move the sliders down at the bottom to set the Prescaler, Postscaler,
and PR2 register values. At the bottom, it will tell you the frequency in
Hz, and the period in seconds. So you want 0.0014 seconds (1.4 ms).

Start by setting it for 1:16 Prescaler, 1:2 Postscaler, then move the PR2
slider until you get 0.0014 second. Then you can read the PR2 value
from the webpage.

You should do this.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Tue Oct 19, 2010 11:39 am     Reply with quote

hi

I have some confusion...

on my configuration setup_timer_2(T2_DIV_BY_16,242,16);

what is number 242

when I use set_timer2(100) my range start in 100 at 242 or 256?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 19, 2010 12:32 pm     Reply with quote

242 is the PR2 register number for Timer2.

For your other questions, read this tutorial:
http://www.microcontrollerboard.com/pic-timer2-tutorial.html
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Tue Oct 19, 2010 12:46 pm     Reply with quote

I know that and I have read this page... my problem is know what happens when I call set_timer1()

I configurate timer1 with PR2 = 242 on main function but I don't know if when I call set_timer1() this value of PR2 is changed or not...

if value is change I need considerate my range 0 to 256 but if it don't change my range is 0 to 242....

this is my problem... because I don't have oscilloscope at friday Confused
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Oct 21, 2010 5:03 pm     Reply with quote

hi

Someone can tell me if my calculations stay correct? I need have pulses positives on timer1 with 1.6ms and on timer2 with 1.4ms.
Code:

#int_TIMER1             //every 1.6ms - 16bits
void TIMER1_isr(void)
{

   if (!pause_cycle)
   {
      output_high(S1SP);
      set_timer1(57535);      //SPEED = 65535 - (1.6ms/(4/20Mhz))
      pause_cycle = 1;       
   } else
   {
   output_low(S1SP);
   pause_cycle = 0;
   }
   
}

#int_TIMER2             //every 1.4ms - 8bits
void TIMER2isr(void)
{
   if (!pause_cycle2)
   {
      output_high(S2DR);
      set_timer2(228);      //STEERING = 255 - ((1.4ms/((4*255)/20Mhz))
      pause_cycle2 = 1;
   } else
   {
   output_low(S2DR);
   pause_cycle2 = 0;
   }
}

(...)
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);   //periode 13.1ms
setup_timer_2(T2_DIV_BY_16,255,16);             //periode 13.1ms


PS: I work with PIC18F252 at 20MHz.

best regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri Oct 22, 2010 10:28 am     Reply with quote

hi

Is normal in oscilloscope I see my timer2 with a wave with 50% duty cycle very different of 1.4ms??

I don't understand where stay wrong my code... someone see it?

best regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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