20X2 Wake from Sleep 0 Problems

beb101

Senior Member
I am testing the following program:
Code:
pause 1000

'set INT1 (C.1) to trigger Interrupt on rising edge
	hintsetup %00100010

;enable interrupt flags INT1 (C.1)		
	setintflags %00000010,%00000010

	setint %00000010,%00000010

main:
 
 for b1 = 0 to 7
   sertxd("The value of b1 is ",#b1,13,10)
   pause 400
 next b1
 	
 sertxd("Going to Sleep",13,10)
 sleep 0
 
goto main
 
Interrupt:
  if pinC.1 = 1 then interrupt
  sertxd("Wakeup from INT1",13,10)
  hint1flag = 0
  setintflags %00000010,%00000010 're-enable interrupt flags INT1 (C.1)
Return
It works just fine in the simulator. The interrupt works on the breadboard if I Plug a jumper from Pin c.1 to 3.3V for a duration of about 2 sec. The the interrupt does not fire if I quickly plug and unplug the jumper into 3.3V.

The attached push button circuit also does not fire the interrupt, but the circuit functions correctly; the output is low with the switch open and when grounded the output is 3.3V. Upon releasing the switch, the output returns to 0V after a short delay.

So it appears that Pin c.1 must go high for a certain period of time to invoke the interrupt in hardware, but it in the simulator it is instantaneous. I have searched the manuals, but cannot find any mention of this issue.

Baxter

N.B. I have commented out this statement: "if pinC.1 = 1 then interrupt" and the behavior is the same.
 

Attachments

beb101

Senior Member
Understood, papaof2... but I am speaking of the behavior AFTER the 20X2 has gone to sleep (e.g. sleep 0).
.
 

premelec

Senior Member
I thought I saw somewhere that the AXE wakes briefly every 2.3 seconds during sleep - perhaps that's the time it takes to check a pin - have you determined the time delay to the interrupt? Referred to as "c.1 must go high for a certain period of time " - what that time IS may give you a clue...
 

beb101

Senior Member
premelec,

I think you may have found the answer. I haven't measured the time, but it of the order of 2 to 3 sec. Your supposition is perfectly logical.
Even though most every functionality is shutdown with a Sleep 0, the interupt checking must continue; otherwise how could it wake itself.

My circuit still isn't working even with a bigger capacitor, but that's another issue.

Thanks,

Baxter
 

Technical

Technical Support
Staff member
You can only have one interrupt condition, so setint is 'cancelling out' the previous setintflags.
The sleep period is multiples of 2.1 seconds on X2 parts.
 
Last edited:

beb101

Senior Member
I am getting some very strange results when working with with sleep 0. If I run following code which is improperly formed to enable an interrupt:

Code:
pause 1000
	hintsetup %00100010 'rising edge, B.0(hint1)
main:
  	for b1 = 0 to 7
 	   sertxd("The value of b1 is ",#b1,13,10)
 	   pause 400
 	next b1
    sertxd("Going to Sleep",13,10)
    sleep 0
goto main
 
Interrupt:
	sertxd("Wakeup from INT",13,10) 		
Return
The output is as expected and the Picaxe goes to sleep. Now, if I take a jumper and connect it to C.1 and the other end to 3.3v for a period of the order of 3 sec, It wakes up and repeats the main loop (Sub: Interrupt is never invoked). If I repeat this, but connect to ground it also wakes up. If I comment out "hintsetup", it will not wake up. But the point here is that "hintsetup" on the 20X2 refers to B.0 (hint1) and b.1 (hint2). So my question is; how is "hintsetup" influencing C.1 so that it will wake up the Picaxe? This is what the manual says about Sleep 0:

Picaxe Manual Part2, Page 230

On X2 parts ‘sleep 0’ puts the microcontroller into permanent sleep - it does not
wake every 2.1 seconds. The microcontroller is only woken by a hardware
interrupt (e.g. hint pin change) or hard-reset. The chip will not respond to new
program downloads when in permanent sleep.

Note that this says "only woken by a hardware interrupt", but I do not have a proper hardware interrupt enabled. Is this an undocumented feature?

Baxter
 

hippy

Ex-Staff (retired)
if I take a jumper and connect it to C.1 and the other end to 3.3v for a period of the order of 3 sec, It wakes up and repeats the main loop ... If I repeat this, but connect to ground it also wakes up
It doesn't do that on my 20X2 so my gut feeling is some hardware issue that has the PICAXE resetting rather than waking from sleep. Put a SERTXD immediately after the SLEEP 0 which will show if it is waking or resetting.

If it's not that we will have to investigate further.
 

beb101

Senior Member
Hi Hippy,
I added this as suggested,

sertxd("Going to Sleep",13,10)
sleep 0
sertxd("After Sleep 0",13,10) <--- Added

Output after Download to 20X2,

The value of b1 is 0
The value of b1 is 1
The value of b1 is 2
The value of b1 is 3
The value of b1 is 4
The value of b1 is 5
The value of b1 is 6
The value of b1 is 7
Going to Sleep

Plug in jumper C.1 to 3.3V for approximately 2 to 3 sec,

After Sleep 0
The value of b1 is 0
The value of b1 is 1
The value of b1 is 2
The value of b1 is 3
The value of b1 is 4
The value of b1 is 5
The value of b1 is 6
The value of b1 is 7
Going to Sleep

Plug in jumper C.1 to gnd for approximately 2 to 3 sec,

After Sleep 0
The value of b1 is 0
The value of b1 is 1
The value of b1 is 2
The value of b1 is 3
The value of b1 is 4
The value of b1 is 5
The value of b1 is 6
The value of b1 is 7
Going to Sleep

This is the same for either the Picaxe terminal or a PC terminal. I then went to Options --> check Firmware and I get the message: Error- Hardware not found on COM3. However, with the above waking procedure output will still go to the terminal.

I then downloaded this program without any interrupt or sleeping code,
Code:
pause 1000
main:
  	for b1 = 0 to 7
 	   sertxd("The value of b1 is ",#b1,13,10)
 	   pause 400
 	next b1
goto main
and Check firmware now gives, Firmware version C.2. The 20X2 is on a breadboard together with a 74HC14 for inversion of TXd and RXD of a CP2102 USB to serial adapter. The board is being powered by a Sparkfun 3.3V/5V powersupply (set to 3.3V).

Baxter
 

hippy

Ex-Staff (retired)
Very odd. I'm also using 20X2 version C.2 with your code and nothing I do on C.1 causes it to wake, only a high on B.0 as would be expected.
 

beb101

Senior Member
I have a second 20X2 (also C.2 firmware) mounted on an Arduino protoboard using a FTDI USB to serial adapter with a 74HC14 inverter for the serial.
I tried the code in my post #8 for c.1 on it and it will not wake up just as you found, but merely momentarily plugging a jumper (no connection to 3.3V) into B.0 (hint1) does wake it. I suspect that I may have somehow damaged the one on the breadboard. Sorry for not thinking about testing with the second 20X2 to begin with.

Baxter
 

srnet

Senior Member
Does the C.1 pin otherwise work as normal as an input ?

What happens to the supply volts when you connect C.1 to VSS or VDD ?

Does the same thing happen if you connect C.1 pin in the same way but through a resistor such as 10K ?

A faulty chip that causes interrupts when it should not seems very odd, but a chip with an electrical problem with the pin could affect the supply volts and cause the symptoms you describe.
 

beb101

Senior Member
Hi srnet,
Trying your suggestions ...
Code:
'connection: C.1 to 10k
'----------------------
pause 1000
main:

if pinc.1 = 1 then
   sertxd("c.1 is high",cr,lf) '10k to V+ --> OK
elseif pinc.1 =0 then
   sertxd("c.1 is low",cr,lf) '10k to gnd -- OK
else
   sertxd("c.1 has no input",cr,lf) '10k to nothing --> low OK
endif
pause 5000

goto main
================================================
'check voltage
'-------------
Pause 1000

main:
  high C.1  'Meter reading through 10k --> 3.344
  pause 5000
  low C.1   'Meter reading through 10k --> 0.000
  pause 5000
goto main
Meter connected to supply rails = 3.35V

C.1 connected to V+, Meter reading = 3.35V

C.1 connected to gnd, Meter reading = 3.35V

C.1 connected to 10k connected to V+, Meter reading = 3.35V

C.1 connected to 10k connected to gnd, Meter reading = 3.35V

So, the port seems to be OK.

Baxter
 
Top