Motion board initialization

Forum related to the FLEX boards

Moderator: paolo.gai

Locked
luduvigo
Newbie
Posts: 3
Joined: Fri Sep 23, 2011 3:33 pm

Motion board initialization

Post by luduvigo » Fri Sep 23, 2011 3:43 pm

Hi,
I have at the moment no experience in microcontroller programming but I'm trying to start in doing something.
I'm trying to use a Motion Board to move a little machine, but I'm not able to use the motor 2.

I used a little demo that a friend provided me but I'm not able to move the motor 2 that is connected to RD6_PIN83. Ichecked the code and I wanted to ask if using this function:

Code: Select all

__INLINE__ void __ALWAYS_INLINE__  init_motorPWM(EE_UINT16 pwm_ptcon,
		EE_UINT16 pwm_pwmcon1, EE_UINT16 pwm_pwmcon2, EE_UINT16 usperiod,
		EE_UINT16 pwm_sevtcmp)
{

	/* Check if the ADC is initialized */
	if (EE_motorPWM_init != 0) return;


	PTCON   = pwm_ptcon;
	PWMCON1 = pwm_pwmcon1;
	PWMCON2 = pwm_pwmcon2;
	PTPER   = us2ticks(usperiod);
    SEVTCMP = pwm_sevtcmp;

	/* init the enable pins for the H bridge */
    TRISDbits.TRISD6 = 0; /* motor M2 enable pin */
    TRISDbits.TRISD7 = 0; /* motor M1 enable pin */

    EE_motorPWM_init = 1;
}

the problem can be here, when it's called the function:

init_motorPWM(0x000C, 0x0011, 0x0, MOTOR_PWM_USPERIOD, 0x0 );

I think that maybe I have to pass another value but all the CON values from the datasheet I find are not working.

luduvigo
Newbie
Posts: 3
Joined: Fri Sep 23, 2011 3:33 pm

Re: Motion board initialization

Post by luduvigo » Mon Sep 26, 2011 1:01 pm

The problem was not the initialization, but I don't understand why I'm not able to put to 1 the bit RD6.
If I put that bit to 1 the voltage for the motor 2 remains the same.

erikadds
Newbie
Posts: 45
Joined: Wed May 12, 2010 9:41 am

Re: Motion board initialization

Post by erikadds » Mon Sep 26, 2011 2:22 pm

Hi,
if you want to change the output of the pin RD6, you can use these instructions:
LATDbits.LATD6 = 1; // to enable the bridge
LATDbits.LATD6 = 0 // to disable the bridge

See ee_flex_motionboard.h and ee_flex_motionboard.c for further info about the use of pwm (sections labeled with __USE_DCM_PWM__).

Regards,
Dario

luduvigo
Newbie
Posts: 3
Joined: Fri Sep 23, 2011 3:33 pm

Re: Motion board initialization

Post by luduvigo » Mon Sep 26, 2011 3:45 pm

Sorry, I did not give a complete explaination.

The problem is that I'm not able to set the RD6 bit to 1 with
LATDbits.LATD6 = 1;
but I'm able to set the RD7 with
LATDbits.LATD7 = 1;

The result is that only motor1 works.
That seems to me quite strange also because I changed the software and the board and the problem is still the same.

erikadds
Newbie
Posts: 45
Joined: Wed May 12, 2010 9:41 am

Re: Motion board initialization

Post by erikadds » Mon Sep 26, 2011 4:46 pm

With MPLAB debugger it is possible to stop the simulation/execution and watch the value of the registers.
Watch the value of the TRISD register, and check if the RD6 bit is 0 (output).
Then, if RD6 is an output pin, check if there is an instruction in your code that clear the RD6 bit.
If the code seems to be ok, try to execute the instruction
LATDbits.LATD6 = 1
in a loop (at least 10 times).
If the output pin remains to 0 on different boards, it is not an hw problem, then you have to repeat the sw check.

Dario

Locked