Interrupt and pulsin

atharvai

Senior Member
hi This may have been posted earlier sry.

I have a digital input on input 0 of 18X. I would like to trigger an interrupt when a '1' arrives. (I've managed to do that bit.) And then count the number of subsequent ones. there are several possible 8 bit sequences coming through.
1
01
011
0111
01111
011111
0111111
1111111
(yes variable lengths)

I tried putting in pulsin in the Interrupt sub routine but when simulating there was nothing stored in the variable b0 i used. i also tried w0. but nothing stored.

The following is my test program:
'**********************************************
Init:
let b0 = 0
let pins = %00000000
setint %00000001,%00000001
Main:
goto Main

Interrupt:
let pins = %00000001
pulsin 0,1,w0
setint %00000001,%00000001
return
'**********************************************

i think i'm using it wrong. not sure

THanks for the help in advance
 

tiscando

Senior Member
What is the baud rate of the signal to input 0 (i.e. how long a '1' is)?
The pulsin command measures the length of a pulse, but if the pulse is longer than 0.65535 sec, then the result is 0, so this is hard to simulate on the programming editor's simulator. also, in the picaxe manual no.2, look at the 'count' and 'serin' commands, see if they are better.
 

atharvai

Senior Member
good question. well the simple answer is no idea. i'll have to research a bit more and get back to u. in the meantime i will look at 'count' and 'serin'. Thanks
 

atharvai

Senior Member
ok the baud rate is not known at the moment so i won't use 'serin'. also the specs i've been given do not mention the pulse width or duty cycle. so i'm gonna go back and try and diginto some books and hte internet and look for more info...
thanks
 

hippy

Ex-Staff (retired)
I would like to trigger an interrupt when a '1' arrives. And then count the number of subsequent ones. there are several possible 8 bit sequences coming through.

pulsin 0,1,w0
If you want to count the number of pulses you have to use COUNT rather than PULSIN, but then you have to decide what period to count for.

If you simply want to know how any 1's have arrived, simply increment a number in a variable in your interrupt routine, wait for the current pulse to finish, then return from the interrupt ready for the next one.

I'm not sure what you're really trying to do, but if you want to determine how long each of the possible pulses lasts then you can use PULSIN but not in an interrupt.
 
Top