nick703
Advanced Member level 1
- Joined
- Oct 17, 2011
- Messages
- 422
- Helped
- 21
- Reputation
- 44
- Reaction score
- 22
- Trophy points
- 1,298
- Location
- surat
- Activity points
- 3,987
Hello friends i have a implement code to rotate stepper motor using Encoder .
and complete working as reverse and forward stepper motor using encoder below code.
My micro controller is PIC32MX575F256H.
Encoder pin is RE6 AND RE7.
Below code is working perfectly.
now my question is when i use PORTG pin RG2 AND RG3 . That time i changed above code to below code
but my stepper motor only rotate one direaction is that pin issue of PIC32MX575F256H ?
OR please give me solution how to resolve this thing to rotate stepper motor in both direaction.
please help me.
and complete working as reverse and forward stepper motor using encoder below code.
My micro controller is PIC32MX575F256H.
Encoder pin is RE6 AND RE7.
Below code is working perfectly.
Code:
char old = 0;
void Encoder(void)
{
int new = 0 ;
int value = 0 ;
new = PORTE ; //// encoder pin here PORTE PIN 6 ,PIN7
value = new ^ old ;
if (value & 0x40)
{
if(new & 0x40)
{
mStepper_B_Enb(); // STEPPER ENABLE
if(new & 0x80)
{
mStepper_B_For(); // STEPPER FORWARD
mStepper_B_Fourth();
}
else
{
mStepper_B_Rev(); // STEPPER REVERSE
mStepper_B_Fourth();
}
mStepper_B_Off();
Delay_us(25);
mStepper_B_On(); // STEPPER ON
}
}
old = new ;
return ;
}
main()
{
while(1)
{
Encoder();
}
}
now my question is when i use PORTG pin RG2 AND RG3 . That time i changed above code to below code
Code:
char old = 0;
void Encoder(void)
{
int new = 0 ;
int value = 0 ;
new = PORTG ; //// encoder pin here PORTG PIN 2 ,PIN3
value = new ^ old ;
if (value & 0x04)
{
if(new & 0x04)
{
mStepper_B_Enb(); // STEPPER ENABLE
if(new & 0x08)
{
mStepper_B_For(); // STEPPER FORWARD
mStepper_B_Fourth();
}
else
{
mStepper_B_Rev(); // STEPPER REVERSE
mStepper_B_Fourth();
}
mStepper_B_Off();
Delay_us(25);
mStepper_B_On(); // STEPPER ON
}
}
old = new ;
return ;
}
main()
{
while(1)
{
Encoder();
}
}
but my stepper motor only rotate one direaction is that pin issue of PIC32MX575F256H ?
OR please give me solution how to resolve this thing to rotate stepper motor in both direaction.
please help me.