Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

using PIC16F877 together with L293D

Status
Not open for further replies.

oTaRu

Junior Member level 2
Joined
May 21, 2009
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,473
l293d

Hi all,

I having a problem using the PIC16F877 to enable/disable L293D IC chip for enabling and disabling the DC motor.

I am using PORTD of PIC16F877 to control the enable pin 1 of L293D but it's seem not controlling at all.

here is the code:

//Define compiler error message.
#ifndef __CPU_16F877__
#error "This program is tailored for PIC16F877 controller"
#endif

//Include required header files here.
#include "io16f877.h" //the hardware register definition file.



/****************************************************************
The variable timer_value holds the count between two consecutive timer interrupts.
This is the desired time (sec) between interrupts divided by
the time period of each timer count.
E.g. in this program, TIMER1 is configured so that each count = 1.6 uS,
so timer_value of 60000 will give an interrupt period of 96 mS.
****************************************************************/
//int timer_value=0xEA60; //decimal 60000.


/**********************************************************************
Declare functions to be used in the main program, i.e.
void DelayUs(int count)
void initialize_IO_ports(void)
void wait()

**********************************************************************/
//Put the body of all these functions here, before isr() and main().

void DelayUs(int count)
{
int i;
int j;
for(i=0;i<count;i++)
{
for(j=0;j<5000000;j++);

//This for loop has 5 NOPs & wastes 1 uS for our PIC clock frequency of 20MHz.
}
}


void wait()
{
char i;

for(i=0;i<100;i++)
{
RD1 = 0;
DelayUs(100);
}
}




void initialize_IO_ports(void)
{
//set the digital IO ports as per requirement.
TRISB = 0xFF ; //portB as input.
TRISD = 0x00 ; //portD as output.

//clear the output ports at the beginning.
PORTD = 0x00 ; //clear portD.
}


void main()
{
//setup port D as output


while(1)
{

RD1=1;
wait();

//Stop
RD1=0;
wait();
}
}
 

l293d enable

actually i only need output pin as I need the PIC16F7877 to be able to have internal time control then when time is up, the output port will be off... So I believe the TRISB input can be ignored.
 

l293d pic

I might be wrong but I think that your problem is with delay loop


void DelayUs(int count)
{
int i;
int j;
for(i=0;i<count;i++)
{
for(j=0;j<5000000;j++);

//This for loop has 5 NOPs & wastes 1 uS for our PIC clock frequency of 20MHz.
}
}

j<5000000 is always true for 8bit mcu


Regards
 

pic16f877 have output pins

Kaleborg said:
I might be wrong but I think that your problem is with delay loop


void DelayUs(int count)
{
int i;
int j;
for(i=0;i<count;i++)
{
for(j=0;j<5000000;j++);

//This for loop has 5 NOPs & wastes 1 uS for our PIC clock frequency of 20MHz.
}
}

j<5000000 is always true for 8bit mcu


Regards

So what value should I use? What is your recommendation?

thanks!
 

pic16f87 disable adcon1

Well I think that the value you entered is way to big. It's 8 bit platform so value cant be bigger than 255. You said that:
I am using PORTD of PIC16F877 to control the enable pin 1 of L293D but it's seem not controlling at all.
I think that the problem is that your program can not get out of that delay loop.
for(j=0;j<5000000;j++);

Instead of 5000000 try put in 255.

Regards
Krzysztof
 

enable pin in l293d

thanks Kaleborg! I have tried to reduce the delay loop but somehow my output was unable to have a full 5v to trigger the L293D. It always stuck at about 0.5mv or 1.3mv
 

l293d interfacing with pic16f877a

Kaleborg is partly right: “j<5000000 is always true”, but not because of a 8-bit uC, but because j is an ‘int’ (j € (-32768, 32767) ), and if your compiler did not complain about this, you should change it!
If you make j an ‘unsigned int’, it can then go up to 65535.

But that’s only part of the problem!
In your ‘wait()’ function you do ‘RD1 = 0’, so that any previous attempt to do otherwise (‘RD1 = 1’) in main() will only last about a couple us, so the correctness with which you time ‘DelayUs()’ is irrelevant.

Arthur
 

enables l293 pic

thanks Kaleborg! I have tried to reduce the delay loop but somehow my output was unable to have a full 5v to trigger the L293D. It always stuck at about 0.5mv or 1.3mv
I think it may be because you did not configure ports as digital. By default pins are set as analog. If you need use digital output, clear register ADCON1 or ADCON0.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top