int cnt = 127; //init - pwm cycle
void main() {
TRISB = 0xFF; // B is input
TRISC = 0X00; // C is output
PORTC = 0x00; // Init - C=0
TRISD=0x00; // D is output
PORTD=0x40; // D.f6=1 (motor turns clockwise)
ADCON1 = 0x7F; // all pins digital
INTCON = 0xD0; // gie i int enabled
OPTION_REG = 0x00;
PWM1_Init(5000); // pwm freq = 5000hz
PWM1_Set_Duty(cnt);
PWM1_Start();
while (1)
{
}
}
void interrupt (void)
{
if (INTCON.INTF)
{
//motor changes direction on each interrupt:
PORTD.f7=~PORTD.f7; // D.f7=1 (motor turns clockwise);
PORTD.f6=~PORTD.f6; // D.f6=1 (motor turns counterclockwise)
PORTD.f0=~PORTD.f0; // LED on D.f1 changes state on each interrupt
INTCON.INTF = 0; // reset int flag
}
}
//motor changes direction on each interrupt:
PORTD.f7=~PORTD.f7; // D.f7=1 (motor turns clockwise);
PORTD.f6=~PORTD.f6; // D.f6=1 (motor turns counterclockwise)
The next thing i was going to do was to try to use the other port of the L298, like you said. I don't know exactly how they work, but maybe the port B is damaged, but port A remained intact. A shot in the dark indeed.
I do not have an oscilloscope and i cannot see the pwm signal on RC2, but when i measure with the multimeter it gives me readings compatible with the duty cycle i set. (2.5V for 127/255 Duty Cycle).
The current rating of my motor is 1.2A according to the datasheet. Although the motor is rated for 27V +/-2,7 i am inputting 12V in the L298 Vs pin (pin 4). I figured that this will not affect the motor or the L298 badly at all, since it's well below the nominal voltage. Am i correct or this is my problem and i have blown the L298.
Thanks again Willis
int cnt = 127; //init - pwm cycle
void main() {
TRISB = 0xFF; // B is input
TRISC = 0X00; // C is output
PORTC = 0x00; // Init - C=0
TRISD=0x00; // D is output
PORTD=0x40; // D.f6=1 (motor turns clockwise)
ADCON1 = 0x7F; // all pins digital
INTCON = 0xD0; // gie i int enabled
OPTION_REG = 0x00;
PWM1_Init(5000); // pwm freq = 5000hz
PWM1_Set_Duty(cnt);
PWM1_Start();
while (1)
{
}
}
void interrupt (void)
{
if (INTCON.INTF)
{
//motor changes direction on each interrupt:
PORTD.f7=~PORTD.f7; // D.f7=1 (motor turns clockwise);
PORTD.f0=~PORTD.f0; // LED on D.f1 changes state on each interrupt
INTCON.INTF = 0; // reset int flag
}
}
int cnt = 127; //init - pwm cycle
void interrupt (void) {
if (INTCON.INTF)
{
//motor changes direction on each interrupt:
PORTD.f7 = ~PORTD.f7; // D.f7=1 (motor turns clockwise);
PORTD.f6 = ~PORTD.f6; // D.f6=1 (motor turns counterclockwise)
Delay_ms(20);
PORTD.f0 = ~ PORTD.f0;
PORTD.f1 = ~ PORTD.f1; // LED on D.f1 changes state on each interrupt
INTCON.INTF = 0;
} // reset int flag
}
void main() {
TRISB = 0xFF; // B is input
TRISC = 0X00; // C is output
PORTC = 0x00; // Init - C=0
TRISD=0x00; // D is output
PORTD=0x40; // D.f6=1 (motor turns clockwise)
ADCON1 = 0x7F; // all pins digital
INTCON = 0xD0; // gie i int enabled
OPTION_REG = 0x00;
PWM1_Init(5000); // pwm freq = 5000hz
PWM1_Set_Duty(cnt);
PWM1_Start();
while(1) {
}
}
Sorry for not responding immediately.
I was waiting to buy a new L298 IC and once i did i hooked it up ( i was fearing that the first one was blown). As soon as i hooked it up and then turned the power on i first tried to see if it was getting too hot. It wasn't getting hot at all. I also checked the PIC to see if it was getting hot and it was okay too.
Next, i tried to measure the voltage on the OUT1 pin. I rearranged my code a tiny bit, so that every time i hit the RB0 pin (external interrupt) the PWM duty cycle changes for a quarter upwards until it hits maximum and then resets to zero. So the PWM duty cycle starts with 0-->64-->128-->192-->255-->0... etc. I also removed the part of the code that changed the direction of the motor on each interrupt. Now the direction stays the same all the time. I measured the voltage and it is 5V on one and 0V on the other pin.
I measured the voltage on both the PWM pin on the PIC and the OUT1 pin of the L298. Here's what i got for the respective duty cycle values:
DC PIC OUT1
0-------0V-------0.15V
64------0.99V----4.22V
128-----1.99V----7.09V
192-----2.99V----9.95V
255-----3.99V----11.8V
The Vs of the L298 is set on 12V.
But whatever the outputs were, the motor wasn't turning at all.
I also have an LED hooked up through a resistor on the PWM pin on the PIC and it works perfectly, meaning the light intensity changes according to the PWM duty cycle.
I really do not know what is wrong.
I appreciate your help.
I would like to try another approach and see if this works. The L298 has the capability four 3 different drive states: 1 motor in low power mode, 2 motors in low power mode, or 1 motor in high power mode. Since we are having trouble driving the motor in low power mode, let us see if we can get the motor to move by driving it in high power mode.
1. Connect Enable A and Enable B together. This should still be the main enable signal coming from the uC.
2. Tie In 1 and In 4 together. this is your direction signal.
3. Tie In 2 and In 3 together. this is your direction ' signal.
4. Tie Out 1 and Out 4 together. This is your motor +.
5. Tie Out 2 and Out 3 together. This is your motor -.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?