Infrared output while parallel tasking.

daeleo

New Member
Hi guys,
If anyone out there has experience with Infrared, I'd sure appreciate your input on this...

I'm attempting to make a simulated, defusable bomb for our Lazertag games, and I've only recently had some success in my attempts to get my 20m2 to talk to our lazertag guns.

After googling to hell and back, I've come across the info needed to both pulse accurately at 38khz,

setfreq m32
PWMOut IR,209, 421


and I've found the proper protocol to talk to our taggers

http://web.archive.org/web/20090304155723/http://lasertagparts.com/ltto.htm

Which successfully triggered damage responses on my Pheonix LTX tagger.


My problem lies in that all the operations I need the chip to perform, I'm going to be using the parallel tasking feature;
Which, to my knowledge, forcibly sets the clock freq to 16mhz, and executes operations at 4mhz.

After attempting to compensate by dropping pwmout (and the related pauses) down by a factor of 8 (also by using the wizard) to;
PWMOut IR,25, 52

I just can't get a response from the gun anymore, is it because the frequency accuracy is too far out of spec?

(also, at this juncture, I'm not attempting to run any additional tasks save for placeholder pauses to force the parallel tasking mode, and the only thing I have wired up is an emitter LED to a transistor, which functioned perfectly at the 32mhz setup)
 

westaust55

Moderator
Lcome to the PICAXE forum.

Although you are seemingly past the IR basics, you may still find the IR basis tutorial I posted here of interest:
http://www.picaxeforum.co.uk/showthread.php?17303-Infrared-(IR)-Communications-Basic-Tutorial

With respect to the M2 parts, the default clock speed is 4MHz and when multitasking, as you say, the clock speed is auto increased to 16MHz and each process operates at nominally 4MHz.
There is no need to adjust PAUSE commands etc down by a factor of 8. very minor tweaks may be needed for time critical tasks.
 

daeleo

New Member
Ah yes! I read your pdf, and it most certainly helped get me to where I am now, thank you for that :)

I guess what it boils down to is whether this non-functioning output at 4mhz;

Code:
PWMOut IR,25, 53
pauseus 300

PWMOut IR, off
pauseus 600

PWMOut IR,25, 53
pauseus 300

PWMOut IR, off
pauseus 200
;end preamble


;team
PWMOut IR,25, 53
pauseus 100              ;0

PWMOut IR, off
pauseus 200              ;space


PWMOut IR,25, 53
pauseus 100              ;0

PWMOut IR, off
pauseus 200              ;space
;/team


;playerid
PWMOut IR,25, 53
pauseus 100              ;0

PWMOut IR, off
pauseus 200              ;space
            

PWMOut IR,25, 53
pauseus 100              ;0

PWMOut IR, off
pauseus 200              ;space
              

PWMOut IR,25, 53
pauseus 100              ;0

PWMOut IR, off
pauseus 200              ;space
;/playerid           


;mega
PWMOut IR,25, 53
pauseus 100              ;0

PWMOut IR, off
pauseus 200              ;space


PWMOut IR,25, 53
pauseus 100             ;0

PWMOut IR, off ;off
;/mega
Is equivalent to this properly functioning code running at 32mhz;
Code:
PWMOut IR,209, 421
pause 24

PWMOut IR, off
pause 48

PWMOut IR,209, 421
pause 24

PWMOut IR, off
pause 16
;end preamble



PWMOut IR,209, 421
pause 8              ;0

PWMOut IR, off
pause 16              ;space



PWMOut IR,209, 421
pause 8              ;0

PWMOut IR, off
pause 16              ;space


PWMOut IR,209, 421
pause 8              ;0

PWMOut IR, off
pause 16              ;space



PWMOut IR,209, 421
pause 8              ;0

PWMOut IR, off
pause 16              ;space



PWMOut IR,209, 421
pause 8              ;0

PWMOut IR, off
pause 16              ;space



PWMOut IR,209, 421
pause 8              ;0

PWMOut IR, off
pause 16              ;space



PWMOut IR,209, 421
pause 8             ;0

PWMOut IR, off ;off
If it indeed is equivalent, then I suppose I have to sit there and tweak the micro-pauses (tried raw pauses to no avail sadly), to see if that can compensate for some sort of execution lag.. or something like that...

Anyhow, thank you again, you've already been a big help before you even replied to my post!
 

SAborn

Senior Member
It seems to me you have your pause's ass about, if at 32mhz you have a pause of 16 than at 4mhz it would be the same as pause of 2 not 200.

Then i could be wrong, as i dont have my mind around what it is you are trying to do exactly.
 

daeleo

New Member
Yes, true, but as a simple pause of 2 didn't seem to work, I then am attempting to employ Microsecond pauses (pauseus as opposed to pause), 200 of which being equal to a normal pause of 2.

My hope is that by shrinking the pauses to the microsecond level, that perhaps tweaking them a few microseconds in either direction may force the signal back into "phase," and make it work again, if you know what I mean.

Though no luck as of yet.. :p
 

inglewoodpete

Senior Member
I may be wrong but I don't think it would be possible to do something that is time critical like this on something as simple as a PICAXE.

It does not run true parallel tasks but (something like) multiplexing commands from 2 or more "tasks" (read: programs or queues). So if you are doing something time-critical in Task 1 and Task 2 executes a time-consuming command, then there will be a delay before Task 1 gets to execute its next command.

I suspect that you need to dedicate a (PICAXE) chip to your time-critical task.
 

srnet

Senior Member
I then am attempting to employ Microsecond pauses (pauseus as opposed to pause), 200 of which being equal to a normal pause of 2.
You will find that because of the delay excuting commands, pause 2 might not be the exact same delay as pause 200
 

daeleo

New Member
Ok, alternate idea!
I'll be willing to forgo the bomb's persistant "radiation damage" doing so will let me drop all the IR data to the end of the program when the bomb blows.

So then, I'll have to find a means of killing all of the other tasks upon "detonation," and, if at all possible, run a single task upclocked back to 32mhz to pulse out the "death blow" IR damage.

You guys think this falls more into the realm of plausibility?
 

hippy

Ex-Staff (retired)
You guys think this falls more into the realm of plausibility?
There's more chance of it working with all other tasks suspended or aborted but I am not sure you can bump any multi-tasking PICAXE up to 32MHz.

The best way would be to try it and compare the output with what works on a scope or logic analyser, and to compare that with known output from gun detonation to ensure the timing is as close as it can be.

The other option is to add a second PICAXE dedicated to detonation signalling; trigger that from the master PICAXE then you can do whatever you want in the master and not have to worry about it not working.
 

BillyGreen1973

Senior Member
The other option is to add a second PICAXE dedicated to detonation signalling; trigger that from the master PICAXE then you can do whatever you want in the master and not have to worry about it not working.
This is the way I would go too. The IR output picaxe can be a small 08M2. This way your 'radiation damage' feature can be used too buy just signalling the 08M2 to output every few ms. The link between the two picaxe's could be a simple RX/TX, and leave the main Picaxe to deal with 'de-fuse' puzzle/game.
 

GrahamGo

Senior Member
Hi I had a logic analyzer hooked up for something else. So this only took a minute or two. Here is your code, with some time measurements. I cannot measure the PWM total times, so just toggled another pin at every transition. Its probably not a totally accurate measurement, but hopefully it helps.

Your PWM at 4 & 32mh/z is spot on. But you can see that the delays @ 4mh/z are longer than @ 32mh/z. Maybe you can do the maths, and compensate. If you want to put the modified code back up I can measure again.

infra1.JPG

Code:
dirsB = %111111
symbol IR = B.4
Symbol EN_Pin = B.3

setfreq m32

toggle EN_Pin
	PWMOut IR,209, 421 	; functioning @ 32mh/z
	pause 24						; = 3.242ms
toggle EN_Pin
	PWMOut IR, off
	pause 48						; = 6.183ms
toggle EN_Pin
	PWMOut IR,209, 421	; = 38.462 kh/z
	pause 24						; = 3.242ms
toggle EN_Pin
	PWMOut IR, off
	pause 16						; = 2.2ms
;end preamble
toggle EN_Pin
 


setfreq m4
 
toggle EN_Pin
	PWMOut IR,25, 53 		; none functioning @ 4mh/z
	pauseus 300					; = 5.25ms

toggle EN_Pin
	PWMOut IR, off
	pauseus 600					; = 8ms

toggle EN_Pin
	PWMOut IR,25, 53 		; = 38.462 kh/z
	pauseus 300					; = 5.21ms

toggle EN_Pin
	PWMOut IR, off
	pauseus 200					; 3.88ms

;end preamble
toggle EN_Pin
 

GrahamGo

Senior Member
Couldn't just leave it! Ok, I made some compensations. I removed the "toggles" and measured the pulse trains in mm on the PC screen. The only measurement that I can accurately do is the 6ms preamble PWM=off. Try with the new 4mh/z values below, these are very close to the 32mh/z timings, so try tweaking around these numbers. I did try the Pause 6 @ 4mh/z and this measures = 7.6ms

Code:
dirsB = %111111
symbol IR = B.4
Symbol EN_Pin = B.3

setfreq m32

toggle EN_Pin
	PWMOut IR,209, 421 	; functioning @ 32mh/z
	pause 24						; = 3.242ms
;toggle EN_Pin
	PWMOut IR, off
	pause 48						; = 6.183ms
;toggle EN_Pin
	PWMOut IR,209, 421	; = 38.462 kh/z
	pause 24						; = 3.242ms
;toggle EN_Pin
	PWMOut IR, off
	pause 16						; = 2.2ms
;end preamble
;toggle EN_Pin
 


setfreq m4
 
toggle EN_Pin
	PWMOut IR,25, 53 		; none functioning @ 4mh/z
	pauseus 200					; 

;toggle EN_Pin
	PWMOut IR, off
	pauseus 400					; = 6.05ms

;toggle EN_Pin
	PWMOut IR,25, 53 		; = 38.462 kh/z
	pauseus 200
;toggle EN_Pin
	PWMOut IR, off
	pauseus 140
;end preamble
toggle EN_Pin
 

daeleo

New Member
You are amazing GrahamGo, I've gotten successful, albeit intermittent hits with this code: (you nailing the 6 pause made this immensely easier)

Code:
symbol IR = C.2
setfreq m4
symbol pause1 = b1
symbol pause2 = b2

let pause1 = 13
let pause2 = 26

do

PWMOut IR,25, 52
pauseus 180

PWMOut IR, off
pauseus 400

PWMOut IR,25, 52
pauseus 180

PWMOut IR, off
pauseus pause2
;end preamble


;team
PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space


PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space
;/team


;playerid
PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space
            

PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2             ;space
              

PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space
;/playerid   = LTX team 3, so as to damage both terrorists (team 1) and CTs (team 2)          


;mega
PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space


PWMOut IR,25, 52
pauseus pause1             ;0

PWMOut IR, off ;off
;/mega
Heck of a difference right? not even close to the original..

Also, for the sake of posterity, here is all my bomb code, (once I finish putting everything together, I'll likely have to tweak the ir a lot more..)



Code:
;Physical design:
; flat panel in a box with 3 evenly spaced potentiometers, each with a corresponding led which lights when properly aligned,
; in the middle in the start/disarm button, aad above it is a hatch in the panel which, when properly disarmed, opens and a tritium keychain core is
; held between two points, which, upon removal is the final step to disarm the bomb.
; to the side there also lies a switch to toggle the game running time so 10 or 20 upon boot.


; --------------------PIN MAPPINGS--------------------


;* indicates reserved -potential- function
; 17 usable pins
; pin C.6 is IN only


;~~~~~~~~~~~~~~~~~~~~~~~~ Right side of chip ~~~~~~~~~~~~~~~~~~~~~~~~
; pin A.0 can be disconnected and used as IN only --Difficult--


;pin B.7 is POT 1 Indicator LED      =(OUT)=

;pin B.6 is POT 2 Indicator LED      =(OUT)=
 
;pin B.5 is POT 3 Indicator LED      =(OUT)=  
 
;pin B.4 is Servo*                   =(OUT)=

;pin B.3 is Piezo Buzzer             =(OUT)=  

;pin B.2 is Blown LED                =(OUT)= 

;pin B.1 is IR LED                   =(OUT)=   

;pin B.0 is Disarmed LED             =(OUT)=   

;-----------------------------------------------------------------------------------
;~~~~~~~~~~~~~~~~~~~~~~~~ Left side of chip ~~~~~~~~~~~~~~~~~~~~~~~~~
  
;pin C.7 is   

;pin C.6 is Start / Disarm Button    =(IN!)=  

;pin C.5 is Core detection circuit*  =(IN)=

;pin C.4 is Timer Select Toggle      =(IN)=  

;pin C.3 is Potentiometer 1          =(IN)=

;pin C.2 is Potentiometer 2          =(IN)=

;pin C.1 is Potentiometer 3          =(IN)= 

;pin C.0 is the servo reset button*  =(IN)=



;--------------------END PIN MAPPINGS--------------------


;Note - servos only work at 4mhz or 16mhz
;clock auto-set to 16mhz with 4mhz timings

#Picaxe 20M2

symbol IR = B.1
symbol blown = bit0
symbol timeswitch = pinC.4
symbol timeremaining = w3
symbol POTLED1 = B.7
symbol POTLED2 = B.6
symbol POTLED3 = B.5

symbol POT1True = bit1
symbol POT2True = bit2
symbol POT3True = bit3
symbol StartStop = pinC.6
symbol Core = pinC.5

symbol pause1 = b1
symbol pause2 = b2






Start0:
;Pot position routine

readadc10 c.1,b1 ;read and set random positions
random b1
readadc10 c.2,b2
random b2
readadc10 c.3,b3
random b3

readadc10 c.1,b4 ;read random into timer value

do
readadc10 c.1,b5

readadc10 c.2,b6

readadc10 c.3,b7


loop



Start1:
;core removal and Interrupt routines
do

if Core = 0 then goto Disarmed


if b5 = b1 then high POTLED1 let POT1True = 1
if b5 != b1 then low POTLED1 let POT1True = 0
endif
endif


if b5 = b1 then high POTLED2 let POT2True = 1
if b5 != b1 then low POTLED2 let POT2True = 0
endif
endif


if b5 = b1 then high POTLED3 let POT3True = 1
if b5 != b1 then low POTLED3 let POT3True = 0
endif
endif

if POT1True = 1 and POT2True = 1 and POT3True = 1 and StartStop = 1 then suspend 0 suspend 2 goto Disarmed
endif


if POT1True = 0 and POT2True = 0 and POT3True = 0 and StartStop = 1 then suspend 0 suspend 2 goto Blownup
endif

if POT1True = 0 and POT2True = 0 and POT3True = 1 and StartStop = 1 then suspend 0 suspend 2 goto Blownup
endif

if POT1True = 0 and POT2True = 1 and POT3True = 0 and StartStop = 1 then suspend 0 suspend 2 goto Blownup
endif

if POT1True = 0 and POT2True = 1 and POT3True = 1 and StartStop = 1 then suspend 0 suspend 2 goto Blownup
endif

if POT1True = 1 and POT2True = 0 and POT3True = 0 and StartStop = 1 then suspend 0 suspend 2 goto Blownup
endif

if POT1True = 1 and POT2True = 0 and POT3True = 1 and StartStop = 1 then suspend 0 suspend 2 goto Blownup
endif

if POT1True = 1 and POT2True = 1 and POT3True = 0 and StartStop = 1 then suspend 0 suspend 2 goto Blownup
endif

loop



Start2:
;Timer and beep routine -- beeps faster as it approaches , fancy intense movie-style.

if timeswitch = 0 then let timeremaining = 1000 + b4 ;tune for 10 minutes
endif
if timeswitch = 1 then let timeremaining = 10000 + b4 ;tune for 20 minutes
endif


FOR b4 = timeremaining  TO 0 STEP 15 ;fine-tune later

	sound B.7,(25,50)
	pause timeremaining
	
	if timeremaining = 0 then goto Blownup
next








Start3:
;radiation routine

let pause1 = 13
let pause2 = 26

pause 10000

do

PWMOut IR,25, 52
pauseus 180

PWMOut IR, off
pauseus 400

PWMOut IR,25, 52
pauseus 180

PWMOut IR, off
pauseus pause2
;end preamble


;team
PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space


PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space
;/team


;playerid
PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space
            

PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2             ;space
              

PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space
;/playerid   = will be set to LTX team 3, (363-0001100) so as to damage both terrorists (team 1) and CTs (team 2)          


;mega
PWMOut IR,25, 52
pauseus pause1              ;0

PWMOut IR, off
pauseus pause2              ;space


PWMOut IR,25, 52
pauseus pause1             ;0

PWMOut IR, off ;off
;/mega


if Blown = 1 then goto Blast
pause 5000
if Blown = 1 then goto Blast
loop



Blast:
;kill damage, probably max mega damage (binary 11), times 7 to ensure even players with 25 health die.



Disarmed:
;happy green lights or bomb goes dark or something, good jorb.


Blownup:
let Blown = 1
sound B.7,(190,100) ;some long and dreadful sounding beeps that accompany failure.
;Notes 1-127 are ascending tones. Notes 128-255 are ascending white noises. -- so some static too probably.
 

GrahamGo

Senior Member
Happy to help, like you I haven't been playing with Picaxe for very long. But I like your application. I see that there is a completed projects area, perhaps you can stick it in there when you have wrapped it up.

Edit. Actually there is a problem. See attached. In the data portion PWM=off period is 1.844ms (I don't know what it should be) But see the logic trace, which is showing single data PWM=on, see that this comprises of two frequencies, which are 38.46kh/z and 153.84kh/z.

Someone mentioned in the multitasking mode that the clock is fixed at 16mh/z and the tasks operate at a nominal 4mh/z. It appears that this is not quite true. Clearly your program is switching between 4 & 16mh/z. Strangely though each PWM data bit switches clock frequency in the same places.

But based on what I see, I think the suggestion of adding an 08M2 just to provide the PWM stuff is the way to go.

infra2.JPG
 
Last edited:
Top