Ultrasonic affecting PWMout frequency

lxlramlxl

New Member
I'm using an 18M2 chip which allows the PWMout option instead of using a 555 timer to get a 36khz frequency.
But when observing the frequency being outputted by the chip when the ultrasonic becomes active I noticed it changes.
which then loses detection of my infrared.

Is there any way around this?
 

hippy

Ex-Staff (retired)
Operating speeds can fall back to 4MHz to suit the command being executed and this can affect PWMOUT but there should be no change if already at 4MHz.

It is not clear what you mean by "when the ultrasonic becomes active"; some further details and your source code may help clarify things.
 

lxlramlxl

New Member
Code:
'Infrared Transmitter
pwmout B.3, 26, 53
pwmout B.6, 26, 53
'Infrared Reciever
if pinB.5 = 0 then goto Cutpower
if pinB.4 = 0 then goto Cutpower

'Ultrasonic
symbol trig = B.1 			; Define pin for Trigger & Echo (All M2, X2 parts)
symbol range = w1 			; 16 bit word variable for range

main:	pulsout trig,2 			; produce 20uS trigger pulse (must be minimum of 10uS)
	pulsin trig,1,range 		; measures the range in 10uS steps
	pause 20			; recharge period after ranging completes

	; now convert range to cm (divide by 14.8) or inches (divide by 5.8)
	; as picaxe cannot use 14.8, multiply by 10 then divide by 148 instead

	let range = range * 10 / 148	; multiply by 10 then divide by 58
	debug range			; display range via debug command
	goto Start			; and around forever

	; Note that X2 parts operate at 8MHz instead of 4MHz and so modify the calculation
	; let range = range * 10 / 58 / 2 ; multiply by 10 then divide by 58 then divide by 2
That's the bit of code that matters I guess.

The LEDS are currently at around 37kHz which is fine as they need to be 36-38kHz.
The only thing I can think of is the Pulse of the ultrasonic changing the frequency, just don't know why.

Parts:
Ultrasonic: http://www.picaxestore.com/index.php/en_gb/srf005.html
Infrared LED: http://www.picaxestore.com/index.php/en_gb/led023.html
Sensor: http://www.picaxestore.com/index.php/en_gb/led020.html
 

hippy

Ex-Staff (retired)
Thanks for the code details. There is nothing I could immediately see which should be causing a change of operating frequency which would affect PWMOUT.

It might be worth trying without the ultrasound module connected to see if that is the cause - the code should still run even though it will give incorrect readings.
 

Technical

Technical Support
Staff member
If 'start' is at the top of your program you are continuously resetting the pwm with two new pwmout commands every single loop.
This is not what you want - set them once at the top of the program and then never process the pwmout command again.
 

lxlramlxl

New Member
If 'start' is at the top of your program you are continuously resetting the pwm with two new pwmout commands every single loop.
This is not what you want - set them once at the top of the program and then never process the pwmout command again.
You're absolutely correct and this has indeed solved the problem with the pwmout.

I'm still unsure what chip I am using to drive the stepper motor. I have only two control pins as the other two are always high.
So would I be correct in saying that to control it this way I would use the following;
Code:
Step	wire 1	wire 2
1	low	high
2	high	high
3	high	low
4	low	low
 
Top