Picaxe 18x pwm cutting out

cl10Greg

New Member
Hello,
We are using a picaxe 18x for pwm control of a varying motor and are having problems. The pwm duty cycle is varied based on the analog input from a NI DAQ card. The pulse works fine and shows up great on the scope, the problem is when we are trying to run the motor. The PWM kicks on for about 3 seconds and then the pulses stops for about (like an overload) and then kicks back on. We are running the pwm at 10K and runs to a H-bridge. We used a transistor to clean it up a bit but still the same problem occurs. Here is the code:
Code:
init:
	let b1 = 0
	let w0= 0
main:
	gosub checkVoltage
	if pin1 = 1 then
			gosub dynamicPWM
			pwmout 3 , 249, w0
	elseif pin1 = 0 then goto shutOff
	end if
	goto main	
shutOff:
	pwmout 3,off
	goto main
checkVoltage:
	readadc 0,b1
	return
dynamicPWM:
	if b1 <= 225 then
		let w0 = b1*4
	elseif b1 > 250 then
		let w0 = 1000
	endif
	
	return
 

Andrew Cowan

Senior Member
Could the PICAXE be resetting/unstable due to noise? Assuming it is not getting to the 'Shutoff' routine, have you got decoupling/smoothing capacitors around the PICAXE?

A
 

Dippy

Moderator
Sounds like poor power supply, or ,as Andrew alludes to, noise.

Post your circuit precisley. What is the power supply. Tell us the current rating of the motor. Describe the H bridge.
In addition to PSU/decoupling noise issues, bad PCB practice/design can cause problems like this too.
How is it all connected? PCB, stripboard, breadboard?
 

MartinM57

Moderator
Stick a

sertxd ("...started", CR, LF)

at the start to see if the whole PICAXE is resetting.

Or a LED+R on a spare output and at the start

high n 'n = pin number
pause 1000
low n

...and see if the LED lights at the same time as it cuts out...
 

MartinM57

Moderator
..also it's advised to only issue a pwmout when you change the duty cycle as there will be a discontinuity in the output waveform - I doubt your motor will notice in thsis case though.

So protect your pwmout with a check to see if w0 is the same as last time - you'll need to use another variable to store "last time round w0"
 

eclectic

Moderator
@Greg.
There's a conflict, with
b1 and w0.

Add these two lines to your first program,
and watch what happens.

Code:
dynamicPWM:
sertxd (#b1,"  ") ;*********
	if b1 <= 225 then
		let w0 = b1*4
	elseif b1 > 250 then
		let w0 = 1000
	endif
	sertxd (#b1,cr,lf) ;*******
	return
Then please try this program
Code:
#picaxe 18X

init:
	let b2 = 0 ;*****************************
	let w0= 0
main:
	gosub checkVoltage
	if pin1 = 1 then
			gosub dynamicPWM
			pwmout 3 , 249, w0
	elseif pin1 = 0 then goto shutOff
	end if
	goto main	
shutOff:
	pwmout 3,off
	goto main
checkVoltage:
	readadc 0,b2            ;*********
	return
	
dynamicPWM:
sertxd (#b2," ")
	Let w0 = b2 *4 MAX 1000
sertxd (#b2,cr,lf)
	return
It seems to be working OK here.
e
 

cl10Greg

New Member
ok, so hooked up an led for the init case to see if the chip is completely resetting and as suspected it is resetting. But the motor turns off and then there is a 2 second delay and the init case runs so i dunno what is doing between these points. We are using a 4.5 v wall wart. The h bridge is SN754410. We are trying the decouple methods right now. Can you help me with the save last w0 code? I am not sure where how to accomplish this. The motor current rating is about 1 amp at stall.

Ill try to post the schematic shortly
 

cl10Greg

New Member
thanks for all the responses. Have a weird issue though. So if we start the motor at a 60% duty cycle at first and increase it, there is no problem even up to 100%. The motor works perfectly.If we try to start the motor at 80% duty cycle though it has the same problem of the chip resetting. Any ideas on this one or a code idea to start it at initially smaller then move it up from reading the analog or any other ideas? The motor is working better but we are using it for a spring like constant to provide torque feedback on a knob. Any ideas or suggestions on this?
 

cl10Greg

New Member
yes, i switched the variables and that is what made me reach my new results of the motor continuously working if we start the duty cycle low and increase. But do you have any idea why there would be such a problem with starting the chip at a higher duty cycle or why swiftly increasing the analog input gives us a problem?
 

MartinM57

Moderator
last_w0 implementation - not that I think it's too relevant in this case - and with some structure simplifications (untested - but with ec's post #6 corrections using b4 instead)

Code:
symbol last_w0 = w1

init:
	let b4 = 0
	let w0= 0
        sertxd ("...started", CR, LF)
main:
	if pin1 = 0 then goto shutOff
	readadc 0,b4
	gosub dynamicPWM
	if last_w0 = w0 then goto main			
	last_w0 = w0 
	pwmout 3 , 249, w0
	goto main	

shutOff:
	pwmout 3,off
	goto main
		
dynamicPWM:
	if b4 <= 225 then
		let w0 = b1*4
	elseif b4 > 250 then
		let w0 = 1000
	endif
	
	return
 

eclectic

Moderator
@Greg.
I'm using an 18X, on an AXE091 board.
Input 0 connected to a 10k pot.
Input 1 connected via 10k to ground. Switch to V+

Output 3 to a ULN2003 to a small motor.

The program (from post #6)

Code:
#picaxe 18X

init:
	let b2 = 0 ;*****************************
	let w0= 0
main:
	gosub checkVoltage
	if pin1 = 1 then
			gosub dynamicPWM
			pwmout 3 , 249, w0
	elseif pin1 = 0 then goto shutOff
	end if
	goto main	
shutOff:
	pwmout 3,off
	goto main
checkVoltage:
	readadc 0,b2            ;*********
	return
	
dynamicPWM:
sertxd (#b2," ")
	Let w0 = b2 *4 MAX 1000
sertxd (#b2,cr,lf)
	return
It's working fine,
whichever Pot. Position it starts from.

The only way to stop it is
the switch on Input 1

ec
 

MartinM57

Moderator
yes, i switched the variables and that is what made me reach my new results of the motor continuously working if we start the duty cycle low and increase. But do you have any idea why there would be such a problem with starting the chip at a higher duty cycle or why swiftly increasing the analog input gives us a problem?
...because one or more of:
- your power supply is not powerful enough
- you don't have separation of the motor wiring and the PICAXE power supply wiring

...so the extra power taken at high duty cycles or at a rapidly increasing duty cycle is collapsing the supply to the PICAXE.

Probably ;)
 

hippy

Ex-Staff (retired)
@ cl10Greg : Could you clarify exactly what the fault now is as it stands - Is it an identified reset problem which we don't yet know the cause of or is it not resetting and the problem is something else ?
 

cl10Greg

New Member
Thanks again for all the fast and great responses to start with.

The main problem is when we have the motor at stall, which is what we want for torque feedback, the PIC stops pulsing after about three seconds. It will start again once the stall is let go but the problem is the resetting at stall. We are trying diodes to stop the motor and the h-bridge from drawing current and power away from the PIC. the PIC and the H-bridge are sharing the 4.5V power supply and the motor has a separate 12 volts.
 
Top