hi2c and timer conflict

dj_trippn

New Member
Hi all,

I have a project where I have been using hi2c to send data to another picaxe and it has been working fine. I am using a 28X1.

I have an input interupt that is counting revolutions of a motor. I ran into a problem where I needed a pause of about 4 seconds, which was jumping out of the pause. After reading the forum I discovered the issue with jumping out of pause when an interrupt occurs. So I created a custom p_ause routine using the timer as follows:
Code:
p_ause:
	pause_time = 65535 - pause_time
	pause_time = pause_time +1
	timer=pause_time
	settimer 63973
	
time_loop:
	if toflag=0 then time_loop
	return
Now I have a problem where my i2c stops working after using this p_ause routine. From the forum I discovered the issue with "settimer and hpwm" and "settimer and i2c" in pre V4 firmware. Please note that my original code has always had the command
Code:
settimer 65520 	' set timer for creating random number
in my initial setup because I use it create a random number.

I checked my firmware and I had V3. I swapped for a V5 firmware. And the problem still existed. After some experiementing I discovered if I set the timer back to 65520 after I have used the p_ause routine then my i2c starts working again!

Is there a reason that I need to set the timer back to 65520 for i2c to work correctly? I havnt tried going back to firmware V3 but I suspect it would work fine when setting the back back to this value.

Thanks
 

Technical

Technical Support
Staff member
Please have a look at the commands in Appendix 2 of the manual part 2 "Possible Conflicting Commands". This shows the commands that use internal hardware interrupts.

Basically when the timer command is active the processor core must spend a fair amount of time processing the 'time' interrupts which happen quite frequenctly. If an i2c interrupt occurs at the same time as timer is being processed then i2c may be missed (and vice versa) and that could lock up the i2c bus until either timer or i2c are reset.

Unfortunately there is no simple solution to this problem - a single core processor like the microcontrollers can only do one thing at a time - and running multiple 'internal hardware' interrupt based features simulatenously (background i2c/serial, timer, pwm) will, at some point, always cause some kind of processing conflict.
 

dj_trippn

New Member
Thanks for the reply Techincal. Thats a reasonable explanation. Just to help me understand could you please give a bit more detail what would cause this and therefore be an appropriate fix.

Is your comment still relevant if I am not using the timer interrupt flags? I'm only using the 'setint' input interrupt.

Why would implementing the settimer 65520 command alloy i2c to work again, is this resetting the timer? Because the timer is always running in the background (overflowing back to zero and continuing, or does it stop once it overflows?) and the i2c still works. It was only when I intiated the p_ause routine which changes the timer, that the i2c stopped working.

Thanks again.
 

Technical

Technical Support
Staff member
Th eflags don't really matter, its a question of whether timer is active or not.

Re issuing a settimer command does completely reset the timer module and interrupt system (it does carry on working in the background). Without seeing the whole program it is harder to comment further.
 
Top