Marc72
Newbie level 1
Hello
I m trying to turn my stepper motor with a pic16F877A + l297 + l298 with this code but what i get at PORTC.2 is the led blinking
and the motor is not turning so i affect the 4 output of the motor into some LED to see the signal but the 4 LED are taking the same signal like the clock,
thanks for your help
--------------------------------
void main()
{
unsigned char dc ;
TRISC = 0 ; // set PORTC as output
PORTC = 0 ; // clear PORTC
/*
* configure CCP module as 4000 Hz PWM output
*/
PR2 = 0x0F ; //7c
T2CON = 0b00000101 ;
CCP1CON = 0b00001100 ; //CCPR1L
CCP2CON = 0b00111100 ; // FF
PORTC.B1=1; //Enable
PORTC.B3=1; //CW
for(; // forever
{
/*
* PWM resolution is 10 bits
* don't use last 2 less significant bits CCPxCON,
* so only CCPRxL have to be touched to change duty cycle
*/
for(dc = 0 ; dc < 128 ; dc++)
{
CCPR1L = dc ;
CCPR2L = 128 - dc ;
Delay_ms(1) ;
}
for(dc = 127 ; dc > 0 ; dc--)
{
CCPR1L = dc ;
CCPR2L = 128 - dc ;
Delay_ms(1) ;
}
}
}
--------------------------------
I m trying to turn my stepper motor with a pic16F877A + l297 + l298 with this code but what i get at PORTC.2 is the led blinking
and the motor is not turning so i affect the 4 output of the motor into some LED to see the signal but the 4 LED are taking the same signal like the clock,
thanks for your help
--------------------------------
void main()
{
unsigned char dc ;
TRISC = 0 ; // set PORTC as output
PORTC = 0 ; // clear PORTC
/*
* configure CCP module as 4000 Hz PWM output
*/
PR2 = 0x0F ; //7c
T2CON = 0b00000101 ;
CCP1CON = 0b00001100 ; //CCPR1L
CCP2CON = 0b00111100 ; // FF
PORTC.B1=1; //Enable
PORTC.B3=1; //CW
for(; // forever
{
/*
* PWM resolution is 10 bits
* don't use last 2 less significant bits CCPxCON,
* so only CCPRxL have to be touched to change duty cycle
*/
for(dc = 0 ; dc < 128 ; dc++)
{
CCPR1L = dc ;
CCPR2L = 128 - dc ;
Delay_ms(1) ;
}
for(dc = 127 ; dc > 0 ; dc--)
{
CCPR1L = dc ;
CCPR2L = 128 - dc ;
Delay_ms(1) ;
}
}
}
--------------------------------