Combining signals generated by pulsout

Ghostbear

Member
Hi all,

This is more of a can-it-be-done than anything else.

At present, I've a circuit that generates two pwm signals (one carrier, one signal) and combines them via an external transistor.

Is there a method I could use to combine the signal internally before sending it to the output pin? I know I could do it with just the picaxe bh taking the output pins, reading them in on another pair of pins and outputting that, but that needs 3 extra pins and I'm trying to reduce the component count if possible :)
 

hippy

Technical Support
Staff member
Which PICAXE are you using ?

The M2 series have a Data Signal Modulator (DSM) on-chip which sounds like it may be exactly what you need having described a carrier and signal.

There might also be some diode-mixing, or resistor and diode-pull-down options but probably no saving over your transistor.
 

AllyCat

Senior Member
Hi,

The title says "Combining signals generated by pulsout" which might be more difficult.

But if you can use the PWM (or Capture/Compare) internal hardware, then it should be possible to apply those signals internally, directly to the DSM hardware, provided that you can identify which PICaxe pin corresponds to each PWM channel. See probably section 23 in the appropriate (M2) base Microchip PIC data sheet from the "Advanced Technical Details" link here.

Cheers, Alan.
 

hippy

Technical Support
Staff member
The title says "Combining signals generated by pulsout" which might be more difficult.
Possibly impossible as a single PICAXE can only generate one PULSOUT at a time. But maybe there are multiple PICAXE involved.

I was guessing it's a PWMOUT being gated by a PULSOUT, or series of those to generate something like a 38kHz IR remote control code signal. That's the sort of thing DSM is good for -

http://www.picaxeforum.co.uk/showthread.php?19241-38-kHz-Pulses-for-IR-Beacon&p=179772&viewfull=1#post179772

It may be possible to do the gating using the internal MDBIT with POKESFR, PAUSEUS, POKESFR to replace the PULSOUT.

It's always the problem with more open ended question'; there's no easy answer without more details. Hopefully Ghostbear will provide those.
 

Ghostbear

Member
Hi all,

Realised I could have worded the title better - apologies for that, it's been one of those days, not help by us losing our bearded dagon today :(

Anyhow, heres the code, and it was in fact PWM I was using:
Code:
; =================================================
;   File....... tag mk2 auto.bas
;   Purpose.... "Worlds of Wonder" compatible ir "gun" emiiter circuit
;   Chip.... 14M2
;   Author..... Adrian Arnold
;   E-mail..... [email]adyarnold1975@gmail.com[/email]
;  ===============================================
; -----[ Program Description ]---------------------------------------------
#rem

#endrem

; -----[ I/O Definitions ]-------------------------------------------------

symbol trg = pinC.2
symbol reload = pinC.1
symbol trigpls = B.5
symbol muzzflsh = B.3
Symbol carrierpls = B.4
symbol hitpls = B.2
symbol rldflsh = C.0

symbol shotrst =b1
symbol ammocount = b0
symbol counter = b1

; -----[ Variables ]-------------------------------------------------------
let shotrst=0

; -----[ Program Code ]---------------------------------------------------

init:
	pwmout carrierpls, 16, 33 ; 57600Hz at 50% @ 4MHz
	pwmout pwmdiv4, hitpls, 138, 277 ; 1800Hz at 50% @ 4MHz
	let ammocount=0

Main:
	  if trg=1 then 'may be better doing this as an interrupt
			do
				if ammocount<30 then
					high trigpls
					high muzzflsh
					pause 100 'wait 50 microsecond
					low trigpls
					low muzzflsh
					pause 100
					let ammocount=ammocount+1
					if ammocount = 30 then
						shotrst=1
					endif
				endif
				
		loop while trg=1 and shotrst<>1'ammocount<30 'shotrst=0	
	else 
		low trigpls
		low muzzflsh
endif 

if reload=1 then
	for counter = 1 to 20
		high rldflsh
		pause 200
		low rldflsh
		pause 200
	next
	let ammocount=0
	let shotrst=0
endif


goto main
 
Last edited:

hippy

Technical Support
Staff member
I am guessing this is the effective PULSOUT ...

Code:
high trigpls
high muzzflsh
pause 100 'wait 50 microsecond
low trigpls
low muzzflsh
It seems to be a 100ms pulse rather than 50us, so you could probably do it by turning PWMOUT on and off or using PWMDUTY commands, setting duty to 0 for off.
 

AllyCat

Senior Member
Hi,

Beware that PWMDUTY is rather a "slow" command compared with PWMOUT. A clue is that PWMDUTY adds about 34 bytes to the size of the program, so it's doing quite a lot! ;)

Cheers, Alan.
 

Ghostbear

Member
Not quite.

The two PWM are generating the signals.

Code:
	pwmout carrierpls, 16, 33 ; 57600Hz at 50% @ 4MHz
	pwmout pwmdiv4, hitpls, 138, 277 ; 1800Hz at 50% @ 4MHz
They are modulated together with an external AND gate.
The resulting modulated signal is fed to another AND gate along with the trigpls to generate the signal that&#8217;s fed to the Mosfet driven IR LED

It&#8217;s the signal generated by the two PWM signals being modulated via an external AND gate I was looking at for now, so ideally, instead of 2 output pins, plus a transistor AND gate, I&#8217;ve just got one output pin that I can turn on/off with the trigpls either internally (ideally) or with a single transistorised AND gate to reduce the number of external components.

If It helps, I can upload the circuit diagram when I get home tonight
 

hippy

Technical Support
Staff member
The two PWM are generating the signals. They are modulated together with an external AND gate.
So, considering just the PWMOUT output, that's -

Code:
#Picaxe 14M2
PwmOut          B.4,  16,  33 ; 57600Hz at 50% @ 4MHz
PwmOut pwmdiv4, B.2, 138, 277 ;  1800Hz at 50% @ 4MHz
Do : Loop
And that gives a continuous stream of pulses on the output of the AND gate which you will see on a scope as -

Code:
___|||||_____|||||_____|||||_____|||||_____
Untested, but if you disconnect what goes to pin C.1 ( because C.1 is the output for DSM on a 14M2 ), run this code, you should see exactly the same coming out on the C.1 pin -

Code:
#Picaxe 14M2
PwmOut          B.4,  16,  33 ; 57600Hz at 50% @ 4MHz
PwmOut pwmdiv4, B.2, 138, 277 ;  1800Hz at 50% @ 4MHz
PokeSfr $FC, %11000000 ; SFR $39C MDCON
PokeSfr $FD, %00000100 ; SFR $39D MDSRC
PokeSfr $FE, %00000000 ; SFR $39E MDCARL
PokeSfr $FF, %00000111 ; SFR $39F MDCARH
Do : Loop
It should be possible to disconnect the outputs for PWMOUT B.2 and B.4 so one or the other can be used for the input which used to be on C.1

Best course would be to try the above, check C.1 outputs the same as the AND, adjust until it does. Then set about making B.2 and B.4 usable as inputs.
 

Ghostbear

Member
So, considering just the PWMOUT output, that's -

Code:
#Picaxe 14M2
PwmOut          B.4,  16,  33 ; 57600Hz at 50% @ 4MHz
PwmOut pwmdiv4, B.2, 138, 277 ;  1800Hz at 50% @ 4MHz
Do : Loop
And that gives a continuous stream of pulses on the output of the AND gate which you will see on a scope as -

Code:
___|||||_____|||||_____|||||_____|||||_____
Untested, but if you disconnect what goes to pin C.1 ( because C.1 is the output for DSM on a 14M2 ), run this code, you should see exactly the same coming out on the C.1 pin -

Code:
#Picaxe 14M2
PwmOut          B.4,  16,  33 ; 57600Hz at 50% @ 4MHz
PwmOut pwmdiv4, B.2, 138, 277 ;  1800Hz at 50% @ 4MHz
PokeSfr $FC, %11000000 ; SFR $39C MDCON
PokeSfr $FD, %00000100 ; SFR $39D MDSRC
PokeSfr $FE, %00000000 ; SFR $39E MDCARL
PokeSfr $FF, %00000111 ; SFR $39F MDCARH
Do : Loop
It should be possible to disconnect the outputs for PWMOUT B.2 and B.4 so one or the other can be used for the input which used to be on C.1

Best course would be to try the above, check C.1 outputs the same as the AND without the AND, adjust until it does. Then set about making B.2 and B.4 usable as inputs.
Cool :) I'll give it a shot this weekend
 

hippy

Technical Support
Staff member
Forgot to say that you won't need the second AND gate for the trigger pulse. That can be handled by adjusting the DSM so it outputs the pulse stream or nothing.
 

Ghostbear

Member
Forgot to say that you won't need the second AND gate for the trigger pulse. That can be handled by adjusting the DSM so it outputs the pulse stream or nothing.
I did wonder if that was an option, but figured I'd go for the whole "suck it & see" experimental approach :)
 

Ghostbear

Member
Hi folks, bit of thread necromancy here.

I’d got this working via the external AND gate quite successfully, but still want to look at getting it to work on the single pin. Question is, and I’ve probably read it several times without it twigg8ng what it is, but how would you disconnect the outputs for B.2 and B.4?

Is it a case of using the DIR command just to st the pin direction?

Is it also possible to use the serout command in place of the 1800hz signal? The reason being I've got a signal that consists of 50ms 1800hz pulse, followed by several bytes of serial data all modulated with the 57.6khz carrier and I can get the thing to modulate internally, but I've not yet been able to a) switch off the B2 & B4 pins to input only or successfully get the serout to work yet
 
Last edited:

hippy

Technical Support
Staff member
Similar to the code in in Post #11, this should take the carrier PWMOUT on B.4, modulated by the PWMOUT on B.2, output that on C.1, while not putting PWM out on either B.2 or B4. Not tested with an actual chip though -

Code:
#Picaxe 14M2
PwmOut          B.4,  16,  33 ; 57600Hz at 50% @ 4MHz
PwmOut pwmdiv4, B.2, 138, 277 ;  1800Hz at 50% @ 4MHz
PokeSfr $FC, %11000000 ; SFR $39C MDCON
PokeSfr $FD, %10000100 ; SFR $39D MDSRC
PokeSfr $FE, %10000111 ; SFR $39E MDCARL
PokeSfr $FF, %00000000 ; SFR $39F MDCARH
Do : Loop
If you want to send some pulse of carrier, then send carrier modulated by serial, you will need to switch the MDSRC between the two ...

PokeSfr $FD, %10000100 ; SFR $39D MDSRC - For PWM

PokeSfr $FD, %10001010 ; SFR $39D MDSRC - For HSEROUT

If you are not using HSEROUT but have SEROUT connected back to the C.0 MDMIN pin then you would need -

PokeSfr $FD, %00000001 ; SFR $39D MDSRC - For MDMIN

You might have to play with the serial polarity to get the signal you desire out or it may be necessary to adjust the MDxxxx registers, might have to swap MDCARL and MDCARH values, maybe adjust other settings.
 
Top