| View previous topic :: View next topic |
| Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 18, 2010 5:38 pm |
|
|
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
|
|
Posted: Tue Oct 19, 2010 11:39 am |
|
|
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
|
|
 |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Tue Oct 19, 2010 12:46 pm |
|
|
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  |
|
 |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Oct 21, 2010 5:03 pm |
|
|
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
|
|
Posted: Fri Oct 22, 2010 10:28 am |
|
|
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 |
|
 |
|