View previous topic :: View next topic |
Author |
Message |
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
Timer0 interrupt problem |
Posted: Mon May 08, 2006 4:03 am |
|
|
Hi,
I'm writing a code with timer0 interrupt and it works very very good, now i need to add an HW compartor interrupt in my PIC16F628A code but when i write lines to setup Comparator timer0 interrupt stops running while other function run. It's stange .... if i remove comparator setup line it begins running again. what could be my problem??
I copy setup lines directly from ccs help or PIC16F628A.h file and CCS compiler build my file without problems!!
thanks |
|
|
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
|
Posted: Mon May 08, 2006 6:19 am |
|
|
hi dude, i've got the same problem, but not using comparator setup.. i just call an extern rountine and the timer 0 stops counting...
i solved my problem setting up timer 0 again at the end of my external routine.. try it... but i didnt get answer about it until now.
regards. _________________ Andre |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 08, 2006 6:27 am |
|
|
For problems like this post a short program demonstrating your problem.
Always mention the compiler version you are using. |
|
|
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Mon May 08, 2006 10:09 am |
|
|
Code: | void main()
{
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(A3_VR_A2_VR);
setup_vref(VREF_HIGH|6);
setup_oscillator(OSC_4MHZ);
set_tris_a(0b00010101);
int_count=INTS_PER_200MS;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_32);
enable_interrupts(INT_RTCC);
//abilita la porta di input AN0
//setup_adc_ports(RA0_ANALOG);
// setup_comparator(A3_VR_A2_VR);
// setup_vref(VREF_HIGH|6);
// enable_interrupts(INT_COMP);
enable_interrupts(GLOBAL);
while (true)
{
if (C1OUT == 1) output_high(PIN_A0);
else output_low(PIN_A0);
// isPressed();
switch (numPressed)
{
// case 0 : cicla(); break;
case 1 : analogico(0); break;
case 2 : analogico(1); break;
}
}
}
|
There is a Led on pin A2 unfortunately. i see it flashing quickly instead flashing every second with timer0.
but now timer seems working. I wrote setup comparator before setup timer0 as 'andreluizeng' told me. |
|
|
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
|
Posted: Mon May 08, 2006 10:32 am |
|
|
good... my project is working like this way either..
but the question is...
why doesnt work on another way ?
regards... _________________ Andre |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue May 09, 2006 12:25 pm |
|
|
andreluizeng wrote: | good... my project is working like this way either..
but the question is...
why doesnt work on another way ? | It is possible the compiler initializes the comperators incorrectly. For us to check this, which compiler version are you using? |
|
|
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Tue May 09, 2006 1:32 pm |
|
|
version 3.242
comparators work correctly. |
|
|
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
|
Posted: Tue May 09, 2006 3:31 pm |
|
|
hi..
my compiler�s version is: 3.221.
regards. _________________ Andre |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue May 09, 2006 3:45 pm |
|
|
Your program is not complete, the #fuses line and #include for your chip are missing. More important, the interrupt functions are missing so I can't check those.
Is it possible you didn't create the comperator interrupt handler yet? A glitch on the comperator inputs might trigger the comperator interrupt and without the interrupt handler function present the interrupt will never clear resulting in the noticed behaviour of the processor stalling.
I don't have v3.242 anymore as I didn't consider that version stable, so I checked your program with v3.241. The code looks allright at first glance except for one undocumented feature: Code: | setup_comparator(A3_VR_A2_VR);
setup_vref(VREF_HIGH|6); | Setup_comparator will clear the comperator interrupt flag but when you change the reference voltage it is possible the comperator is triggered immediately again. Try reversing these two lines, or even better, call clear_interrupt(INT_COMP) just before enabling the global interrupt.
The same error is in the provided example file ex_comp.c
Tip from the manual regarding setup_counters(): Quote: | This function is provided for compatibility with older versions. setup_timer_0 and setup_WDT are the recommended replacements when possible. |
|
|
|
|