|
|
View previous topic :: View next topic |
Author |
Message |
karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
problem with timer 0 of 12F675 |
Posted: Thu Feb 21, 2008 12:35 am |
|
|
Hello,
I try to set high the pin GP0 after 5 sec, we use timer 0 of 12f675 with internal oscillator.
This is my code..
Code: | #include <12F675.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO, CPD, PROTECT, NOMCLR, PUT, BROWNOUT
#byte OSCCAL=0x90
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
//========================
#use fast_io(a)
#byte ADCON0 = 0x1F
#byte ANSEL = 0x9F
#byte CMCON = 0x19
#rom 0x3ff = {0x3470} // input the calibration code
int rtcc=0,seconds=0;
#int_RTCC
RTCC_isr()
{
rtcc++;
if (rtcc == 250)
{
seconds++;
rtcc=0;
}
if (seconds==5)
{
output_HIGH(GP0);
seconds=0;
}
}
void main()
{
ADCON0 = 0; // ADC off
ANSEL = 0; // GPIO pins 0,1,2 and 4 set to all digital
CMCON = 7; // Comparators off
set_timer0(0);
setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_16);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
set_tris_a(0b111110); //GP0 output
output_low(GP0);
while(1) {
}
}
|
I turn on the power supply but PIN GP0 is low only. I think timer 0 is not work. Please check my code and give solution for problem. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 12:28 pm |
|
|
It works OK for me. I installed vs. 3.185 of the compiler (your version)
and programmed a 12F675 with the code. MPLAB displayed a message
saying the calibration memory was already programmed, so it didn't
put in your new value (0x3470). I read the ROM at address 0x3FF,
and my PIC has 0x3480 at that location. However, if you really have
0x3470, it should still work.
Anyway, I put a scope probe on the GP0 pin and used a stopwatch to
find the delay before GP0 goes high. It was 4.37 seconds.
Here are some possible reasons why it doesn't work for you:
1. Your hardware may not be correct.
2. You may not really have a correct value programmed at ROM address
0x3FF. You need to use your programmer to read the ROM. Look at
that address. Do you really have 0x3470 there ? |
|
|
karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
|
Posted: Thu Feb 21, 2008 11:11 pm |
|
|
PCM programmer wrote: | It works OK for me. I installed vs. 3.185 of the compiler (your version)
and programmed a 12F675 with the code. MPLAB displayed a message
saying the calibration memory was already programmed, so it didn't
put in your new value (0x3470). I read the ROM at address 0x3FF,
and my PIC has 0x3480 at that location. However, if you really have
0x3470, it should still work.
Anyway, I put a scope probe on the GP0 pin and used a stopwatch to
find the delay before GP0 goes high. It was 4.37 seconds.
Here are some possible reasons why it doesn't work for you:
1. Your hardware may not be correct.
2. You may not really have a correct value programmed at ROM address
0x3FF. You need to use your programmer to read the ROM. Look at
that address. Do you really have 0x3470 there ? |
thank you for help..how to get perfect 5 seconds delay from 12f675 internal oscillator |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 11:29 pm |
|
|
Calculate the rate of the timer interrupt.
The oscillator frequency is nominally 4.0 MHz.
Divide that by 4 to get the instruction clock: 1.0 MHz
You are using RTCC_DIV_16, so divide it by 16 to get: 62.5 KHz
This is the clock for Timer 0.
The timer rolls over and interrupts after 256 counts, so
divide 62.5 KHz by 256 to get the interrupt rate: 244.14062 Hz
This means the timer interrupt occurs approximately 244 times
per second.
Currently, you check if it counts to 250 before you increment
the 'seconds' counter. Change it to the correct count. |
|
|
|
|
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
|