|
|
View previous topic :: View next topic |
Author |
Message |
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
timer 0 freezing |
Posted: Wed May 05, 2010 5:31 am |
|
|
Hi,
I have a question. What are the conditions required to stop timer 0 from operating. I use 18F4520, this is how I initiate the system:
Code: |
setup_wdt(WDT_ON);
disable_interrupts(GLOBAL);
set_timer0(0);
set_rtcc(0);
setup_timer_0(T0_EXT_L_TO_H | RTCC_8_BIT | T0_DIV_1); parameters
setup_adc_ports(ALL_ANALOG | AN0_TO_AN7 | VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL | ADC_CLOCK_DIV_8);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RTCC);
enable_interrupts(int_rda);
|
My timer is stopping from overflowing when I test inputs (digital input button), it happens randomly. I clock my board with 20MHz, the board is still working, it takes commands over rs485 and executes it what indicates that main loop works but because my timer 0 is frozen it is skipping all functions depending on timer overflow. The timer seems to be stopping when I test for button input and then if it is 0 I turn on AD to test voltage on another AD input.
This is my timer function:
Code: |
#int_RTCC
void timer0_isr(void) {
if (timer_tick >= 255 ) {
timer_tick = 0;
}
timer_tick++;
timer_flag = 1;
}
|
Thank you. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
David Pouzar
Joined: 20 Sep 2005 Posts: 27
|
timer 0 seems frozen |
Posted: Wed May 05, 2010 7:57 am |
|
|
I believe Timer 0 is still running, to verify this use the get_timer0() which will display the count that timer is on. I believe your problem is in your timer_flag = 1, where are you resetting this? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Wed May 05, 2010 8:00 am |
|
|
The only real thing to 'stop' the timer here, would be that the external clock input is stopping, or is not being seen properly.
Much more likely to be a software problem as David says.
Best Wishes |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Sat May 08, 2010 4:47 am |
|
|
thnx, I have moved timer routine to main loop, then I am freezing main loop :(
Code: |
#int_RTCC
void timer0_isr(void) {
timer_tick++;
timer_flag = 1;
}
|
timer_tick is a global, the some like timer_flag, the question is, do I need to do any shadow variables and copy value of variables executed within IRQ?
thnx _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sat May 08, 2010 7:50 am |
|
|
Almost certainly not.
For int1 flags, no.
For int8 values, no.
For int16 or larger values, then probably.
The problem here comes about, because code has to update the two 'halves' at different times. So if (for instance), an interrupt occurs, and changes a value, between the bottom half, and the top half being read, you may get an incorrect value.
However all that will go wrong is the value will be wrong. No hanging.
All you do, is disable_interrupts, copy the value into a local' variable instead, then enable_interrupts.
You either have a code problem - you keep posting a perfectly acceptable working interrupt handler, but are not doing what is necessary to find a problem - _simplify_ your main code. Remove components till the problem disappears, or you have the code down to just the part showing the problem - no more than perhaps 50 line _in total_ as a compilable program. Then post this, and we have a chance of being able to help. The other possibility is that you have a hardware problem - a processor being hung by a brownout for example, nothing to do with the timer.
What you are posting can work. As David said right at the start, you need to be looking at your logic in controlling the flag.
Best Wishes |
|
|
|
|
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
|