Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:03 11 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PWM command hates me...

     Page 1 of 2    
Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 10:24pm 14 Jul 2014
Copy link to clipboard 
Print this post

Not having much fun here - PWM command does not seem to want to ramp-up and ramp-down a test motor, connected via a PWM H-Bridge motor driver.

Here is the test code:


'PWM tester for 44-pin MicroMite
'11/07/2014

SetPin 2,DOUT
SetPin 1,dout

Pin(2)=1:Pin(1)=0

Print "Ramping up..."
For x=20000 To 100000 Step 100
PWM 1,x,50:Pause 10
Pin(2)=1
Next
Print "Ramping down..."
For x=100000 To 20000 Step -100
Pin(2)=1
PWM 1,x,50:Pause 10
Next
End


This is on a 44-pin MicroMite module.(from WW)

When power is connected, motor just runs forward at full speed no matter what the MM code is doing.

Any ideas?

Attached is the PDF for the 6221 H-Bridge controller - I am using PWM control mode B.

2014-07-15_082344_BD6221F-E2_H-Bridge18v_SOP8.pdf Edited by Grogster 2014-07-16
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 10:53pm 14 Jul 2014
Copy link to clipboard 
Print this post

Opps - I think I have the wrong I/O pins - I am using physical pin1 on the WW 44 module, which I don't think is PWM controller #1....

...testing....

EDIT: Yes, I was on the wrong I/O pin, I needed to be on pin 21(for the 44's)

I am getting speed up and speed down now, but still not the range I was hoping for, which is fully-off to full-speed, and full-speed to fully-off.

Tinkering continues.Edited by Grogster 2014-07-16
Smoke makes things work. When the smoke gets out, it stops!
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 10:54pm 14 Jul 2014
Copy link to clipboard 
Print this post

Try leaving the frequency constant and adjust the PMW instead

PWM 1, 20000, 5 ' 5% PMW
Pause 1000
PMW 1, 20000, 60 ' 60% PMW

Jman
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 11:00pm 14 Jul 2014
Copy link to clipboard 
Print this post

Ahhhhh - cheers - will test.
I might be using the command wrong.......

@ jman - you are onto something there - if I vary the last paremeter, the motor slows up!!!

Tink, tink, tink......Edited by Grogster 2014-07-16
Smoke makes things work. When the smoke gets out, it stops!
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 11:11pm 14 Jul 2014
Copy link to clipboard 
Print this post

Hey Groggy,
you not on the plonk again?
Bob
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 11:20pm 14 Jul 2014
Copy link to clipboard 
Print this post

THANKS JMAN - You were RIGHT on the money there!!!!!!

New code:


'PWM tester for 44-pin MicroMite
'11/07/2014

SetPin 2,DOUT
SetPin 1,dout

Pin(2)=1:Pin(1)=0

Print "Ramping up..."
For x=100 To 0 Step -1
PWM 1,20000,x:Pause 50
Pin(2)=1
Next
Print "FULL SPEED!"
Pause 2500
Print "Ramping down..."
For x=0 To 100
Pin(2)=1
PWM 1,20000,x:Pause 50
Next
End


This code ramps up the motor to full speed, then ramps it back down again. This is zero-to-full-speed, then full-speed-to-zero.

Works wonderfully - thanks.

Out of interest, what was I doing wrong?
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 11:21pm 14 Jul 2014
Copy link to clipboard 
Print this post

  BobD said   Hey Groggy,
you not on the plonk again?
Bob


HAHAHA!!!!!

Nope, not tonight, as I feel very embarrassed about that last thread!!!
Smoke makes things work. When the smoke gets out, it stops!
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 936
Posted: 12:29am 15 Jul 2014
Copy link to clipboard 
Print this post

Hi Grogster,

you have only changed the frequency, not the duty-cycle with your code.

The frequency says how often your motor is switched on and of in a second but the duty-cycle says how long the motor is on or off in each cycle and thats make the speed.
A higher frequency makes a smoother behavior of the motor but should not change the speed...
Take a look to:PWM

Frank
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6220
Posted: 12:33pm 15 Jul 2014
Copy link to clipboard 
Print this post

The controller chip has a minimum PWM frequency of 20kHz
  Quote  The PWM frequency can be input in the range between 20kHz and 100kHz. Note that control may not be attained by switching on duty at frequencies lower than 20kHz, since the operation functions via the stand-by mode. Also,circuit operation may not respond correctly when the input signal is higher than 100kHz. T


Your motor is likely to have a preferred frequency. You can usually adjust the frequency to get a 'hum free' motor which runs cool.
Hopefully, that preferred frequency is within the range of the controller.

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 01:32pm 15 Jul 2014
Copy link to clipboard 
Print this post

Thanks guys - I obviously was using the command wrong, and thanks to Frank for the clarification - useful information for me.

The motor I am using is a gearbox motor, so extremely accurate RPM is not important for me, it is the ramp-up and ramp-down. I also plan to use the brake mode of the PWM controller, by setting both inputs high - this locks the motor.

It is all tinkering towards my model elevator project, and this is the motor control for the cabin/counterweight hoist motor.

I gave up last night before I got myself in another mess, but later tonight, I plan to add to the test code, so that the motor ramps up and ramps down forward, then ramps up and ramps down in reverse. This is done just by applying the PWM to the 2nd input, and the 1st one I was using - it is held high instead.

SHOULD be painless enough, now that I am using the command correctly!

Thanks everyone, and I will post back.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 08:01pm 15 Jul 2014
Copy link to clipboard 
Print this post

UPDATE - It is working fine in reverse now, once I worked out a couple of bugs in the way I was driving things.....


'PWM tester for 44-pin MicroMite
'11/07/2014



Print "Ramping up..."
For x=100 To 0 Step -1
PWM 1,25000,x,100:Pause 50
Next
Print "FULL SPEED!"
Pause 2500
Print "Ramping down..."
For x=0 To 100
PWM 1,25000,x,100:Pause 50
Next
Print "Stopped."

Pause 2500

Print "Now trying reverse - Ramping up..."
For x=100 To 0 Step -1
PWM 1,25000,100,x:Pause 50
Next
Print "FULL SPEED!"
Pause 2500
Print "Ramping down..."
For x=0 To 100
PWM 1,25000,100,x:Pause 50
Next
Print "Stopped - Test ended."
End


Smoke makes things work. When the smoke gets out, it stops!
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 10:53am 27 Jul 2014
Copy link to clipboard 
Print this post

Hey Grogster !
Now that you're a pwm-miester :
Are there 4 separate pwm channels ?
(both frequency and duty cycle independent)
or 2 ?
Seems I remember someone saying 4, but now,
looking at the manual it says 2 ????????
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:38am 27 Jul 2014
Copy link to clipboard 
Print this post

  hitsware said   Hey Grogster !
Now that you're a pwm-miester :
Are there 4 separate pwm channels ?
(both frequency and duty cycle independent)
or 2 ?
Seems I remember someone saying 4, but now,
looking at the manual it says 2 ????????



So my understanding is 5 outputs
Consisting of 2 separate channels
Outputs on channel 1x have the same frequency but can have independent ratios
Outputs on channel 2x have the same frequency but can have independent ratios

Regards
Jman
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 01:37pm 27 Jul 2014
Copy link to clipboard 
Print this post

Agreed. Sorry I missed your post yesterday, hitsware - I was fully involved in the networking hell thread, and constant playing around there to see if I could get that working. The PWM motor control has been shoved to the side of the desk, once I had the concept working!

Too many things I want to play with on the uM and MM, and not enough flippin' hours in the day!!!
Smoke makes things work. When the smoke gets out, it stops!
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 04:17pm 27 Jul 2014
Copy link to clipboard 
Print this post

  jman said  
  hitsware said   Hey Grogster !
Now that you're a pwm-miester :
Are there 4 separate pwm channels ?
(both frequency and duty cycle independent)
or 2 ?
Seems I remember someone saying 4, but now,
looking at the manual it says 2 ????????



So my understanding is 5 outputs
Consisting of 2 separate channels
Outputs on channel 1x have the same frequency but can have independent ratios
Outputs on channel 2x have the same frequency but can have independent ratios

Regards
Jman


How many 'hardware timers' on that 28 pin model ?
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 04:41pm 29 Jul 2014
Copy link to clipboard 
Print this post

What the world needs is PWMPAL in the MicroMite !

https://solarbotics.com/download.php?file=722Edited by hitsware 2014-07-31
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9488
Posted: 04:57pm 29 Jul 2014
Copy link to clipboard 
Print this post

Clickable link HERE

EDIT: You could always get one of those and hook it to the uM... Edited by Grogster 2014-07-31
Smoke makes things work. When the smoke gets out, it stops!
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 05:14pm 29 Jul 2014
Copy link to clipboard 
Print this post

I've got one .

The only weakness (for my purpose)
is the range of frequency ...

If it had an 'external clk'
rather than it's xtal that'd
do it !
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6220
Posted: 05:18pm 29 Jul 2014
Copy link to clipboard 
Print this post

The price is a bit steep compared to the micromite.
I might be interested if it had 32 bit counters instead of 16 bit.

Jim
VK7JH
MMedit
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 06:41pm 29 Jul 2014
Copy link to clipboard 
Print this post

> if it had 32 bit counters instead of 16 bit

right.....then enough range from xtal
how many hardware counters in the
MaxiMite chip ?
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025