Interrupt on 18M2

eggie

Member
Please can someone tell me if it is possible to pull and 18M2 out of sleep with an interrupt. Looking through the manual I can only find reference to this with the X2.

I need to pull an 18M2 out of sleep when an 08M pulls a pin high so that it can subsequently send a serial signal with an instruction.

Is this possible or do I need to change my chip?

Many thanks

Eggie
 

jim1248

Member
Well I tried this code on the simulator and it worked
Code:
setint %000000001,%000000001,c ;interrupt on c.0 low - high


do
	sleep 10
	
loop

interrupt:
	pulsout c.1,1000
	setint %000000001,%000000001
	return
Jimmy
 

eggie

Member
Jimmy

Thanks for your response. I will build a circuit and try it out at the weekend to see if it works in real life. I was just wondering if anyone had actually done this in a live situation.

Eggie
 

hippy

Ex-Staff (retired)
Sorry for being late to the game, but no, a change in pin state won't cause an immediate interrupt and terminate the sleep ....

Code:
#Picaxe 18M2
#No_Data
#Terminal 4800

Gosub Interrupt_Init

Do
  Toggle B.0
  Sleep 1
Loop

Interrupt:
  SerTxd( "IRQ " )
Interrupt_Init:
  If pinC.0 = 0 Then
    SetInt %000000001,%000000001, C
  Else
    SetInt %000000000,%000000001, C
  End If
  Return
Put a LED on B.0 and it will toggle every 2.5 seconds or so. Put an active high button to C.0 and the toggling is still 2.5 seconds no matter how often the button is pushed. If you are holding it just as it comes out of sleep then you will get an interrupt than. Same with 'SLEEP 10' but a bit more boring to watch :)
 

jim1248

Member
Depending on exactly what you program is doing you may be able to use hserin, but more info would be needed.

Another solution would be to use an X2 part and the serial interrupt.

Jimmy
 

hippy

Ex-Staff (retired)
Perhaps the question are; why do you need to sleep at all and what response time do you want ?
 

eggie

Member
This is the ongoing saga of me making an MP3 alarm clock. In between blowing up MP3 modules (see another thread) I have been looking at the control system. The clock is to go next to the bedside and so the brief from my wife (apart from it actually working) is that it needs to be reasonable to look at. As amateurish buttons on a big box would go down like a brick balloon, I have gone for a remote control system. This way I only need to provide a digital clock face, a light button and an infra red detector.

I have bitbanged the control signal (using your code thanks Hippy) from a tiny remote from the £ shop and have the programme written that will read and interpret the buttons to adjust the clock and control the MP3 player. However, I have found that the process of detecting and interpreting the pulsin including waiting time when there is no pulse is quite long and trying to do anything else while detecting a pulsing corrupts the results. It is asking a bit much therefore from the one chip to do this along with everything else. I am therefore proposing to separate the remote control system from the main clock/MP3 controls by having an 08M constantly monitoring for the signal and also listening for a signal from the clock module (a disassembled alarm clock) that pulls a voltage low when the alarm goes off and can be read with ADC.

When the 08M detects an input it sends a pin high as an interrupt to the 18M2 and then sends a serial signal a short time later telling the 18M2 what to do next. It follows then that if the MP3 in not in playback mode, the 18M2 is not needed and can be put into sleep to save battery power…. and this is where I have the problem. From the sound of it I need to change the chip to an X2 or work around the 2.3 second delay - which sounds a bit more challenging but probably more interesting to programme. 08M sends pin high as a handshake, 18M2 responds when raised from sleep sending another pin high on the 08M, 08M then sends serial instruction. That way I can avoid the need for a 2.5 second delay on the handshake (such a delay would not be a problem when pulling it out of sleep but would be far too long for clock adjustment).

I suppose that an alternative may be to pull a connection high but sink it low with the 08M until a handshake is needed and then allow it to revert to high for a short period. The 18M2 could then sink the same connection low as an acceptance handshake. I can only think that sinking a pin low will take a lot of power from the battery if it is run continuously. What do you think?? Any suggestions on the highest resistor that would be acceptable to pull the connection high whilst giving a reasonable response time and not consuming too much power would be appreciated. As you will appreciate, with the unit not being used for 23 hours and 45 minutes each day, standby power consumption is a key factor in the design.

Third option would be to vary the output of the 08M depending on whether the 18M2 is in sleep mode or not (it holds a pin high when the it is active)........ the choices are endless - or so it seems.

Jimmy mentions the hserin pin – would this pull the chip out of sleep? I cannot see any mention of this in the hserin instructions in the manual.

Thanks for your help.

Eggie
 

hippy

Ex-Staff (retired)
One alternative to SLEEP is NAP. That will cut down the wake-up time and may be a good compromise.

You could also handle IR differently so the 08M is generally napping and only enters the bit bang receive when the first IR is received. As long as the IR sends commands multiple times you might miss the first but should get the second and it's always a good idea to check you have two consecutive which are the same before doing anything.

The 08M could then power-up the 18M2 and keep it powered until the 18M2 tells it to kill the power. Instant zero-current consumption though the caveat is the 18M2 circuit can only use 25mA in total though it can be powered by multiple 08M pins.

I don't believe high-speed serial will cause a wake from SLEEP but I may be wrong.

For a complicated multi-PICAXE setup it would be necessary to see some block diagram of what connects to what, what receives and control what, and what data passes between PICAXE - A picture is worth a thousand words.

There's also the other lesson that's learned over time - simpler is usually better or at least easier. I'm sure there's some way to do it all with a single PICAXE but that needs a full and detailed operational specification to say how, plus the effort in analysing it.
 

BCJKiwi

Senior Member
As part of a bigger project running on a 28X2 @ 32MHz, have recently constructed a configuration routine that uses 2 buttons and a single 7 seg display to set a range of variables. This has replaced an IR system.

There is a main menu and five sub menus, with settings within the individual menus accepting either 1, 2 or 4 digits.
Within each submenu there are various steps, a total of almost 30 settings.

There is some repeated code due to the nature of the parameters being set plus a number of subroutines - a total of around 500 lines but for a clock setting should be much less.

Range and error checking included. One button is used to step through the 0 to 9 range and will cycle around if the button is held down. The other button is to confirm the choice. Value selected and menu options are indicated in the 7 Seg.

Your system should be much simpler as there are far fewer options and more display digits available.

Would this system be of use?
 
Last edited:

eggie

Member
Thanks to both of you for your advice. Sorry for not responding straight away but it was our office Christmas party last night......hic!

I will look at the nap option and read up about it. As a novice there are so many different instructions to take in all at once. I have read through the complete manual 2 twice since starting but there is always some command I have not picked up as relevant to what I do. (any knowledge I have on either electronics or computing is self taught)

I have a circuit diagram on TinyCad but this has been evolving as I go along. I can bring it up to date at the weekend and post it then.

It will be my wife that will be controlling the alarm and so it needs to be clear for her to operate in her semi-zombified state first thing in the morning and a sequence of buttons might be a bit much, but the concept is very interesting for future projects. One of the IR changers I have bought is a key ring type and can be fixed to the bedpost for easy access to volume controls etc. I have also put a lot of work into the IR decoding and it would be disappointing to give up on it now when I am so close.

I will update this post at the weekend with what I have done to date.
 

eggie

Member
Attached is my circuit diagram for the alarm clock and the code I was proposing to use for the 08M. The code for the 18M2 is not in a state that can be posted yet. (ps - I realise that I am missing a diode off the amplifier power relay.)

I really like the concept of the 08M powering the 18m2 - that will solve a lot of my problems. Need to rearrange the circuit diagram. I presume pin 0 can be used for powering but will this need to be separated from the programming socket when programming the 08M? - I was thinking about doubling up with pin 1 to make sure that I had enough power.

I think I will need to keep the 08M powered up all the time as I need it to constantly monitor the ADC for being pulled down by the alarm.
 

Attachments

techElder

Well-known member
I'm not sure why you are using battery power only and not using the mains. At least with mains power on, you needn't worry about anything being asleep.
 

hippy

Ex-Staff (retired)
Looks okay but I still don't really understand why you need a separate 08M for the IR. I'm sure that could be brought into the MP3 controlling PICAXE.

On the amps; are they line-level driving or direct to speaker ? They look like the former so if you've got external wiring I'd be tempted to combine that all as multi-core back to some 'hub' ( so just one cable to the table-top controller ) and provide power from mains up from the hub. You could go further and put the MP3 player and/or amps in the hub.

I'm also not sure what the input buttons actually do. I imagine this as much simpler; the clock alarm signal which starts the MP3 playing, and IR command which shuts that off fully or snoozes.

I think I'm missing the big picture. Do you have an 'operational specification', a side of A4 which explains to your other half how to use the thing when you've gone away on a business trip ?
 

eggie

Member
I am trying to make the alarm self contained to avoid wires across the bedside table - hence the batteries, but logic says I will probably have to give up and go to mains if it gets too difficult.

I do not have anything in the way of a written operational specification at present - it is all in my head. However, the main question I had about bringing an 18m2 out of sleep has been answered and your suggestion of using the power from the 08m to drive the 18m2 is looking like the best option. Rather than going too far down the line with posting information I will carry on experimenting with the suggestions made and then post something more complete. You never know - if it works then I can put it in the user projects if people are interested!!

In terms of using the 08M to monitor the IR, the IR receiver is an area I want to experiment more with for my own education and interest and intend to do so once this project is complete. However, with bitbanging data the Picaxe skips pulses if asked to do anything else. In particular the current code of

IRLoop1:
pulsin Ir_input,PulseType,w0 ; read IR pulse
if w0<Start_pulsin then goto IRLoop1 ;loop back of start pulse not detected

already drops the second pulse whist it is checking the first. It is not important when using changer setting 119 but some of the other changer settings send the first of the data bits immediately after the start pulse, so the code is corrupted if the second pulse is missed..... Anyway, that is for another day!!

Thanks for your help so far.

eggie
 

mike_biddell

New Member
To be absolutely candid, the absence of any sort of wake on interrupt for the 18M2, absolutely tarnishes the reputation of an otherwise magnificent device. There is no point in using NAP or SLEEP. What's the point of a sleeping brick, with no functionality. Both of those commands are pointless on the 18M2. It's very disappointing. It cant think of an application where either command would be useful i.e. where input monitoring is not required for long durations.
 

Technical

Technical Support
Staff member
Sleep and nap are very useful in battery applications, putting the device into low power mode to save energy. You can easily wake up at regular intervals to check a switch state and then either do something or go back to sleep. A large number of commercial products do this, so it is actually widely considered a useful feature!
 

mike_biddell

New Member
Sleep and nap are very useful in battery applications, putting the device into low power mode to save energy. You can easily wake up at regular intervals to check a switch state and then either do something or go back to sleep. A large number of commercial products do this, so it is actually widely considered a useful feature!
Technical, not half as useful as a device which does both. A huge number of devices are required to take action if an input changes state. If SLEEP is used the 18M2 is oblivious to the change, especially if it's an input which asserts momentarily and then de-asserts (to the 18M2 in sleep mode, the event is not seen). Therefore SLEEP rules out a huge number of potential applications. I'm not quite sure why this was not implemented on the 18M2.
 

papaof2

Senior Member
Technical, not half as useful as a device which does both. A huge number of devices are required to take action if an input changes state. If SLEEP is used the 18M2 is oblivious to the change, especially if it's an input which asserts momentarily and then de-asserts (to the 18M2 in sleep mode, the event is not seen). Therefore SLEEP rules out a huge number of potential applications. I'm not quite sure why this was not implemented on the 18M2.
It's based on the silicon of the underlying PIC chip - not something Rev-Ed has total control over. Remember that the PICAXE line was created for educational use, not commercial production. If you need to interrupt sleep or nap, there are other chips.

I'd like an 08XX that had a 1024 byte buffer for hserin to use as a stand-alone GPS to I2C interface, but that silicon isn't available - so I use a different chip.

John
 

hippy

Ex-Staff (retired)
If SLEEP is used the 18M2 is oblivious to the change, especially if it's an input which asserts momentarily and then de-asserts (to the 18M2 in sleep mode, the event is not seen).
It is possible to work round that using the SRLATCH command. It won't wake the PICAXE from SLEEP but it will allow any momentary event to be flagged and the PICAXE can then act upon it.

Firstly the 08M2 example, going-high button push to pin 1 (SRI) and a LED on pin 2 (SRQ). It prints "Pressed Button" even if the button was pressed during the 20 or so seconds of sleeping ...

Code:
#Picaxe 08m2
#No_Data
#Terminal 4800

' 08M2 Pin 1 = SRI - From button 
'      Pin 2 = SRQ - To LED

SrLatch %10001000, %10000000

Output 2
Do
  Sleep 10
  If pin2 = 1 Then
    SrReset
    SerTxd("Pressed Button",CR,LF)
  End If
Loop
Now an 18M2 example, going-high button push to pin B.0 (SRI) and a LED on pin C.3 (SRQ). It's a little more complicated as Serial Out is also C.3 so the SRLATCH needs to be disabled to send the SERTXD message and then the SRLATCH needs to be re-enabled. If not wanting SERTXD then it can be just like the 08M2 version ...

Code:
#Picaxe 18M2
#No_Data
#Terminal 4800

' 18M2 Pin B.0 = SRI - From button 
'      Pin C.3 = SRQ - To LED

SrLatch %10001000, %10000000

Do
  Sleep 10
  If pinC.3 = 1 Then
    SrLatch Off
    SerTxd("Pressed Button",CR,LF)
    SrLatch %10001000, %10000000
  End If
Loop
In both cases the PICAXE reads the pin the SRQ output goes to; not recommended but does seem to work for me ( and, yes, pinC.3 / Serial Out can be read as if it were an input on the 18M2 ! ). In an ideal world you'd take the SRI output pin and feed it back into another input pin, check the state of that.
 

mike_biddell

New Member
Hippy

That is really useful ....... quite a good work around. Thanks.
Is the lack of wake on interrupt for 18M2 a silicon problem? Or a software problem. If the former, it will obviously never happen. If the latter, then we live in hope.

Cheers
Mike
 

mike_biddell

New Member
I note that the 20X2 has hardware interrupt on two pins. I hope this device remains in production and is not replaced by the 20M2 part (which presumably has no interrupts).
 

westaust55

Moderator
I note that the 20X2 has hardware interrupt on two pins. I hope this device remains in production and is not replaced by the 20M2 part (which presumably has no interrupts).
@mike,

Some brief history of the PICAXE range for your information.

In &#8220;recent&#8221; history say over the past 5 years, there are nominally two PICAXE chip series:
1. The M series, and
2. The X series.

The &#8220;M&#8221; series has recently progressed form the &#8220;M&#8221; to the &#8220;M2&#8221; range.
The &#8220;X&#8221; series has progressed through the &#8220;X&#8221;, &#8220;X1&#8221; and now &#8220;X2&#8221; range.

Each compliments the other with the X2 parts have additional commands, greater memory, etc.

As such you need have no fear that an X2 part will be superseded by an M2 part.

X1 and X2 parts have interrupt capability via the SETINT, SETINTFLAG.
The X2 parts also have the HINTSETUP command.

M2 parts only use the SETINT command with polled interrupts.

The hardware interrupt &#8220;hintx[/]&#8221; pins for the X2 parts only and are setup using the HINTSETUP command then can be monitored via the SETINTFLAG command and associated flags.
 

mike_biddell

New Member
westaust

Thank u. My mind is at rest. It's wake from sleep that has been troubling me. On the M2 parts, there is no HW interrupt for a wake up call from sleep. If u want to use sleep to conserve battery power, this limits M2 parts to synchronous/sampling type applications where inputs do not require immediate action. So any alarm functions are out of the window. Also any input which asserts and de-asserts whilst the M2 part is in sleep is not seen. Hippy has suggest an interesting work around for M2 parts, but using X2 is probably the simplest solution. I dont know whether the lack of wake on interrupt is part of the M2 silicon architecture or it's software. On an entirely different topic... I think I have evidence that the 18M2 has no input protection diode on input C.5 (discovered during my experiments to wake 18M2 from sleep).

Cheers

Mike
 

hippy

Ex-Staff (retired)
On an entirely different topic... I think I have evidence that the 18M2 has no input protection diode on input C.5
That is correct. Leg 4 on the M2 parts is the input which would be MCLR (Reset) on PICmicro silicon but can be used as a general purpose input as it is with the M2's.

Not having an input protection / clamping diode on MCLR should not be a problem unless a voltage greater than +V is input to the chip through that pin. In that case an external clamping diode should be added between the input and +V.
 
Top