I think I already know the answer?

Lez T

Member
A little question to which I believe the main answer will be 20X2 and irin.
Is there a way to do a 'Timeout' for infrain2, I am using the 18x and have come to a stumbling block whereby I sometimes get stuck at infrain2 command, if the infra signal is lost, I know that the irin command has a timeout with it but I have got most of the coding done for the 18x and the 20x2's won't be here until early next year,( I know it's only a couple of days but it sounds longer).

A work around would be handy to prove or disprove some theories.
I am already counting the pulses and averaging them on input0 ( leg 17), to check that I am still receiving a signal.

Code:
	count 0, 2000, b0 			'count pulses in 2 seconds
	for counter = 1 to 10
	w2 = w2 + b0 			        'take 10 samples and add together
	next
	b0 = w2 / 10                               'divide result to get average into b0
	pause 50
	if b0 = 104 and b10 = 75 then run   'b10 is the saved IR 'code'
	if b0 = 104 and pin2 = 0 then ask    ' pin2 is the input button to accept 
                                                        ' the received code on LCD prompt
[code]

but I need to do infrain2 to refresh this if the IR stops.

All suggestions are welcome, anything is better than a wait for Jan 2010.
Regards.
Lez.
 

Lez T

Member
Hippy, thank you, but I took one look at the code and knew that I didn't understand a 'bit' of it, I am going to check out and see if different IR codes produce a different result in my calc's and attempt to get roung it that way.

Still a serious newbie with this code lark.
Regards.
Lez.:confused:
 

eclectic

Moderator
@Lez.

Could you give us some more info
about your requirements please?

At the moment, you need between
1040 – 1049 pulses,
input over 2 seconds. (Allowing for timing errors).

That's a very narrow range. < 1% variation.


e
 

MartinM57

Moderator
Code:
count 0, 2000, b0 'count pulses in 2 seconds
for counter = 1 to 10
w2 = w2 + b0 'take 10 samples and add together
next
b0 = w2 / 10 'divide result to get average into b0
...
if b0 = 104 and b10 = 75 then run 'b10 is the saved IR 'code'
...
There's no averaging going on here - you're doing one count command, multiplying the answer by 10 in a circuitous manner and then dividing it by 10...

Also run is a command, so can't be after a IF..THEN statement and the compiler throws it out - please, at least, post code that compiles ;)

And without seeing what variable you have symbol'ed to counter, bets are off as to what your code is doing
 

Lez T

Member
@E

The code is a bit scrappy at the moment as I am trying to combine 2 parts, as below.

[code}
'IR recieve and Alarm OK. Lez T.18x





main:

symbol counter = b1 'define the variable b1 as counter
symbol counter2 = b6 'define the variable b5 as counter2

infrain2 'wait for new signal
let b10 = 75 'psuedo id code stored in b10
if infra = b10 then swon1 'right 'code' switch on 1
if infra <> b10 then alarm1 'wrong 'code' switch alarm1
swon1:

high 2 'Led to show operation
pause 100
low 2
pause 100
b1 = 0 ' reset b1 to 0
w2 = 0 ' reset w2 to 0
count 0, 2000, w1 ‘ 'count pulses in 2 seconds
for counter = 1 to 10
w2 = w2 + w1
next
w1 = w2 / 10 'w1 averaged reading of 5*w1/5 ie 20%
if w1 >115 then alarm1 'out of range alarm
if w1 <95 then alarm1 'out of range alarm

goto main 'else loop back to start

alarm1: 'label alarm1
for counter2 = 1 to 5 'should be 25 (25*1.2s=30s)
high 2,3,4
pause 200 '**pin 2 = LED**
low 2,3 '**pin 3 = LCD backlight**
pause 200 '**pin 4 = Buuzzer**
high 2,3
low 4
pause 200
low 2,3,4
pause 200
high 2,3
low 4
pause 200
low 2,3
pause 200
next counter2
goto main

'next stage full alarm after timer and resume monitor after inititial alarm'
[ code]

and this part, which is the user interface LCD and buttons

Code:
' Screen rx store and ok..... OK. Lez T.18x








init: 
	pause 1000							'short pause
	serout 7,n2400,(253,1,"Received code is")		'load mess #1
	pause 1000							'short pause
	serout 7,n2400,(253,2,"          ..Store ? ")		'load mess #2
	pause 1000							'short pause
	serout 7,n2400,(253,3,"***** Alert On  ")		'load mess #3
	pause 1000							'short pause
	serout 7,n2400,(253,4,"Checking code    ")		'load mess #4
	pause 1000							'short pause
	serout 7,n2400,(253,5,"**** mode  O.K. ")		'load mess #4
	pause 1000							'short pause

let infra = 0							        'reset infra in
let b10 = 0								'reset b10 ''ID'store' 
 	
main:
	infrain2							'code 'ID' from IR 

	serout 7,n2400,(254,128)				'goto line1 pos1
	pause 50							'short pause
	serout 7,n2400,(1)					'display mess #1
	pause 1250							'short pause
	serout 7,n2400,(254,192)				'goto line2 pos1
	pause 50							'short pause	
	serout 7,n2400,(2)					'display mess #2
	pause 1250							'short pause
	serout 7,N2400,(254,192,#infra," ")			'display infra & mess#2
	pause 1000

if pin2 = 1 then goto store					'push button on unit 
goto main								'no pin2 got to main

store:								'write to b10 & confirm
	let b10 = infra						' write id to b10
	serout 7,N2400,(254,192,#b10,"    STORED>> ")	'display mess and ID
	pause 3000							'pause 3 secs
	goto display1

display1:
	serout 7,n2400,(254,1)					'clear LCD
	pause 50							'short pause
	serout 7,n2400,(254,134)				'goto line1 pos1
	pause 50							'short pause
	serout 7,n2400,(3)					'display mess #3
	pause 1250							'short pause
	serout 7,n2400,(254,192)				'goto line2 pos1
	pause 50							'short pause
	serout 7,n2400,(4)					'display mess #4
	pause 50							'short pause								
	serout 7,N2400,(254,206,#b10," ")			'display b10 & mess#4
	pause 1000							'short pause
	serout 7,n2400,(254,1)					'clear LCD
	pause 50							'short pause
	serout 7,n2400,(254,192)				'goto line2 pos1
	pause 50							'short pause	
	serout 7,N2400,(5)					'display mess #5
	pause 1250							'display pause 
	serout 7,n2400,(254,1)					'clear LCD
	pause 50							'short pause
	serout 7,n2400,(254,134)				'goto line1 pos1
	pause 50							'short pause
	serout 7,n2400,(3)					'display mess #3
	pause 1250							'short pause
	serout 7,n2400,(254,192)				'goto line2 pos1
	pause 50							'short pause
	serout 7,n2400,(4)					'display mess #4
	pause 50							'short pause								
	serout 7,N2400,(254,206,#b10," ")			'display b10 & mess#4
	pause 1000							'short pause
	serout 7,n2400,(254,1)					'clear LCD
	pause 50							'short pause
	serout 7,n2400,(254,192)				'goto line2 pos1
	pause 50							'short pause	
	serout 7,N2400,(5)					'display mess #5
	pause 1250							'display pause 
	if infra = b10 then goto display1	
	if infra <> b10 then goto main


	'*************''next step alarm int and display change''********

[code]

In the first part of the code I can lose the IR and go to alarm 19 of 20 times, I would like to try and find a way to eliminate the possibility of a 'lockup' as this is to be a demo to a customer who will fund the rest of the dev' work.
The second part which I did seperately is the 'user interface' of LCD and Buttons.
 I have ordered 20X2's  ( as the command 'irin' has a timeout) but will not get delivery until early jan and would like to try and work this out first. 
The joining together of the two codes I am finding harder than expected but I am plodding through.
Regards.
Lez.:confused:
 

eclectic

Moderator
@Lez.
Part of your program
Code:
count 0, 2000, w1 ‘ 'count pulses in 2 seconds
for counter = 1 to 10
w2 = w2 + w1
next
w1 = w2 / 10 'w1 averaged reading of 5*w1/5 ie 20%
if w1 >115 then alarm1 'out of range alarm
if w1 <95 then alarm1 'out of range alarm
What are you counting?

e
 

Lez T

Member
@E,
I was just counting the IR pulses to just check that ir was still being received.
I do not know if they change regarding each command ie ir numbers 35 or 76 or 127, this was my next move to see if there was any change that I could detect and use.
Regards.
Lez.
 

MartinM57

Moderator
The code is a bit scrappy at the moment as I am trying to combine 2 parts, as below.
Code:
'IR recieve and Alarm OK. Lez T.18x

main:

symbol counter = b1 'define the variable b1 as counter
symbol counter2 =[B][I] b6[/I][/B] 'define the variable [B][I]b5 [/I][/B]as counter2
Code:
infrain2 'wait for new signal
let b10 = 75 'psuedo id code stored in b10
if infra = b10 then swon1 'right 'code' switch on 1
if infra <> b10 then alarm1 'wrong 'code' switch alarm1
swon1:
...
... unless you're forcing the result of infrain2 to be exactly 75 somehow, not much chance of ever getting to swon1 where all the complexity is...

Code:
count 0, 2000, w1 &#8216; 'count pulses in 2 seconds
for counter = 1 to 10
w2 = w2 + w1
next
w1 = w2 / 10 'w1 averaged reading of [B][I]5*w1/5 ie 20%[/I][/B]...
eh? (as above - no averaging) and 5*w1/5 ie 20% doesn't make a whole load of sense to me

Sorry mate, I know it's time for Good Cheer and all that, but I don't understand what the real problem is and the code is just a bit too scrappy to spend time on...good luck..
 
Last edited:

Lez T

Member
@ Martin

Code:
count 0, 2000, b0 'count pulses in 2 seconds
for counter = 1 to 10
w2 = w2 + b0 'take 10 samples and add together
next
b0 = w2 / 10 'divide result to get average into b0
...
if b0 = 104 and b10 = 75 then run 'b10 is the saved IR 'code'
...
There's no averaging going on here - you're doing one count command, multiplying the answer by 10 in a circuitous manner and then dividing it by 10...

Also run is a command, so can't be after a IF..THEN statement and the compiler throws it out - please, at least, post code that compiles ;)

And without seeing what variable you have symbol'ed to counter, bets are off as to what your code is doing
It was my belief that my code would sample input0 for 2 secs and write its value to w2, do this for 10 samples, keeping a running total, then dividing the running total by 10 after 10 samples would give me an average.

Would someone be so kind as to tell me where I have gone wrong as I believe this is OK.
Also my code compiled OK and ran OK, the command 'run' is not used in the 18x and I have used it as a label ( wrongly) to allow me an easy check on the flow of my code. This was a mistake to use this 'word' I will not use it again, but as I have only used 08's and 18x's I have never had to worry about using it, Apologies for a lack of experience here.
Regards.
Lez.
 
Last edited:

eclectic

Moderator
@Lez.

Far from perfect, but try this code
with your remote.

Code:
#picaxe 18X

Setint %00000000, 00000001 
;interrupts on Pin0 LOW (receiving ANY IR signal)

main:
sertxd ("waiting  ")
pause 1000

goto main

Interrupt:

infrain

sertxd (cr,lf, "key = ", #infra,cr,lf)

Setint %00000000, 00000001 ; Re-Sets interrupt

return

#rem
see Manual 2, page 180
e
 

Lez T

Member
@ Martin
... unless you're forcing the result of infrain2 to be exactly 75 somehow, not much chance of ever getting to swon1 where all the complexity is...
All I am doing is to transmit the number 75 from another pic, sorry , I don't know how else to get a number to infrain2 via input0.

Code:

count 0, 2000, w1 &#8216; 'count pulses in 2 seconds
for counter = 1 to 10
w2 = w2 + w1
next
w1 = w2 / 10 'w1 averaged reading of 5*w1/5 ie 20%...

eh? (as above - no averaging) and 5*w1/5 ie 20% doesn't make a whole load of sense to me
Please see last post as I thought it was correct, please advise...

An apology for mistakes in the labelling, as I have stated before this is fairly new to me
 
Last edited:

MartinM57

Moderator
Code:
w2 = 0
for counter = 1 to 10
  count 0, 2000, w1 &#8216; 'count pulses in 2 seconds
  w2 = w2 + w1
next
w1 = w2 / 10 'w1 is averaged reading of 10 two second counts of pin0
You have to put the count inside the loop.

...and this will all but lock up your system for 20 seconds while it runs - maybe that's OK, but you need to appreciate that...
 

Lez T

Member
@Martin
Thank you, I now know where I am going wrong with this. I will look into this.
Thank You.
Regards.
Lez.
 
Last edited:

Lez T

Member
@E,
what I really need is to know that the IR is NOT there, without locking up, will the input be high without IR and then I could use,
Setint %00000001, 00000001 (ie check input0 for a 1 high state, no IR rx )

I had looked at using an interrupt but did not know what the pin state was, and had not got as far as checking with the 'scope. I had looked at the pin and saw that there was a frequency of some sort and my early checks with averaging were giving varied results, thus my going down the path of averaging it out to 'see' an IR input, I believe the battery pack on the TX board was going low and giving me varied tx.
 
Last edited:

eclectic

Moderator
@E,
what I really need is to know that the IR is NOT there, without locking up, will the input be high without IR and then I could use,
Setint %00000001, 00000001 (ie check input0 for a 1 high state, no IR rx )

I had looked at using an interrupt but did not know what the pin state was, and had not got as far as checking with the 'scope. I had looked at the pin and saw that there was a frequency of some sort and my early checks with averaging were giving varied results, thus my going down the path of averaging it out to 'see' an IR input, I believe the battery pack on the TX board way going low and giving me varied tx.
At the moment, without knowing your circuit,
I can only suggest that you experiment.

Signing off for some late Christmas cheer. :)))

Ho Ho Ho
 

Lez T

Member
@E,
I will have to draw them up first as the project is breadboarded at the moment on a Axe091, off to P'boro in a while, so it will be tomorrow, also, haven't tested the interrupt code yet, will get on to that too.
Regards.
Lez.
 

Lez T

Member
Windows XP home edition, if I had any left I would pull my hair out.
All I have to do is hit control print screen and it will copy the desktop to the clipboard, still cannot make a forum-able file out of it...
 
Last edited:

eclectic

Moderator
Tomorrow ,
play with Gadwin again (Ohh-err).

You can draw a box around the bits you need.

More jokes about artistic cricketers, but I'll shut up!

e
 

slimplynth

Senior Member
http://www.google.co.uk/search?q=snagit&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a

If you're on XP (works on win7)...

there's a handy bit of sofware, 'snagit'. Amongst other things; will let you take freehand sections of a picture and place into clipboard... handy if you want to graft the face of your nearest an dearest onto baboon bodies.. here's a badly drawn one of me :)



snagit also lets you capture your desktop and save as a movie/video file... handy if anyone ever wanted to youtube their simulator etc woes.
 

eclectic

Moderator
@Lez.

If you're using Express or similar:

1. Do the drawing.

2. Use the mouse roller or the zoom key
to enlarge the required circuit to full screen size.

3. Then screen-capture.

e
 

Lez T

Member
Finally found a way to show the circuit.


Hope this works after all this......
Regards.
Lez.

Was it worth it?

Thanks @E the interrupt works great
 
Last edited:
Top