14M2 confusion

FIREMANJIM

New Member
I am reading the manual on the 14M2 Chip and it says a interrupt can be set on inputs 1,2,and 3. Does that mean c1, b1 or what??? Really confused because I am new at this. Thanks in advance for any help
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

Please accept our apologies for any confusion and if you can tell us where the confusing information is we can see what we can do about improving that.

On the 14M2 the pins which can be used to trigger interrupts using the SETINT command are pins C.0, C.1 and C.2
 

FIREMANJIM

New Member
Thank you Hippy for taking the time to answer. I am the owner of JTSWildlifeCameras Wildlife Cameras and I designed my control boards and they run off the Picaxe 14M2 & 20M2 chips. I am definitely still learning the programming stuff. I have the basics but still have a lot to learn. The internal timer that you can enable and disable with the disabletime and enabletime commands can it be cleared and read to use in a program? Say I want the code to do a act every 10 minutes, can that timer be used for that? Cleared by simple Timer = 0????
 

hippy

Technical Support
Staff member
On the M2 devices the 'time' variable increments approximately once a second. A timeout after 10 minutes would therefore be "If time > 600 Then...".

You can reset the 'time' variable to zero by using "time=0", but there is a caveat; the next time it increments may be at any time up to a second later, but in many applications that would not be problematic.

If you can explain what you ultimately want to achieve, members will be delighted to explain how they would go about doing that, will be able to suggest the best approach to use in your particular case, what the pros and cons are with the options available.
 

FIREMANJIM

New Member
OK guys..Here is what I need. This board controls a remote slave flash for a wildlife trail camera. It has a Photo Sensor that senses when the flash fires. When it senses the flash has fired it turns on a mosfet which powers the slave board. It also has a CDS sensor which senses night and daytime outside. When it is daytime outside it the board sleeps for 5 minutes, wakes up checks the CDS sensor and if it is still daytime it goes back to sleep for 5 more minutes. If it is night time it turns on the slave flash power for 25 seconds to charge it fully and then turns it off. It then monitors the PT sensor for the flash to fire. If the flash does not fire for 10 minutes it turns on the slave power for 10 seconds then turns it back off to save power.In the daytime mode I can put a nap 3 at the end to save battery power. But in night mode I can not put in the nap 3 because it misses the flash firing so it has to run at a straight 4mhz. I am thinking I need to use a SETINT for the PT sensor instead of what I am doing now. I think a SETINT will monitor the PTInput pin more allowing me to use a nap 3 . Here is the program I am testing now. What do you guys think? Any help appreciated....

Code:
symbol CDSPwr = b.0
symbol CDSRead = b.1
symbol SlavePwr = b.2
symbol PTPwr = b.3
symbol PTInput = pinb.4
symbol LED = b.5
symbol DIP5 = pinc.0
symbol DIP4 = pinc.1
symbol DIP3 = pinc.2
symbol DIP2 = pinc.3
symbol DIP1 = pinc.4

symbol DayStatus = bit0
symbol SlaveOn = bit1
symbol PTPwrOn = bit2

symbol DayLevel = b4
symbol DaySetting = b5
symbol NightSetting = b6
symbol Counter = b7
symbol SlaveOnTimer = w3
symbol SlaveOnTime = w4
symbol SlaveRefreshTime = w5
symbol SlaveRefreshTimer = w6
symbol CheckCDSTime = w7
symbol CheckCDSTimer = w8

disablebod

low CDSPwr
low SlavePwr
low PTPwr
low LED
' set input pins as inputs
Input b.4
Input c.0
Input c.1
Input c.2
Input c.3
Input c.4
 
' set default variable settings
SlaveOn = 0
PTPwrOn = 0
DayStatus = 1
DaySetting = 128
NightSetting = 117
CheckCDSTime = 19350        '2.5 minutes 1 second = 129
SlaveOnTime = 3225        '25 seconds 1 second = 129
SlaveRefreshTime = 61921     '7.0 minutes 1 second = 129
nap 5

High LED
Pause 1000
High SlavePwr
SlaveOn = 1
Pause 30000
Low SlavePwr
SlaveOn = 0
SlaveRefreshTimer = 0
Pause 1000
Low LED
Pause 2000
High       CDSPwr                    ' apply power to CDS sensor
nap 5     ' allow power to settle
readadc                CDSRead, DayLevel
low CDSPwr
if DayLevel <= NightSetting then
       DayStatus = 0
    pause 500
endif
if DayLevel >= DaySetting then
    DayStatus = 1
    pause 500
endif
Pause 1000
GoSub Flash
Pause 1000
GoTo MainProgramLoop

Flash:
for Counter = 1 to 10
high LED
pause 200
low LED
pause 200
next Counter
return

MainProgramLoop:
If DayStatus = 1 Then
    GoTo DayProgram
Else
    High SlavePwr
    SlaveOn = 1
    High PTPwr
    PTPwrOn = 1
    GoTo NightProgram
EndIf

DayProgram:
If DayStatus = 1 Then
    sleep 131
    high       CDSPwr                    ' apply power to CDS sensor
      nap 5     ' allow power to settle
      readadc                CDSRead, DayLevel
      low CDSPwr
    if DayLevel >= DaySetting then
        DayStatus = 1
        CheckCDSTimer = 0
        If PTPwrOn = 1 Then
            Low PTPwr
            PTPwrOn = 0
        EndIf
        If SlaveOn = 1 Then
            Low SlavePwr
            SlaveOn = 0
        EndIf
    EndIf
      if DayLevel <= NightSetting then
            DayStatus = 0
        CheckCDSTimer = 0
        If PTPwrOn = 0 Then
            High PTPwr
            PTPwrOn = 1
        EndIf
        If SlaveOn = 0 Then
            High SlavePwr
            SlaveOn = 1
        EndIf
        Pause 500
        GoTo NightProgram
      endif
      pause 500
EndIf
Nap 3
GoTo DayProgram


NightProgram:
If DayStatus = 0 Then
    If PTInput = 1 Then
        High SlavePwr
        SlaveOn = 1 
        SlaveOnTimer = 0
    EndIf
    
    
    if SlaveOn = 1 then
          SlaveOnTimer = SlaveOnTimer + 1    'increment temporary counter for leaving the slave on 
          if SlaveOnTimer >= SlaveOnTime then           'flash recharge set to about 25 seconds no 
                 Low SlavePwr ' turn slave off
                SlaveOn = 0
                SlaveOnTimer = 0
            SlaveRefreshTimer = 0
                pause 500
          endif
    endif
             
    CheckCDSTimer = CheckCDSTimer + 1
    If CheckCDSTimer >= CheckCDSTime then
        high       CDSPwr                    ' apply power to CDS sensor
          nap 5     ' allow power to settle
          readadc                CDSRead, DayLevel
          low CDSPwr
          if DayLevel <= NightSetting then
                DayStatus = 0
            CheckCDSTimer = 0
            If PTPwrOn = 0 Then
                High PTPwr
                PTPwrOn = 1
            EndIf
            pause 500
          endif
          if DayLevel >= DaySetting then
            DayStatus = 1
            CheckCDSTimer = 0
            If PTPwrOn = 1 Then
                Low PTPwr
                PTPwrOn = 0
            EndIf    
            If SlaveOn = 1 Then
                Low SlavePwr
                SlaveOn = 0
            EndIf
            pause 500
            GoTo DayProgram
        endif
    EndIf
    SlaveRefreshTimer = SlaveRefreshTimer + 1
    if SlaveRefreshTimer >= SlaveRefreshTime then
        high LED    '************************************************
        pause 500
          high SlavePwr
        SlaveOn = 1
          pause 10000
        low SlavePwr
        SlaveOn = 0
          SlaveRefreshTimer = 0
          pause 500
        Low LED    '**************************************************
    EndIf
EndIf
Goto NightProgram
 
Last edited by a moderator:

westaust55

Moderator
Welcome to the PICAXE forum.

Please accept our apologies for any confusion and if you can tell us where the confusing information is we can see what we can do about improving that.

On the 14M2 the pins which can be used to trigger interrupts using the SETINT command are pins C.0, C.1 and C.2
I believe that the 'confusion' arises in the PICAXE manual2 (has been modified in online command pages) because under the SETINT command the "Restrictions" for 14M/14M2 mention inputs 0, 1 and 2"

But this also needs to be read in conjunction with the section under "Information" states that:
This can be a combination of pins on the default input port (PortC).
The next sentence then explains that only the X2 parts allows used/designation of alternate IO ports.
 

AllyCat

Senior Member
Hi,

Also, I believe that the "interrupts" on M2 devices are only "polled", so the PICaxe must be running (i.e. not sleeping or napping) to detect a (short) pulse. But, I do vaguely recall that hippy described some form of "latching" feature on the port pins?

However, I suspect that your hardware is already designed/built, with the PT on pinB.4 (Leg 9)? But does the program only need to detect that a pulse has occurred and then a brief delay before the flash is recharged would be acceptable? An alternative way to do this would be to trigger the/a "SR latch", and then the program could check this latch (rather than the pin) when it wakes from nap/sleep.

Unfortunately, the SR Latch has only one trigger pin (not B.4) and IIRC cannot actually be read directly by the program. However, I have devised an alternative method which can latch from a greater range pins (including B.4) and be read directly by the program:

It needs a fair number of POKE/PEEKSFRs but I can give more details if required. Basically, it uses an on-chip Comparator (which offers a further benefit of a selectable analogue input level) to trigger the "Timer1 Gate Latch" hardware (which can be read by the program). Note that the T1Gate hardware may operate totally independently of Timer 1, so the "time" variable can operate entirely as normal. For more details see (particularly) post #7 in this thread.

Cheers, Alan.
 

oracacle

Senior Member
there maybe a of a cheat for this, depending on the secondary flash, you maybe be able to use the actual flash in slave mode. all you would need to do is keep it awake and it would do the hard work of detecting the primary flash. this would mean the picaxe could still be asleep when the system fires and the secondary flash would still fire. This may cause some power supply issues, but does negate the interrupt issue.

Although if you were to use a 20X2 instead of 20M2 you could use the hardware interrupt as that would wake the picaxe from sleep - not tried this my self but can't see any reason why it would not work but I do not know if it will run the interrupt sequence or just continue running the programme as before
 

FIREMANJIM

New Member
When the chip is in sleep mode it is daytime and the PT Input is not even powered on. It is simply waiting for night time to arrive. When the CDS sensor sees it is night it Powers on the PT sensor and turns on the slave for 30 seconds to charge it all the way up. So sleep is not the issue. I can redesign the board have more made for less than $50.00 so that is fine. I guess what I need to know is a interrupt the best way for me to accomplish what I need???
 

AllyCat

Senior Member
Hi,

in night mode I can not put in the nap 3 because it misses the flash firing so it has to run at a straight 4mhz. I am thinking I need to use a SETINT for the PT sensor instead of what I am doing now. I think a SETINT will monitor the PTInput pin more allowing me to use a nap 3
A PICaxe (core) running at 4 MHz consumes about 600 uA (i.e. no more than 3 mW), is that a problem? If so, then you have presumably designed all the rest of the hardware to use a comparable average power? ;)

An important consideration is the length of the "pulse" from the PT (i.e. us, ms or seconds)? Another possibility to save power is to lower the clock to (say) 250 kHz (k250) with a "tight" waiting loop, either polling the pin or a PAUSE until a (soft) interrupt. But interrupts do add an extra level of "complexity" !

Personally, I would connect the PT to the T1Gate input (Leg3) and use the latch as I described above. I'm fairly sure it will latch during a nap/sleep, and certainly it will at even the lowest (32kHz) master clock frequency. But of course any application like this should be tested/breadboarded before committing to a PCB.

Cheers, Alan.
 

oracacle

Senior Member
When the chip is in sleep mode it is daytime and the PT Input is not even powered on. It is simply waiting for night time to arrive. When the CDS sensor sees it is night it Powers on the PT sensor and turns on the slave for 30 seconds to charge it all the way up. So sleep is not the issue. I can redesign the board have more made for less than $50.00 so that is fine. I guess what I need to know is a interrupt the best way for me to accomplish what I need???
this is the question, essentially yes - if you don't want them to wake the system using a M2 chip. using the interrupt will allow you to check for daylight in a continuous loop, the interrupt iirc will be checked by the picaxe between every command execution. hardware interrupts are generally accepted to be faster.

I have a photo transistor sensor for the high speed photography unit. The unit does not have the check for daylight function you are attempting to design. The system also controls the camera as well as the flash and a torch.
I am currently working on laser trip wires which could be used for trails.

here is the high speed unit I built, it uses the comparator interrupt on the 28x2, but running @ 64mhx the response time is very respectful - I don't know how you intend to expose you image but response time maybe something you need to look into, M2 parts can run @ 32mhz I believe but this will affect the timer. you can change the clock speed at any point in the programme
http://www.picaxeforum.co.uk/showthread.php?26768-High-speed-photography

generally before designing and producing a board you should do some prototyping on a bread board to ensure that you ideas are going to work and there the system idea are developed enough to have a good chance of working - I suggest you take this route before having anything else made. you need to ensure that your chosen detection method can detect the possibly tiny pulse width, some flashes at lower power setting will only emit light for less than 1/40,000 second (even at full power 1/1000s). For that short of a time period you may well need an SR latch to capture the signal.
I built a high accuracy timer based on some work that hippy did, it is capable of capturing a flash, it uses 2 SR latches as it twin input timer, there are some extra bit in there for functionality
http://www.picaxeforum.co.uk/showthread.php?28067-High-accuracy-timer

projects may look simple from the outset, but often turn out to be more complex not long after starting, bread boarding a prototype reveals difficulties before they become a major issue, reveals if you have chosen the right hardware and if you need to add a little extra or can do without something else
 

FIREMANJIM

New Member
I finally got this thing working perfectly using the interrupt running at 4mhz. Has not missed a beat in 3 days. How much greater will the battery drain be running it at a straight 4mhz without a nap 3 at the bottom of the code than it would be at 4mhz with a nap 3 at the bottom of the code??? I am assuming that it won't be that significant. And help appreciated.
 

westaust55

Moderator
I finally got this thing working perfectly using the interrupt running at 4mhz. Has not missed a beat in 3 days. How much greater will the battery drain be running it at a straight 4mhz without a nap 3 at the bottom of the code than it would be at 4mhz with a nap 3 at the bottom of the code??? I am assuming that it won't be that significant. And help appreciated.
Have you tried to measure any current values under various conditions.

From this older thread:
http://www.picaxeforum.co.uk/showthread.php?20519-Low-power-operation
something like 50 uA seems reasonable for low power mode.

From AllyCat's advise, in post 11 above, maybe 600 uA for a PICAXE running normally.

when you start to add any other devices, even just a high intensity LED the minimum could be of the order of 1.5 mA or more.
 
Top