Another Interrupt question

donrecardo

Senior Member
Hi
I need to measure how far my model train has travelled each time it goes out for a run.

I know that every 55 turns of the wheels equals 1/100th of a mile travelled so I planned on using a slotted opto detector with schmidt output ( I had one in my parts box) to sit over a disk attached to an axle giving me one output per revolution of the axle .

I tried this code in the simulator
Code:
b0=0   ' initializes the variable holding revolutions made
b1=0   ' initializes the variable which eventually will be the output display

setint %00000100, %00000100  'Interrupt when input 2 goes high , ( detector gets triggered)

idle:     'A loop to sit in waiting for the interrupt
      goto idle

interrupt:
      b0 = b0 + 1   'Wheel has turned once so add one to the counter 
      if b0 = 55 then    ' has it turned 55 times ? ( train travelled 1/100th of a mile)
      goto display           'if so add one to the output display
      endif

intwait:       ' a routine so that if the train just happens to stop with the 
                 ' disk blocking the detector it wont keep on incrementing b0
                 'input 2 must go low before another increment of b0 can occur 
      if pin2 = 1 then intwait  ' loop if disk has not yet cleared detector
      
       setint %00000100, %00000100
      return
display:
      b1=b1+1   ' here while using the debug screen I use b1 as the diplay of 
                    ' 1/100ths of a mile completed . the finished job will use an
                   ' electromagnetic counter
      b0=0     ' get b0 ready to start counting another set of 55
      setint %00000100, %00000100
      goto intwait     ' Same as before , to stop repeat if disk has parked blocking detector
It seemed to work fine on the simulator but then I found out that the slotted opto detector doesnt sit at 0v and go up to 5v on output, its reversed , it sits at 5v and when triggered goes low.
I didnt think that should be a problem and just changed the setint to
%00000100, 00000000 ,expecting it to interrupt when pin 2 goes low and I changed intwait: to look for 0 rather than 1 but for some reason that didnt work
what am I doing wrong ? and is interupt the best way to go in this instance ?

Incase speed may be an issue as to choosing wether or not to use interrupt , the trigger from the opto detector will never be more than 15Hz and most times would be around 6 Hz

Regards
Don
 
Last edited:

GreatWhiteNorth

New Member
I think you may have the setint input condition and mask in the wrong order.
Input condition first then mask.
ie
to interrupt on input1 high only
setint %00000010,%00000010

to interrupt on input1 low only
setint %00000000,%00000010

Hope this helps.
 

donrecardo

Senior Member
I worked out the answer for myself

Hi
I was reading the manual again and found my mistake.

I was putting setint %00000100, %00000100 to interrupt when pin 2 goes high
and that works fine but
putting setint %00000100, %00000000 wont interrupt on pin 2 going low

I had of course mixed up mask and value. I thought it was setint ,mask, value
when infact its setint, value, mask

I have left the original post incase another newbie gets the same problem and can then also see the answer

Hi Great white
I see while I was writing this reply you had already answered it but our posts crossed.
Thanks for the reply

Don
 
Last edited:

AndrewBrown

New Member
Interrupt with RFID and vmusic2

Hello, i am trying to put an interrupt into my code that uses rfid to play a track through a vmusic2 module. Im running it on a 28x1 chip and have 4 tags each playing different tracks.

I need to know how to put an interupt into this code so that if one track is playing it will stop and play a different one. Im a bit of a novice with this stuff and havn't ever used interrupts before.

This is the code i have tried but it didnt work:
setint %00000010, %00000010 'activate interrupt when pin1 only goes high

interrupt:
high 1 'switch output1 on
if b9=b9+1 then interrupt
pause 1000
setint %00000010, %00000010
return
With the rest of the vmusic2 and rfid code in between.

If anyone could help me it would be much appreciated. Thanks
 

papaof2

Senior Member
This line
if b9=b9+1 then interrupt
will never be true.

If you want to compare two values, they must be in separate variables.

John
 

westaust55

Moderator
What is the purpose of the pause 1000 command?
plain delay or waiting for an interrupt condition to clear.

Note that the interrupt feature is turned off whenever an interrupt condition arose so there is no need to wait for the condition to pass.
That is why we must add a new SETINT command to resume interrupt monitoring of inputs.
 
Top