Bug in PIC_stepper.c ?

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
f6exb
Flowcode V4 User
Posts: 2
Joined: Tue Mar 13, 2012 8:23 pm
Contact:

Bug in PIC_stepper.c ?

Post 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*/
}
Seuls les faucons volent.
Les vrais restent au sol.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Bug in PIC_stepper.c ?

Post 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.

f6exb
Flowcode V4 User
Posts: 2
Joined: Tue Mar 13, 2012 8:23 pm
Contact:

Re: Bug in PIC_stepper.c ?

Post 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.
Seuls les faucons volent.
Les vrais restent au sol.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Bug in PIC_stepper.c ?

Post 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.

Post Reply