using interrupt on 18m2 analogue input

michiko

New Member
Hi all.
I've designed a cct to control model train lights when oo gauge train passes using LDR's. Does anyone know what I type on the interrupt Setint command. I've read picaxe command manual page 180 and it shows Setint %10000000,%10000100 to mask and check pin 7&2. But this is digital I have if b0 < 100 etc. We want it to keep checking the presence of a train but it not to stop its normal led lighting sequence. My other way is to duplicate the readadc c.1, b0 in each subroutine. Let me know it its not possible guys. Many thanks.
 

AllyCat

Senior Member
Hi,

A PICaxe interrupt can be only generated by a digital signal, so you cannot specify an analogue threshold.

However, what you want to do is possible, but it needs very much "Advanced Programming" (not directly supported within PICaxe Basic). All the PICaxe M2 chips have additional hardware which is not directly supported by PICaxe instructions. In particular, they have at least one Comparator which can compare an external Analogue input voltage with an internal voltage level set by the Digital-Analogue Converter (which is supported by the PICaxe DACLEVEL and DACSETUP commands).

The output from the Comparator is a digital signal which then can generate an Interrupt. But the Comparator(s) hardware is only connected on a few specific pins (in the 18M2 they're a group of Legs at one end, from 17 around to 3). Also, the comparator output cannot be connected internally to an interrupt, so it's necessary to link two pins (which then cannot be used for anything else).

If you want to look into the possibilities, the starting pint is the Microchip base PIC data sheet.PDF for the 18M2, particularly the Comparator and DAC modules, how they are controlled by Special Function Registers, and the PICaxe PEEKSFR/POKESFR commands in PICaxe Manual 2.

Cheers, Alan.
 

WHITEKNUCKLES

New Member
Could you arrange the illumination on the LDRs so that the input to the Picaxe would cross the normal digital switching point?

Dave
 

BeanieBots

Moderator
Or, use an external comparitor to drive a digital input.
Personally, I'd simply put the check inside the 'normal' sequence of events and set a flag depending on the value read.
Multitasking is probably the best way to go but I've not played much with that. Prefer to role my own.
 

michiko

New Member
thanking you

Hi all you guys.
Many thanks indeed for your great replies. I'll start with your easier ideas first. Also i've just been thinking maybe I could set an output high when train is above LDR then read the output pin. I will feedback as I go along. I promised the rail club I could do this but last night I thought oops maybe I can't, Great to be able to ask questions.
Mike
 
Top