View previous topic :: View next topic |
Author |
Message |
praveen_karimilla
Joined: 30 Nov 2008 Posts: 8
|
PIC18F1320 timers |
Posted: Sun Nov 30, 2008 5:37 pm |
|
|
Hi everybody,
I want to set the Timer0 of 18F1320 in 16 bit mode. Can anyone help with the ccs code ?
plzzzz |
|
|
praveen_karimilla
Joined: 30 Nov 2008 Posts: 8
|
|
Posted: Sun Nov 30, 2008 5:47 pm |
|
|
can any one plzz help me |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 30, 2008 5:48 pm |
|
|
Look at the setup_timer_0() function in the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Also look at the "Timer 0" section in the 18F1320.H file. You will see
a list of parameters that can be used with the setup_timer_0() function.
Here is the file location on your hard drive:
Quote: | c:\program files\picc\devices\18f1320.h |
Then try to write the code. |
|
|
praveen_karimilla
Joined: 30 Nov 2008 Posts: 8
|
|
Posted: Sun Nov 30, 2008 5:55 pm |
|
|
i tried to write the code by doing all but the same problem still persists hi can u help me with the code to use a timer 1 of pic18f1320 in 16 bit mode, the problemm is after it counts until FF and then overflows to oo but i want it to count until ffff can u please help me |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 30, 2008 6:06 pm |
|
|
Post a small test program that shows the problem. |
|
|
praveen_karimilla
Joined: 30 Nov 2008 Posts: 8
|
|
Posted: Sun Nov 30, 2008 7:48 pm |
|
|
Code: | /* program to show the direction of digital compass through
LED switch board using PIC18F1320*/
/* created by Praveen karimilla Msc embedded systems 000496944*/
#include<18F1320.H>
#fuses WDT,NOWDT,
#use delay(clock=4000000)
#define L1 PIN_B0
#define L2 PIN_B1
#define L3 PIN_B2
#define L4 PIN_B3
#define L5 PIN_B4
#define L6 PIN_B5
#define Time1 100
#define Time2 690
#define Time3 700
#define Time4 1290
#define Time5 1300
#define Time6 1890
#define Time7 1900
#define Time8 2490
#define Time9 2500
#define Time10 3090
#define Time11 3100
#define Time12 3700
void main(void)
{
int value;
int loop;
loop1:
output_b(0)
while(!input(PIN_A1))
{
}
setup_timer_1(1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
while (input(PIN_A1) ) // waits for A1 to go high
{
}
setup_timer_1(0);
value=get_timer1();
if (value>=Time1 && value<=Time2)
output_high(L1);
if (value>=Time3 && value<=Time4)
output_high(L2);
if (value>=Time5 && value<=Time6)
output_high(L3);
if (value>=Time7 && value<=Time8)
output_high(L4);
if (value>=Time9 && value<=Time10)
output_high(L5);
if (value>=Time11 && value<=Time12)
output_high(L6);
goto loop1;
} |
This program is to identify the time. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 30, 2008 8:00 pm |
|
|
Quote: | void main(void)
{
int value;
int loop;
value=get_timer1();
|
In CCS, an 'int' is an unsigned 8-bit integer. It can only hold a value
from 0 to 255. You need to change the declaration of value to be 'int16'.
Look at this section in the CCS manual. Notice how the default data
types for 'int', 'long', 'short', etc., are different from MSVC++.
It's important to remember this when writing a program in CCS.
Quote: | Basic and Special types |
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Quote: | #include<18F1320.H>
#fuses WDT,NOWDT,
#use delay(clock=4000000) |
You need to add a fuse for the oscillator. For 4 MHz, you should use
the XT fuse. |
|
|
Guest
|
|
Posted: Sun Nov 30, 2008 8:51 pm |
|
|
i tried by using long value; but the timer high byte is not incrementing |
|
|
praveen_karimilla
Joined: 30 Nov 2008 Posts: 8
|
|
Posted: Sun Nov 30, 2008 8:53 pm |
|
|
i tried by using long value; but the timer high byte is not incrementing |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 30, 2008 8:59 pm |
|
|
Quote: | setup_timer_1(1); // *** Not necessary ***
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
while (input(PIN_A1) ) // waits for A1 to go high
{
}
setup_timer_1(0); |
The lines shown in bold are incorrect. You are calling setup_timer_1()
three times. You should only call it once.
The last line should be changed to set_timer0(0); (not "setup"). |
|
|
praveen_karimilla
Joined: 30 Nov 2008 Posts: 8
|
|
Posted: Tue Dec 02, 2008 3:11 am |
|
|
i changed the instruction as well but the timer high byte is not increasing |
|
|
praveen_karimilla
Joined: 30 Nov 2008 Posts: 8
|
|
Posted: Tue Dec 02, 2008 3:15 am |
|
|
can any one help me plzzzzzzzz |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 02, 2008 2:18 pm |
|
|
Post your new test program. |
|
|
|