Page 1 of 1

Bug in PIC_stepper.c ?

Posted: Wed Apr 11, 2012 9:48 pm
by f6exb
Hello,

I'm using FlowCode V4.5 with EB006 board.

I could not run a stepper motor using the macro component, even with enablemotor and disablemotor instructions.
The animation, was runing fine.
Looking at the code PIC_stepper.c, final instructions "#endif" of / * Macro_EnableMotor_Start * / and / * Macro_DisableMotor_Start * / seem misplaced.
I have relocated it just after the "#else "(I was too lazy to remove it" and now the stepper is running:

Code: Select all

:
[code]
/*Macro_EnableMotor_Start*/

#ifdef MX_MIAC_SYSTEM
.
.
.
   #else
  #endif <==========
	%q_enabled = 1;
	clear_bit(MX_%q_TRIS1, MX_%q_PIN1);
	clear_bit(MX_%q_PORT1, MX_%q_PIN1);
	clear_bit(MX_%q_TRIS2, MX_%q_PIN2);
	clear_bit(MX_%q_PORT2, MX_%q_PIN2);
	clear_bit(MX_%q_TRIS3, MX_%q_PIN3);
	clear_bit(MX_%q_PORT3, MX_%q_PIN3);
	clear_bit(MX_%q_TRIS4, MX_%q_PIN4);
	clear_bit(MX_%q_PORT4, MX_%q_PIN4);

/*Macro_EnableMotor_End*/
}

Code: Select all

/*Macro_DisableMotor_Start*/

#ifdef MX_MIAC_SYSTEM
.
.
.
.
.
.
  #else
  #endif <=========
	%q_enabled = 0;
	set_bit(MX_%q_TRIS1, MX_%q_PIN1);
	clear_bit(MX_%q_PORT1, MX_%q_PIN1);
	set_bit(MX_%q_TRIS2, MX_%q_PIN2);
	clear_bit(MX_%q_PORT2, MX_%q_PIN2);
	set_bit(MX_%q_TRIS3, MX_%q_PIN3);
	clear_bit(MX_%q_PORT3, MX_%q_PIN3);
	set_bit(MX_%q_TRIS4, MX_%q_PIN4);
	clear_bit(MX_%q_PORT4, MX_%q_PIN4);
  
/*Macro_DisableMotor_End*/
}

Re: Bug in PIC_stepper.c ?

Posted: Thu Apr 12, 2012 9:37 am
by Benj
Hello,

That's odd the code looks to be correct and is known to work well.

I wonder if you have "MX_MIAC_SYSTEM" defined anywhere in your program which is causing the issue.

Re: Bug in PIC_stepper.c ?

Posted: Thu Apr 12, 2012 1:18 pm
by f6exb
No, I don't use MIAC system and "MX_MIAC_SYSTEM" is not defined at all.
I have only EB006, EB022 and Flowcode 4.5
Without the mod, I couldn't get the stepper running.

It seems to me that if I don't use MIAC, instructions :

Code: Select all

clear_bit(MX_%q_TRIS1, MX_%q_PIN1);
   clear_bit(MX_%q_PORT1, MX_%q_PIN1);
   clear_bit(MX_%q_TRIS2, MX_%q_PIN2);
   clear_bit(MX_%q_PORT2, MX_%q_PIN2);
   clear_bit(MX_%q_TRIS3, MX_%q_PIN3);
   clear_bit(MX_%q_PORT3, MX_%q_PIN3);
   clear_bit(MX_%q_TRIS4, MX_%q_PIN4);
   clear_bit(MX_%q_PORT4, MX_%q_PIN4);
must be outside of the
#ifdef MX_MIAC_SYSTEM

#endif

but I am a noob at Flowcode.

Re: Bug in PIC_stepper.c ?

Posted: Thu Apr 12, 2012 4:44 pm
by Benj
Hello,

I think the code should look like this.

Code: Select all

#ifdef MX_MIAC_SYSTEM
  MIAC CODE
#else
  Standard CODE
#endif
Where as you now have.

Code: Select all

#ifdef MX_MIAC_SYSTEM
  MIAC CODE
#else
#endif
  Standard CODE
Wonder why it was not working for you as normal, glad you got it working though.