greencardigan
Senior Member
Hi, I'm having trouble with timer interrupts again with my 28x2.
The interrupt code is below. Is there anything wrong with it? I have it set for 100 interrupts per second to do some slow PWM while the rest of my code keeps going.
After running OK for approximately 5 minutes, the second_counter variable stops increasing, but my background code keeps running. What would be stopping my interrupts from occurring?
My code has background hardware serial in, hardware serial out, hardware i2c in and out.
I have already split up all the hserout so they send one byte at a time. Could the hi2c transfers be causing the interrupts to be delayed or missed?
Full code also attached if required.
The interrupt code is below. Is there anything wrong with it? I have it set for 100 interrupts per second to do some slow PWM while the rest of my code keeps going.
After running OK for approximately 5 minutes, the second_counter variable stops increasing, but my background code keeps running. What would be stopping my interrupts from occurring?
My code has background hardware serial in, hardware serial out, hardware i2c in and out.
I have already split up all the hserout so they send one byte at a time. Could the hi2c transfers be causing the interrupts to be delayed or missed?
Code:
interrupt:
if started = 1 then
inc hundredth_counter
if hundredth_counter > OUT then 'set output low for remainder of second when reached out/PID value
low c.5
endif
if hundredth_counter >= EVENTS_PER_SEC then
hundredth_counter = 0 'maybe make hundredth_counter = hundredth_counter - EVENTS_PER_SEC
OUT = PID 'load new PID value into OUT at start of new second
if OUT <> 0 then 'set output high at start of new second
high c.5
endif
inc second_counter
endif
elseif button1 = 1 then
do : loop until button1 = 0
started = 1
endif
gosub timer_setup
return
''''''''''''''''''''''''''''''''''''''
timer_setup:
timer = 0xffff ' generate interrupt at next overflow
toflag = 0 ' clear timer overflow flag
setintflags %10000000,%10000000 ' interrupt on timer overflow
return
Attachments
-
31.5 KB Views: 15
Last edited: