Why does setint change times?

Colinpc

New Member
This piece of code turns pin 2 on and off for 20 secs each when setint is commented out.
When coded as below, the output is on for 20secs and off for 3secs.

I have run it on 08M and 08M2 with same result.

I would appreciate and help on why.

Fred


Code:
symbol timeon = 20			'time on for fan in seconds
symbol timeoff = 20			'time off for fan in seconds

symbol fantime = w3			'counter for fan
fantime = timeon				'initialise as timeon

symbol fanon = b0				'fan on flag
symbol fanflag = b1			'fan flag

symbol fanctr = w4			'fan counter
symbol fan = 2				'output pin for fan

'*****************************************************
main:

setint %00001000,%00001000		'activate interrupt when pin3 only goes high

gosub fancontrol				'

pause 1000					'this is the 1 sec time delay 

goto main

'***********************************************

Fancontrol:		'count seconds for turning fan on and off

inc fanctr

if fanctr < fantime and fanon = 0 and fanflag = 0 then			
	goto fanrun
else if fanctr < fantime and fanon = 0 and fanflag = 1 then
	return	
else if fanctr > fantime and fanon = 1 then
	goto fanoff
else if fanctr > fantime and  fanflag  = 1 then
	fanflag = 0
	goto fanrun
endif

return

fanrun:
	high fan
	fanon = 1
	fantime = timeon
	fanctr = 1
return	
	
fanoff:	
	low fan
	fanon = 0
	fantime = timeoff
	fanctr = 1
	fanflag = 1
return

'**************************************
interrupt:				'button pushed 
pause 100				'debounce switch

return
 

Technical

Technical Support
Staff member
The interrupt will cancel any pause that is currently in progress.
Do you have a 10k resistor pulling input 3 down? Is the circuit correctly decoupled, how is the fan driven...FET etc?
 

Colinpc

New Member
This is the most basic part of the program and is tested as written. There are no interrupt inputs connected and the input pin is tied to ground via 10k. The output is fed to a logic level gate FET and drives a LED light (for testing) from 12 volt supply to ground. (Picaxe is reg to 5v). Programming circuit is wired and PC connected although PC connection makes no difference.

The regulated 5v has a 10uF tantalum on output that is ~15mm from pin 1

In testing, no interrupt is activated by me.

Regards, Fred
 

hippy

Ex-Staff (retired)
Your code in post #1 runs okay for me on an 08M2 ( approx 20 seconds on, 20 seconds off ) either with SETINT included or not.

You may have a circuit wiring error perhaps or the PICAXE is resetting itself because of a power supply collapse or electrical interference.
 

Colinpc

New Member
This is the minimalised code that gives the problem. In the real code, the interrupt service routine does as it was programed to do. The interrupt is activated by a button to 5v.
 

Colinpc

New Member
Thanks Hippy. I will have to try different power supplies etc. The current source is a a bank of car batteries so unlikely to be collapsing. I will try in a different location to rule out interference.
 

hippy

Ex-Staff (retired)
The current source is a a bank of car batteries so unlikely to be collapsing.
Take care when using very high current sources. It may also be that any electrical interference is caused by switching such high current sources so a different location won't improve things.

It's probably best to post full details of your project, a full circuit diagram, and test if it works using a 3 x AA battery supply, the car batteries disconnected.
 

Colinpc

New Member
I have now tried the program with a plugpack and there is no problem.

Hippy, you must have been right re the interference. The battery bank is also used by my 240v inverter that supplies my caravan. I have used plugpacks in the inverter without any problems previously. Just thought I could bypass the plugpack by connecting straight into the battery bank.

Thanks again, Fred
 
Top