CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Microstepping with 16F877A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
blueprint



Joined: 21 Jun 2011
Posts: 12

View user's profile Send private message

Microstepping with 16F877A
PostPosted: Tue Aug 09, 2011 5:59 am     Reply with quote

Hello Dear All,

I have a unipolar 5V stepper motor and I want to drive it with a 16f877a.
I have connected 2 pieces of tc4427 mosfet drivers and 4 pieces of IRF2807 to the pic and, as I see they are working properly.

I supply 50V to the motor and I am trying to use microstepping techniques. Because the motor is 5V, pwm output of the pic never exceeds 10%.

My schema is same with the schema in this document (http://ww1.microchip.com/downloads/en/AppNotes/00907a.pdf page 19, figure 23) (plus mosfet drivers).

My problem is that, I can only drive the motor very slowly. When I trying to increase the speed, motor is just vibrating.

Here is my some code parts:
Code:
int msTable[] = {0, 2, 4, 6, 7, 8, 9, 10, 8, 6, 4, 3, 2, 1}; //Microstepping look up table


Code:
setup_timer_2(T2_DIV_BY_1,101,1); //49.02 khz


Code:
void takeStep(unsigned int16 stepCount){
   static int iCcp1 = 7;
   static int iCcp2 = 0;
   static unsigned int16 i;
   static int1 swCcp1 = true;
   static int1 swCcp2 = true;
   
   for(i = 0; i < stepCount; i++){
     
      set_pwm1_duty(msTable[iCcp1++]);
      if(swCcp1) output_high(PIN_CCP1_SW); else output_low(PIN_CCP1_SW);
      set_pwm2_duty(msTable[iCcp2++]);
      if(swCcp2) output_high(PIN_CCP2_SW); else output_low(PIN_CCP2_SW);
     
      if(iCcp1 > MAX_MS_TABLE_INDEX){
         iCcp1 = 0;
         swCcp1 = !swCcp1;
      } else if(iCcp2 > MAX_MS_TABLE_INDEX){
         iCcp2 = 0;
         swCcp2 = !swCcp2;
      }
     
      delay_us(1000);
   }
   
}


I am regulating speed by changing the sleep time. Sleep time 1000 and above works fine(but very slowly). When I decrease it, motor is starting to vibrate.

Please help me :/


Last edited by blueprint on Tue Aug 09, 2011 6:56 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9115
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 6:21 am     Reply with quote

You don't give any details about the motor(mfr/model) let alone the specs so why do you think it can run at 49KHz ?

Replace the motor with an appropriate resistor and see with a 'scope' what happens.

This test will also confirm that your driver electronics are working correctly.
blueprint



Joined: 21 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 6:54 am     Reply with quote

Thank you for your answer temtronic.

Here is some details of the motor:

3A, 1,66ohm, 7.5mH, nema 24, unipolar. Unfortunately I don't have any more details.

I did some research on the internet and learnt that 20 - 50khz is good to do it. Is it wrong?

I will check the circuit with a resistor as you said and report the last situation.
blueprint



Joined: 21 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 7:01 am     Reply with quote

I have just checked the circuit with a oscilloscope. It works fine at high and low speed.
Ttelmah



Joined: 11 Mar 2010
Posts: 19229

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 7:07 am     Reply with quote

Probably.....
You need to distinguish the PWM frequency (used to modulate the current in the coils), from the 'step rate' (rate at which the phases of the motor are moved). 20-50KHz, is fine for the PWM frequency, but not the step rate.

Generally, unipolar motors, though the easiest to drive, also have the lowest useable step rates. Pulling the data sheet for a very similar motor, first line reads:
"This drive is only suitable for applications where low speeds and low torques are required". Then the torque curves, give 'max pull in speed' (the rate at which you can start stepping the motor), at 1000Hz - no load, and the torque versus speed curve reaches zero at just over 4Khz, with full torque only being achieved up to about 500Hz.

Best Wishes
blueprint



Joined: 21 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 7:38 am     Reply with quote

Thank you for the answer Ttelmah.

But, this motor runs very slowly (approximately 50-60 rpm), I can not believe that this is the speed limit of a unipolar stepper motor?
Ttelmah



Joined: 11 Mar 2010
Posts: 19229

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 8:02 am     Reply with quote

How many steps/rev is the motor?.
You get types with everything from 1.8degree, to perhaps 30degrees. At 1.8 degrees/step, you have 200steps/rev. At 500Hz step rate, this gives about 150RPM. So 50-60RPM, is slow, but only a little. To get full speed, the current modulation needs to change as you move. Remember that when you start to step the motor, each phase is on for less and less time, so the actual PWM 'on' period needs to rise, or the current falls. This is what is happening with your code, and why you are well below the best speeds available.

Best Wishes
blueprint



Joined: 21 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 9:40 am     Reply with quote

Step angle of the motor is 1.8 degree.
Dear Ttelmah, would you please clarify your last post? Do you think that, my problem is with my code? So, how can I fix the problem?
Ttelmah



Joined: 11 Mar 2010
Posts: 19229

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 9:57 am     Reply with quote

Not without getting a lot more complex, and adding a lot more hardware.
You would need to actually sense the current flowing in the motor coil, and modulate the PWM, to regulate this to the required level for your microstep. When you start moving, the current will then be on for a larger proportion of the time.
This is what microstepping control chips do, Having an internal sine table, and using this to control a comparator controlling the PWM. It is probably not 'doable' in software without a lot more speed from the chip.

Best Wishes
blueprint



Joined: 21 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 09, 2011 10:03 am     Reply with quote

Thank you very much Ttelmah!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group