|
|
View previous topic :: View next topic |
Author |
Message |
Fabricio
Joined: 08 Apr 2005 Posts: 8
|
measurement of period |
Posted: Fri Apr 15, 2005 7:33 am |
|
|
Hi,
I want to measure the period of a sign using the "interruption on change" of the PIC12F675. I want to use the pin GP3. Yet I do not have this pic, for what I cannot prove the code.
I have tried to simulate it with Proteus but without success.
Someone can say to me if this code works.
#include <12F675.h>
#fuses intrc_io,nomclr,wdt,noprotect,nocpd,nobrownout,put
#use delay(clock=4000000,RESTART_WDT)
#users232baud=9600,parity=N,xmit=PIN_A1,rcv=PIN_A0,RESTART_WDT)
#byte STATUS=0x03
#byte WPU=0x95
#byte OSCCAL=0x90
long rise;
#int_EXT
EXT_isr()
{
rise=get_timer1();
set_timer1(0);
}
void main() {
restart_wdt();
set_tris_a(0b001101); //gp3 In
port_a_pullups(TRUE);
setup_comparator(NC_NC_NC_NC);
//Load Factory Calibration Value Into OSCCAL
#asm
call 0x3FF
bsf STATUS,5
movwf OSCCAL
#endasm
//-------------------------------------------
setup_timer_1(T1_INTERNAL);
set_timer1(0);
ext_int_edge(L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(global);
while(TRUE)
{
delay_ms(500);
printf("\r\Period=%lu us",rise);
restart_wdt();
}
}
Thanks
greetings |
|
|
Ttelmah Guest
|
|
Posted: Fri Apr 15, 2005 10:06 am |
|
|
Some small comments:
You do not need to load the OSCCAL value. The compiler automatically does this for you, if INTRC is selected.
With an interrupt using a programmable 'edge', there is a danger that the interrupt will trigger as soon as you enable it. If you change the interrupt 'edge', then you should clear the interrupt before enabling the global flag.
You seem to be confusing 'interrupt on change', with the external interrupt. Interrupt on change, does not have an 'edge', it occurs whenever any pin on the affected part of the port _changes_, from the value when it was last read. Your interrupt handler, needs to be 'INT_RB', not INT_EXT, and it is INT_RB that needs to be enabled (without the edge being set). You should read the port, and clear the interrupt flag, before setting the interrupt, and you _must_ read the port inside the handler. INT_EXT, will only work on pin GP2.
As written, no the code will not work.
Best Wishes |
|
|
Fabricio
Joined: 08 Apr 2005 Posts: 8
|
|
Posted: Fri Apr 15, 2005 10:45 am |
|
|
Hi Ttelmah,
thank you very much for your help. Your explanation is very good
I will do some changes and will put the final code
Greetings |
|
|
|
|
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
|