Author Topic: How to Rotate Stepper Motor in Single step in CW and CCW  (Read 1503 times)

0 Members and 1 Guest are viewing this topic.

Offline muthukural001Topic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: in
How to Rotate Stepper Motor in Single step in CW and CCW
« on: April 19, 2018, 05:21:27 am »
Hello,

Doing a project with Two LDRs which detect light and Solar panel which will be moved to the side of LDR which have More light.I have Stepper Motor that configured in Bipolar mode and having step angle of 7.5 degree.

To rotate the Motor in any one of the LDR direction, the difference between LDR1 and LDR2 should be above 300 Ohms (LDR Resistance decrease as light increases).That Means, if LDR1's resistance less than LDR2's resistance and the difference is above 300 Ohms, Move stepper motor one step in Clockwise direction.If LDR2's resistance less than LDR1's resistance and the difference is above 300 Ohms, Move stepper motor one step in Counter Clockwise direction.I do compare LDR1 and LDR2 value after completing single step either in CW and CCW.

My Stepper Motor code:
0x08
0x04
0x02
0x01
looping the above code for 12 times will give one revolution. 4x7.5 = 30 degree for one iteration So 12x30 = 360 degree.


But I don't know how to use it single step.. Please suggest







 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: How to Rotate Stepper Motor in Single step in CW and CCW
« Reply #1 on: April 19, 2018, 02:44:16 pm »
I don't think I quite understand your 'code', it looks like some kind of bit pattern.  It would seem to me that each transition in the pattern is one step.  Each transition (0x08 to 0x04, for example) should rotate the motor 7.5 degrees.  I guess...

I have never seen a motor that is wired that way.  Not that they don't exist, I just haven't seen one.

How about providing a little more info?  Are you using a microcontroller?  Are you using a driver chip (which)?  Perhaps a schematic?  What kind of electronics makes the 300 ohm measurement?  I haven't thought much about it but that seems hard.

 

Offline muthukural001Topic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: in
Re: How to Rotate Stepper Motor in Single step in CW and CCW
« Reply #2 on: April 23, 2018, 07:07:32 am »
Hi rstofer,

Thanks. I managed to get work it. Actually, 360 degree divided by 7.5 degree is 48.It means that we have to apply 48 pulses to get one revolution. I wrote code like below for Clockwise and Counter Clock Wise.


Code: [Select]
#define TOTAL_STEPS 4
#define STEP_MASK  (TOTAL_STEPS - 1)
static uint8_t Cw_Steps[TOTAL_STEPS] = {0x08,0x04,0x02,0x01};
static uint8_t CCw_Steps[TOTAL_STEPS] = {0x01,0x02,0x04,0x08};
uint8_t CW_Step = 0, CCW_Step = 0;

/*--------------------STEP CLCOKWISE--------------------------------*/
void SingleStep_ClockWise(void)
{
    LATD &= 0xF0;
    LATD |= Cw_Steps[CW_Step & STEP_MASK];
    CW_Step++;
    Start_Timer();
    while(!One_Step_Complete);
    Stop_Timer();
 }
/*--------------------STEP CLCOKWISE--------------------------------*/
void SingleStep_CClockWise(void)
{
    LATD &= 0xF0;
    LATD |= CCw_Steps[CCW_Step & STEP_MASK];
    CCW_Step++;
    Start_Timer();
    while(!One_Step_Complete);
    Stop_Timer();
 }


Set timer to 333ms to get rpm of 4.



Thanks,
Muthu
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf