Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:56 02 Aug 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

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 10:55pm 27 Jan 2019
Copy link to clipboard 
Print this post

I want to control an AC 2 wire motor that uses very little current, microamps from a Pic
I have successfully done this by having it connected to 2 pins and doing the following
PIN(7) = 1
PIN(8) = 0
pause 75
PIN(7) = 0
PIN(8)= 1
pause 75

I've been told it will work better if controlled using PWM and it can be done from the micromite but despite reading everything I can about PWM and reading the manual I cannot get my head around how it works

Is it possible to do with? and any suggestions how?

it's a clock motor and it has to get a positive pulse, pause and then a negative pulse for the same period as the positive pulse to move one step

 
BrianP
Senior Member

Joined: 30/03/2017
Location: Australia
Posts: 292
Posted: 05:17am 28 Jan 2019
Copy link to clipboard 
Print this post

Hi Lew

I think your present method is probably the better - PWM has a smooth average output useful for continuously varying motor speed for more conventional motor types. Your clock motor speed is controlled by the frequency of the pulses you send it. So it's behaving like a stepper motor (sort of)...

What is the origin of this motor? It sounds like a battery operated clock motor (1.5 volt).

Also, in what way does it need to work better?

Cheers

BEdited by BrianP 2019-01-29
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 05:41am 28 Jan 2019
Copy link to clipboard 
Print this post

G'Day.

It could be done using a PWM signal to drive something like a 74HC74 flip flop to give a bipolar signal. Then your micro would have an easier life but at the expense of extra hardware.

Peter
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 11:07am 28 Jan 2019
Copy link to clipboard 
Print this post

Hi,

I think this should work. I've used the NOT command to change pin states before on the 'Mites.
PIN(7) will change state every call of SETTICK & PIN(8) will be set to the opposite state of pin(7)

Using SETTICK frees up the 'Mite for other stuff.


SETTICK 75, Clock_pulse, 1

SUB Clock_Pulse
PIN(7) = NOT PIN(7) 'change the state of pin(7)
PIN(8) = NOT PIN(7) 'set PIN(8) to opposite of pin(7)
END SUB


Brian
ChopperP
 
LadyN

Guru

Joined: 26/01/2019
Location: United States
Posts: 408
Posted: 10:13pm 28 Jan 2019
Copy link to clipboard 
Print this post

OK.

Before you proceed figure out which PWM frequency your DC motor gives the highest torque at.

Design the HBridge/switch around that PWM frequency.

My first PIC18 controlled HBridge worked great in simulation until I built it on a board and it was able to barely turn the DC motor because it worked at 100kHz.

I had to get it down to 17kHz for it to give the highest torque so it could be regulated properly with DC 3% - 90%.

EDIT: I noticed you use an AC motor. No experience with those. Keeping this post around for use later, hope it's ok.Edited by LadyN 2019-01-30
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:34am 29 Jan 2019
Copy link to clipboard 
Print this post

  LadyN said  
EDIT: I noticed you use an AC motor. No experience with those. Keeping this post around for use later, hope it's ok.


Sorry I actually made a mistake
it's actually a DC motor, it's a single phase stepping motor that needs a positive pulse to move one step then a negative to move the next step and so on

It is a watch motor*
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 08:45am 29 Jan 2019
Copy link to clipboard 
Print this post

I think you should think of this motor as an AC motor. It is excited by a positive voltage followed by a negative voltage i.e. a simple A.C. waveform although, in modern digital systems, sinusoidal waveforms are being replaced by steps.
The 2 options you have been given should do what you want without loading up the micro.
Good luck.

Peter
 
LadyN

Guru

Joined: 26/01/2019
Location: United States
Posts: 408
Posted: 08:10pm 29 Jan 2019
Copy link to clipboard 
Print this post

  lew247 said  
  LadyN said  
it's actually a DC motor, it's a single phase stepping motor that needs a positive pulse to move one step then a negative to move the next step and so on


Do you have a link to the datasheet?

I dont believe you will be successful using PWM to control a phase stepping motor as it works off phase diff. versus signal amplitude

You might even have to use microstepping but we will need to look at the datasheet first
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 10:26pm 29 Jan 2019
Copy link to clipboard 
Print this post

I'll bet my boots it's a reluctance motor.

Peter
 
BrianP
Senior Member

Joined: 30/03/2017
Location: Australia
Posts: 292
Posted: 11:16pm 29 Jan 2019
Copy link to clipboard 
Print this post

Lew - out of curiosity what are you wanting to do with this motor? If it's a watch motor as you say then it will have VERY limited torque.

As it draws microamps (or even milliamps) it's not likely to strain your Micromite unduly especially as the outputs are only pulsed.

I still think your original method of driving it is the best method (refer my earlier post).

B
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 11:33pm 29 Jan 2019
Copy link to clipboard 
Print this post

In simple terms,
Lew is replacing the control board on an analogue clock with a more accurate time source. He plans to have it auto correct with power failures and auto adjust for daylight saving.

Jim

VK7JH
MMedit
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 11:36pm 29 Jan 2019
Copy link to clipboard 
Print this post

G'Day GrianP

His method works but the micro spends a lot of time doing delays etc. If he wants to do other things he may run into timing problems.
My method (ahem) is the best (ahem ehem) because PWM runs in the background and does not interfere with the micro but it does mean extra hardware.
So it comes down to what is required.
I hope I'm correct in saying that it is a reluctance motor.

Peter

Edit
You sneaked one in there Jim.
How do you know that?
It looks like there will be quite some processing to speed up the motor to correct time
after it has been derived, GPS?
But it does sound like fun.

PEdited by PeterB 2019-01-31
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:03am 30 Jan 2019
Copy link to clipboard 
Print this post

  PeterB said  
You sneaked one in there Jim.
How do you know that?
It looks like there will be quite some processing to speed up the motor to correct time
after it has been derived, GPS?
But it does sound like fun.

P

Lew asked me to help him with the 47L04 EEPROM chip
https://www.thebackshed.com/forum/forum_posts.asp?TID=11033&PN=2
He told me why.

I don't think I have a suitable clock module but I must have a rummage in the shed...

Jim
VK7JH
MMedit
 
BrianP
Senior Member

Joined: 30/03/2017
Location: Australia
Posts: 292
Posted: 12:54am 30 Jan 2019
Copy link to clipboard 
Print this post

@PeterB - good point (which is why I asked what the intended use was).

Would not he be better off then using PULSE instead of PWM? The pulse subroutine could be called from a 1 second interrupt, which shouldn't upset any existing program.

Any correction necessary could be either to add an extra pulse occasionally or to turn off pulsing momentarily if needed to slow down.

All the clock motors I have ever seen as Lew has described work on alternate polarity 1 second pulses, although there are some than run a lot faster to provide a smooth (continuous) operation of the second hand. Either way the pulse method should be able to cope?

Anyway just my 2c worth...

B

 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 01:14am 30 Jan 2019
Copy link to clipboard 
Print this post

Yep. I think we need England to wake up.
C'mon Lew, wake up!

Peter
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 07:39am 30 Jan 2019
Copy link to clipboard 
Print this post

Sorry
The time difference is annoying at times, and I am jealous of your weather down under
it's snowing here now

It's an analog clock that I'm running from a Pi Zero W and I've made a slight change in the Pi code to get proper NTP time from my local NTP timeservers every 15 minutes so the time is always exact without any fancy code in the MM

The issue I had was moving the hands properly, the motor moves 1 pulse (second) by applying a positive voltage pausing then a negative voltage to move the next second

It was driving me potty because it was moving 2 seconds for every real second
until I realised that I was actually telling it to do exactly that - stupid mistake!

It's working perfectly now and I've had it running for a few days with no errors

Thanks Brian for your "NOT" idea, it actually reading that when I realised that I was telling the code to move 2 seconds for every real second.

I've designed the board so it also has a temp sensor and a connection for an E-Ink display to display the Day and Date and temperature (but doesn't have to be used)

The board below shows a button to move the hands manually if you ever need to but I've removed it in the final PCB

I'm using an Sram that HAS to be set to "00000" when the board is first powered up, and then the clock code loaded
Move the hands manually using the wheel on the back of most clock modules or moving the minute hand only to 12:00:00
Power up and it will start ticking fast till it catches up with the current time and then once per second

If there is a power cut then the Sram writes to it's internal Eeprom and this is the position of the hands in seconds.

Once power is reapplied, this figures is transferred back to the Sram, read and then the hands will move fast until it catches back up to the correct time.

I haven't worked on the E-Ink code yet as I blew my first display by using 5V when the maximum voltage is 4V
Hopefully I'll be able to get it working tomorrow when I'm off work next

The board fits perfectly on top of a Pi Zero W and is a tiny bit wider to allow the pinouts for the E-Ink to be shown

It also has a "heartbeat" LED so you can see it working

I've used a 2.54mm pinout for the DS18B20 so it can be mounted off the board and anywhere on the clock away from any heat



The reset button isn't really needed but it's there in case someone really messes up the hands while the clock is running, it will reset the Pi totally, the power can then be removed, the Sram written with "00000" again and then the MM code loaded after moving the hands to 12:00:00 again

Once I'm happy it all works ok and no issues, I'm going to use a different chip such as ATTINY85V-10SH with an Esp8266 or possibly a receiver to pick up the MSF/DCF/Wghatever radio signal

This would allow it to be run from an "AA" for at least a year or more, or even a "C" for a few years

The other option is once Matherp is happy with his Armite L4 code to use that with a receiver which although won't be such low power as the other chip, it should still allow the clock to run for a very long time on battery

And the E-Ink display can always show the battery voltage as well if wanted so it will be easy to see when it needs changing
Edited by lew247 2019-01-31
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 08:37am 30 Jan 2019
Copy link to clipboard 
Print this post

Don't apologize and don't be too jealous of our weather. 38C today, 47.5 last week but 28 tomorrow. Palcal has been talking about something called rain???. I have no idea what he is talking about.
So all your problems are solved?

Peter
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025