my little lab

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Here's another page with an example you can experiment with if you are so motivated:
http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html

You need to understand just how this thing is going to work before you start writing a program to implement it, otherwise you'll be lost.
Sir! Motivated or Not, I'm going to read errthang it takes to understand how it works!!! I HATE giving up...and I told myself by tomorrow night I must have the motor spinning as I want...then move on...

I have something else I wana work on...

Thx for that link ima read it n try to understand...

You can keep on throwing other links if you think I would need them...

And Sarge I MUST say thanks so much for your guidance!!!:D
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Sarge!!

That link is more about the coding part...
And I'm still struggling with the motor logical or achievement part...
I now have a headack with this...

Can you please send a link that talk about that but I'll still have to read that link too...

You said that well! I first need to understand how this thing work prior to programming...
Or can you tell me what I need to understand first...I can google it or just send links if u have some...

Thx Sir
 

SgtWookie

Joined Jul 17, 2007
22,230
I think it is by setting the CCP1CON bits:CCP1M3 - CCP1M0= 1100.
-s that correct??
No. CCP1CON bits M3 through M0 will need to be either 1101 or 1110.
That way, you get complementary outputs.
With 1100, they are all active-high outputs.
With 1111, they are all active-low outputs.
With 1101, P1A and P1C are active high, P1B and P1D are active low.
With 1110, P1A and P1C are active low, P1B and P1D are active high.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Ohk Sir but pins P1M1:p1M0 = 1 0, right? Since you said we going to use Half bridge configuration...

But about pins DC1B1:DC1B0?? I'm a bit confused on this one! Plus I would appreciate a comment on reply #42

Regards,
 

John P

Joined Oct 14, 2008
2,068
The question of how much safety margin to allow when selecting a component is very much a judgment call. But no, if you've got the ULN2065B it'll be fine and you shouldn't replace it. In my opinion, you've spent more money than you need to, but others may not agree.

Looking at the specs for the PWM output on a PIC16F690 (it's my favorite processor right now, but so far I haven't needed this particular feature) I think 1100 in those bits is actually the right setting. There is only one PWM, but you can send it to any of 4 different outputs. That's the key: you keep one phase on at 100%, and then you ramp up another phase from 0% to 100%. Then you switch to modulating the phase that was at 100% and let it drop to 0%. Then you let another one come up to 100%. It's actually a very clever design to let a minimal processor do something quite sophisticated. (That was based on the idea of microstepping so as to turn the motor slowly, so it's a bit different for moving in steps.) But the main point is the interaction between one phase that's delivering 100% torque and another that's delivering less.

But O please, be realistic. If you're a beginner and you expect to have this working by tomorrow night, it is my sad duty to tell you that you may be expecting too much. Nobody is going to sit by the computer waiting for your questions as you go along with this. And even if someone did--to be honest, I can see more than a day's work here even for someone with experience.

What's your programming environment? Have you got a compiler?
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Thanks John for your reply...I'm a beginner and I'm growing thanks to you all...
Well if you say that it will still take more than a day...it ohk...you know better than me...
You guyz are guiding me towards the solution...so I'm doing as you say...

I'm writing my code in PIC assembly language...hope I answered your question...

Thx again
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I wondered if maybe a day on Mars was a month long for Earthlings, but no, it's only about 24 hours plus half an hour. So I think you'll need more than one day for this. Especially if you're working in assembly language.

http://en.wikipedia.org/wiki/Timekeeping_on_Mars
LMAO....:D

Well do you have an algorithm to sove the problem???

Well if C is faster I'll have to shift to C although I've never used it 4 Hardware programing...

Thx!
 

SgtWookie

Joined Jul 17, 2007
22,230
You have four phase wires on the stepper motor. To keep things simple, let's label them A, B, C and D; they will correspond with P1A, P1B, P1C and P1D.

To simply get the motor to step, you can send a sequence to the port like this:
Rich (BB code):
A B C D Angle
1 0 0 0  0°
0 1 0 0  7.5°
0 0 1 0 15°
0 0 0 1 22.5°
1 0 0 0 30°
...etc.
But, that's not going to work for you, as your stepper motor has 48 steps per revolution, and you need 60 steps/rev.
If you step it as in the above sequence, you will only have the correct angle every 4th step.
To get around this problem, you can use PWM. In the first page I linked to, look at the section entitled:
Single Output PWM Mode
You'll note that the P1M1 and P1M0 bits of CCP1CON need to be cleared (0).
You are also going to use the inverted output feature. That way, you can actually have two PWM outputs that are mirror images of each other (when one is high, the other is low), which is just what you need. This is set with the CCP1CON register; selecting 1101 or 1110. In the below sequence, I'm basically using the 1101 setting.

Now the sequence will look like:
Rich (BB code):
   A   B   C   D  Angle
 100%               0°
  20% 80%           6°
      40% 60%      12°
          60% 40%  18°
  20%         80%  24°
 100%              30°
...etc.
The duty cycle is set to the percentage shown in columns A or C, and the B and D outputs are the remaining duty cycle percent (inverted PWM signal).
For each step, you will need to select the outputs that you wish to use, and load the new PWM% value into the proper register.
 
Last edited:

John P

Joined Oct 14, 2008
2,068
I believe that you need to operate the chip in Single Output, pulse steering mode, as described in section 11.4.7 of the manual. At any given time, you'd be sending the PWM signal out of a pin controlling one phase, while an adjacent phase would be On, and the other two phases would be Off. A special case would be when the PWM duty cycle is 0%, so then there would simply be one phase out of the four On.

So I would say (with "position" being counted in full steps):
Rich (BB code):
 Position        A    B    C    D
 0               100
 .8              20  100
 1.6                  60 100
 2.4                      100  60
 3.2             20            100
 4               100
The 20% and 60% duty cycles are guesses. You'd need to experiment with those in order to get the stopping positions evenly spaced.
 

MMcLaren

Joined Feb 14, 2010
861
Hey Sarge,

Thanks for the info' on the ULN2064B. ST just shipped me a sample yesterday. As for Eric's 7.5° stepper, here's what I came up with for microstepping duty cycle values;

Regards, Mike
 

Attachments

Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
Thanks, Mike - looks like I had the numbers swapped on 12° and 18°. That's what happens when I post when tired. :rolleyes:

I don't expect for the numbers to work perfectly due to inaccuracies in the motor itself, but they should be reasonably close.

As far as the ULN2064/ULN2065 - they're good if you want a very small parts count and a lower Vce than the ULN2003/ULN2803 for a given current, but the power loss in the Vce still bugs me.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Big Thanks to Sarge, John P and Mike for your comments...

i need a few minutes to read them as i just opened it...as i been busy with some other labs

regards,
 

John P

Joined Oct 14, 2008
2,068
I have to admit I needed to sleep on it before I understood how SgtWookie and MMcLaren's scheme driving two outputs at once would work. Yes, by using that active high/low feature and the same PWM on two outputs, it'll work. Though driving just one PWM would work too!

Maybe the right way to control the power isn't with an IC at all, but with 4 FETs. That would be more efficient, but note that you need "logic level FETs" that can be driven by the output of the processor.
 

SgtWookie

Joined Jul 17, 2007
22,230
PWMing one output while keeping another on 100% would work too, and would give a somewhat higher torque output, but that higher torque wouldn't be consistent; it would vary between 1x and 2x the single-step torque. That will make it more problematic to determine what the actual PWM % will be needed to get the required angle offsets.

I'd mentioned using logic level MOSFETs previously; even a link to a suggested one that's compact and fairly inexpensive - but of course, the parts count will be higher.

Anyway, the code basically needs to go like this:


CCP1CON bits M3 through M0 set to 1101; P1A & C are active high, P1B and D are active low.
P1M0 and P1M1 of CCP1CON both set to 0

Step 1:
PWM to 100%
P1A and P1B are output pins, P1C and P1D set to inputs
Wait

Step 2:
PWM to 20%
Wait

Step 3:
PWM to 60%
P1B and P1C are output pins, P1A and P1D set to inputs
Wait

Step 4
P1C and P1D are output pins, P1A and P1B set to inputs
Wait

Step 5:
P1A and P1D are output pins, P1B and P1C set to inputs
PWM to 20%
Wait

Loop back to Step 1:
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
#sweating* I thing I understood Mike's table and Sarge explaination although it was NOT easy...

Given the above information, that means I can try to write a piece of code, right??

Also, step 1 - 5 needs to be repeated 12 times in order to complete one revolution, is that correct???

I'll try writing a piece of code 'initialisation part' ...I can tell ima have have a HARD time writing it...

I'll have to load the PR2 register with a value depending on the PWM frequency, which is what??? Also the PWM duty cycle changes 4 times...so how am I going to deal with that!??

Regards,
 

SgtWookie

Joined Jul 17, 2007
22,230
Do you have some LEDs handy? Might be easier to try a few of those first, and see how it goes.

Yes, steps 1-5 need to be repeated 12 times to get 60 steps; that's if you want to stop after 60 steps. If you want it to continue on, just keep repeating that loop.

As far as the PWM frequency, you can use the utility on this page:
http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html
to get the code to set the PWM frequency and percent.
Try using 500 Hz for starters.

Like I showed above, you are going to have to change the PWM % during various steps.
 

MMcLaren

Joined Feb 14, 2010
861
PWMing one output while keeping another on 100% would work too, and would give a somewhat higher torque output, but that higher torque wouldn't be consistent; it would vary between 1x and 2x the single-step torque. That will make it more problematic to determine what the actual PWM % will be needed to get the required angle offsets.

I'd mentioned using logic level MOSFETs previously; even a link to a suggested one that's compact and fairly inexpensive - but of course, the parts count will be higher.

Anyway, the code basically needs to go like this:


CCP1CON bits M3 through M0 set to 1101; P1A & C are active high, P1B and D are active low.
P1M0 and P1M1 of CCP1CON both set to 0

Step 1:
PWM to 100%
P1A and P1B are output pins, P1C and P1D set to inputs
Wait

Step 2:
PWM to 20%
Wait

Step 3:
PWM to 60%
P1B and P1C are output pins, P1A and P1D set to inputs
Wait

Step 4
P1C and P1D are output pins, P1A and P1B set to inputs
Wait

Step 5:
P1A and P1D are output pins, P1B and P1C set to inputs
PWM to 20%
Wait

Loop back to Step 1:
Exactly! Makes perfect sense since the PWM duty cycle corresponds to the active high portion of the signal on the P1A (coil A) and P1C (coil C) pins...

Use a five (5) element array of "duty cycle" and TRIS values for the five (5) unique 6° steps... Sixty (60) 6° steps gets you 360°. Maintain a "position" variable and increment or decrement it by one, according to a "direction" flag, when you get a new "step" flag. Use "position" modulo 5 as the array index...
 
Last edited:
Top