Dc motor speed control

arg733

Senior Member
I am in SHOCK!
We actually have some DATA for a change.......im still recovering from the shock.............

Ok. it looks that you have a lot of electrical noise on the 5v supply, this might be coming from the motor, or just poor power filtering on you circuit.
This is causing the ADC value to jump around and the ADC should be very steady.
Are you 100% sure you have the pulsin pin and the ADC pin the correct way around in the program?
What happens when you adjust the pot, the ADC reading on screen should change.
you mean from the motor that is in another part of the city or the motor of the fridge? :D
 

SAborn

Senior Member
Is this circuit not driving a motor?
It is the motor you built and have in this circuit i was referring to causing noise.
 

arg733

Senior Member
So how are you testing the code if its not the actual circuit operating
i am using 2 frequency generators instead of 1 and a hall and i am measuring the picaxe's output with a frequency counter. So basically very accurate test.
 

SAborn

Senior Member
No its NOT.
It is outputting 5Khz and adjusting the dutycycle within the 5Khz, so the frequency stays the same, just the duty changes, this is a more mormal way to control the motor rather than frequency shift.

There is no way to know how the code will work until there is feedback from the motor with the hall sensor, at this point how do we know what pulsin is without a pulse the read.
 

arg733

Senior Member
No its NOT.
It is outputting 5Khz and adjusting the dutycycle within the 5Khz, so the frequency stays the same, just the duty changes, this is a more mormal way to control the motor rather than frequency shift.

There is no way to know how the code will work until there is feedback from the motor with the hall sensor, at this point how do we know what pulsin is without a pulse the read.
yep i have no way to measure the duty cycle so i don't know if its working that's why i use frequency and not duty
 

arg733

Senior Member
No its NOT.
It is outputting 5Khz and adjusting the dutycycle within the 5Khz, so the frequency stays the same, just the duty changes, this is a more mormal way to control the motor rather than frequency shift.

There is no way to know how the code will work until there is feedback from the motor with the hall sensor, at this point how do we know what pulsin is without a pulse the read.
it IS reading a pulse (from my function generator at 90hz to 100hz = 5.4 - 6KRPMs)
 

arg733

Senior Member
i also tried to use pwmout instead of pwmduty and it behaves very strangely it jumps back and forth.
 

SAborn

Senior Member
I dont know how you would calculate in program the PWM frequency and maintain a steady duty cycle, because if you change either one will effect the motor speed or torque.

You could do something like 1000 hz steps, but that might be a little erradic.
 

arg733

Senior Member
I dont know how you would calculate in program the PWM frequency and maintain a steady duty cycle, because if you change either one will effect the motor speed or torque.

You could do something like 1000 hz steps, but that might be a little erradic.
nope it steps very nice about 50hz could you make a code to monitor the variables for this code ?

Code:
Symbol speed = w0
Symbol demand = w1
Symbol Frequency = w2

main:
pulsin 4, 1, speed
pulsin 3, 1, demand
if speed > demand then
frequency = frequency + 1
else frequency = frequency - 1
endif
let frequency = frequency min 54 max 200
pwmout 2, frequency, 20
pause 900
goto main
 

SAborn

Senior Member
try
Code:
#picaxe 08m2
 #terminal 4800

 w2= 100
 
pwmout C.2,w2,20

Main:
	readadc10 C.1, w3
	w3 =w3 * 64

	pulsin c.4, 1, w1

	if w1 >= 1  then
	w1 = 65535/ w1 
	endif
	
	if w1 > w3 and w2 > 1then 
	w2 = w2-1
	pwmout C.2,w2,20

	endif
	
	
	if w1 < w3 and w2 < 1023 then 
	w2 = w2+1
	pwmout C.2,w2,20

	endif
	sertxd ("Pulsin = ",#w1, 13,10)
             sertxd ("ADC = ", #w3, 13,10)
             sertxd ("Duty = ", #w2, 13,10)

             goto main
remember to change the pin numbers
 

arg733

Senior Member
try
Code:
#picaxe 08m2
 #terminal 4800

 w2= 100
 
pwmout C.2,w2,20

Main:
	readadc10 C.1, w3
	w3 =w3 * 64

	pulsin c.4, 1, w1

	if w1 >= 1  then
	w1 = 65535/ w1 
	endif
	
	if w1 > w3 and w2 > 1then 
	w2 = w2-1
	pwmout C.2,w2,20

	endif
	
	
	if w1 < w3 and w2 < 1023 then 
	w2 = w2+1
	pwmout C.2,w2,20

	endif
	sertxd ("Pulsin = ",#w1, 13,10)
             sertxd ("ADC = ", #w3, 13,10)
             sertxd ("Duty = ", #w2, 13,10)

             goto main
remember to change the pin numbers

nope if adc > 200 frequency increases infinitively and adc is lower than 200 then the frequency decreases infinitively

pin numbers are all ok
 

hippy

Ex-Staff (retired)
I think it's time to step back as it's all getting too confusing and going round in circles.

Forget the physical hardware, forget how speed and desired are read or determined, let's create a program that can be simulated ...

Code:
#Picaxe 08M2

Symbol speed     = w0
Symbol desired   = w1
Symbol frequency = w2

Do
  SerRxd #speed, #desired
  If speed > desired Then
    frequency = frequency + 1
  Else
    frequency = frequency - 1
  End If
  frequency = frequency Min 54 Max 200
  SerTxd( "Frequency=", # frequency, CR, LF) ; space between # and frequency is needed
  PwmOut 2, frequency, 20
Loop
Don't worry about the fact we are using SERRXD, not COUNT or PULSIN, that's simply to make simulation easier, allows the numbers you want to use easier to enter.

When that code is simulated one enters a speed and what's desired. For example 0,100 and perhaps 10,100 the next and so on as speed increases. Watch what Frequency does in the serial output simulation display.

It doesn't do as expected because of that bug which I've already pointed out. So try this ...

Code:
#Picaxe 08M2

Symbol speed     = w0
Symbol desired   = w1
Symbol frequency = w2

Do
  SerRxd #speed, #desired
  If speed > desired Then
    frequency = frequency + 1 Max 200
  Else
    frequency = frequency Min 55 - 1
  End If
  SerTxd( "Frequency=", # frequency, CR, LF)
  PwmOut 2, frequency, 20
Loop
 

arg733

Senior Member
this works:

Code:
#picaxe 08m2
 #terminal 4800

 

Main:
	readadc10 C.1, w3
	w3 =w3 * 10

	pulsin c.4, 1, w1
	
	if w3 < w1 then
	w2 = w2 + 1
	else w2 = w2 - 1
	endif

	let w2 = w2 min 54 max 200
	
	pwmout 2,w2,200
	

             goto main
 

SAborn

Senior Member
Maybe???
It will be a different matter in real life when its controlling the motor.
Just because it works for your simulation and to what you want to see, dont mean it will work in the circuit correctly.

Your next step is to rewrite the code with symbols etc and show me how you can do that.
 

Goeytex

Senior Member
@Arg733,

Please tell me two things ....

1. What is the part number for the Hall Switch you are using on the actual motor?

2. Since you are not really using a motor ( it's across town) you must be using a signal generator as the input for pulsin. What is the duty cycle of this signal?
 

arg733

Senior Member
I think it's time to step back as it's all getting too confusing and going round in circles.

Forget the physical hardware, forget how speed and desired are read or determined, let's create a program that can be simulated ...

Code:
#Picaxe 08M2

Symbol speed     = w0
Symbol desired   = w1
Symbol frequency = w2

Do
  SerRxd #speed, #desired
  If speed > desired Then
    frequency = frequency + 1
  Else
    frequency = frequency - 1
  End If
  frequency = frequency Min 54 Max 200
  SerTxd( "Frequency=", # frequency, CR, LF) ; space between # and frequency is needed
  PwmOut 2, frequency, 20
Loop
Don't worry about the fact we are using SERRXD, not COUNT or PULSIN, that's simply to make simulation easier, allows the numbers you want to use easier to enter.

When that code is simulated one enters a speed and what's desired. For example 0,100 and perhaps 10,100 the next and so on as speed increases. Watch what Frequency does in the serial output simulation display.

It doesn't do as expected because of that bug which I've already pointed out. So try this ...

Code:
#Picaxe 08M2

Symbol speed     = w0
Symbol desired   = w1
Symbol frequency = w2

Do
  SerRxd #speed, #desired
  If speed > desired Then
    frequency = frequency + 1 Max 200
  Else
    frequency = frequency Min 55 - 1
  End If
  SerTxd( "Frequency=", # frequency, CR, LF)
  PwmOut 2, frequency, 20
Loop
your second code doesn't work whatever i enter eg. 120,100 or 150,300 it shows frequency = 54
 

arg733

Senior Member
Maybe???
It will be a different matter in real life when its controlling the motor.
Just because it works for your simulation and to what you want to see, dont mean it will work in the circuit correctly.

Your next step is to rewrite the code with symbols etc and show me how you can do that.
Code:
#picaxe 08m2
 #terminal 4800

Symbol demand = w3
Symbol speed = w1
symbol frequency = w2
 

Main:
	readadc10 C.1, demand
	demand =demand * 10

	pulsin c.4, 1, speed
		
	if demand < speed then
	frequency = frequency + 1
	else frequency = frequency - 1
	endif

	let frequency = frequency min 54 max 200
	
	pwmout 2,frequency,200
	

             goto main
 

arg733

Senior Member
@Arg733,

Please tell me two things ....

1. What is the part number for the Hall Switch you are using on the actual motor?

2. Since you are not really using a motor ( it's across town) you must be using a signal generator as the input for pulsin. What is the duty cycle of this signal?
1.I am amplifying the signal with an irf9540
2Yes. Duty is anything I set it at from 1-99% i have been working with 50%
 

arg733

Senior Member
Maybe???
It will be a different matter in real life when its controlling the motor.
Just because it works for your simulation and to what you want to see, dont mean it will work in the circuit correctly.

Your next step is to rewrite the code with symbols etc and show me how you can do that.
It most certainly does as i know that if i give more than 10khz to my motor it will slow down (I done it manually with my frequency generator.)
 

Goeytex

Senior Member
I asked you for the part number for the hall switch. Do you even have a hall switch, or are you blowing smoke ?

Why can't you answer a straight question with a straight answer ?
 

arg733

Senior Member
Don't get me wrong i will try ALL the codes that have been posted here (most certainly tomorrow) on the actual motor even those that i think may not work.
 

SAborn

Senior Member
I will leave you in the good help of the other members.
Good luck with your project and i hope it works for you.
 

arg733

Senior Member
OK thanks for your help, you are the most helpful person in this post.


I will post the results.
 
Last edited:

arg733

Senior Member
I asked you for the part number for the hall switch. Do you even have a hall switch, or are you blowing smoke ?

Why can't you answer a straight question with a straight answer ?

the hall's switch doesn't really matters as the picaxe gets pulses from the mosfet
 

Goeytex

Senior Member
the hall's switch doesn't really matters as the picaxe gets pulses from the mosfet
You do not understand basic electronics. Every component matters. The hall switch matters because if you you have it connected wrong ( AND YOU DO) it wont work properly. The circuit diagram you posted is bogus and will not work. Trying to work with you is like trying to work with a 10 year old kid who thinks he knows it all.

If you want help here you need to answer the questions that folks ask and not worry about whether or not you think it matters. It obviously matters to them, or they wouldn't be asking the question. YOU are the one asking for help here. No one here owes you anything. Folks have gone out of their way to help you here. The least you can to is be honest and provide the information required to help you. If you won't do that the the help will disappear as you will soon see.
 

arg733

Senior Member
You do not understand basic electronics. Every component matters. The hall switch matters because if you you have it connected wrong ( AND YOU DO) it wont work properly. The circuit diagram you posted is bogus and will not work. Trying to work with you is like trying to work with a 10 year old kid who thinks he knows it all.

If you want help here you need to answer the questions that folks ask and not worry about whether or not you think it matters. It obviously matters to them, or they wouldn't be asking the question. YOU are the one asking for help here. No one here owes you anything. Folks have gone out of their way to help you here. The least you can to is be honest and provide the information required to help you. If you won't do that the the help will disappear as you will soon see.
1.I am a 16yo kid but i obviously don't think i know everything or i wouldn't had asked for help...
2.I stated many times that my English is not perfect...
3.I didn't give the specification of the hall because i knew that it would make it even more confusing...
4.I have it wired correctly as the datasheet suggests pin1=5v pin2=gnd pin3=out...
5.My circuits work very fine and needs no change as i can control my motor and alter the rpm very precisely why i asked help is because i have NO IDEA in programming and i believe i have given all the needed details. There is ABSOLUTELY NO DIFFERENCE if i have a hall sensor that gives 5v pulses to the picaxe directly, or if i have hall that gives pulses to a fet which gives 5v pulses to the picaxe. In both cases the pulse that the picaxe gets is completely identical.The only thing that matters is that the picaxe gets 5v pulses of 75-100Hz and 5v pulses from a frequency generator at 83hz. Why do you need the specifications of the hall which IS NOT WIRED DIRECTLY WITH THE PICAXE??? if you had asked what are the specifications of my computer's motherboard and cpu it would had made more sence.

Lastly i realize that the people on the forum that have provided me a solution (and for that i thank them) loose time from their own problem(s) to help newbies like me.
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
your second code doesn't work whatever i enter eg. 120,100 or 150,300 it shows frequency = 54
Apologies for that; partly an issue with simulation that will be rectified in due course, and this should overcome it and fix a bug.

Repeatedly entering 105,100 ( speed, desired ), will see frequency increase while the speed is greater than desired.

If you enter take the frequency and alter the speed value you are entering depending on that ( as your real hardware would ) then you will see what frequency will do.

105,100 -> 54
104,100 -> 55
103,100 -> 56 etc

Code:
#Picaxe 08M2

Symbol speed     = w0
Symbol desired   = w1
Symbol frequency = w2

Do
  SerRxd speed, desired
  If speed > desired Then
    frequency = frequency + 1 Min 54 Max 200
  Else
    frequency = frequency Min 55 - 1
  End If
  SerTxd( "Frequency=", # frequency, CR, LF)
  PwmOut 2, frequency, 20
Loop
 

arg733

Senior Member
Apologies for that; partly an issue with simulation that will be rectified in due course, and this should overcome it and fix a bug.

Repeatedly entering 105,100 ( speed, desired ), will see frequency increase while the speed is greater than desired.

If you enter take the frequency and alter the speed value you are entering depending on that ( as your real hardware would ) then you will see what frequency will do.

105,100 -> 54
104,100 -> 55
103,100 -> 56 etc

Code:
#Picaxe 08M2

Symbol speed     = w0
Symbol desired   = w1
Symbol frequency = w2

Do
  SerRxd speed, desired
  If speed > desired Then
    frequency = frequency + 1 Min 54 Max 200
  Else
    frequency = frequency Min 55 - 1
  End If
  SerTxd( "Frequency=", # frequency, CR, LF)
  PwmOut 2, frequency, 20
Loop
No need to apologize I'm the one who should apologize for any misunderstanding i have caused and the lack of information.
It works!
Thanks!
I will try it with the physical hardware now
 
Last edited:

arg733

Senior Member
OK that works:
but for some reason the serial terminal opens when i program it.

Code:
Symbol speed     = w0
Symbol desired   = w1
Symbol frequency = w2

main:
  pulsin 4, 1, desired
  pulsin 3, 1, speed
  If speed > desired Then
    frequency = frequency + 1 Min 54 Max 200
  Else
    frequency = frequency Min 55 - 1
  End If
  
  PwmOut 2, frequency, 20
  
  goto main
 
Top