problem using 16f877


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    yrch's Avatar
    yrch Guest


    Did you find this post helpful? Yes | No

    Post Another problem

    Hello again!

    Thanks for your quick response to my post. I guess you were right about the datasheet issue, by examining a bit more and doing a little more research helped me solve my problem.

    However, now I have a problem which I happen to find several solutions, but cannot comprehend them due to my limited knowledge and therefore ask for your help here urgently. This time I have looked at the datasheet carefully, but like I said, it wasn't much of an help since I have trouble understanding it.

    What I'm trying to do at the moment is simply driving a DC motor with a L293D driver circuit and the same PIC, 16F877. According to my program, it needs to run in one direction for 3 seconds, then stop for 1 second and then run in the opposite direction for 3 seconds again. I don' t really need speed control, that is optional, but I do need the reverse direction, which is why I'm using the L293D as a H-bridge.

    Now I will move onto things I have learned through my research on the internet, so that you can help me out better:

    From what I have read, it seems that I need to use (or I better use?) either C1 or C2 port (or both?) for connection to the enable pins on the H-bridge and I should use the PWM module even if I'm going to control the speed of the motor.
    To use the PWM correctly, several data registers should be modified, such as CCP1CON, T2CON and the pulse frequency PR2 and the duty cycle CCPR1L.
    I'm going to be using a DC motor with a 12V input. Though I don't have much of an idea about how those registers should be modified, I added the following lines in my program according to what I have read on the internet:

    CCP1CON = 12
    CCP2CON = 12
    T2CON = %00000101
    PR2 = 249
    CCPR1L = 124
    CCPR2L = 124

    I think the duty cycle and the pulse frequency should be modified in such a way that the desired working and pause periods (3 secs & 1 sec) are achieved. Or are these values unable to determine the motor's sequence and delay and should it be specified within the actual running code (like with "Pause 3000")? If not, how are these aspects related? Apart from the C1 and C2 ports connecting to the enable pins of L293D, I think two additional output ports are required to give the proper rotation direction of the motor. Can these be any port on the 16F877? I have also read that the enable pins should be high, while the directions pins are set low and high one by one. Is there anything else I should know about the enable pins? (because last time I ran the program, no matter which stage of the program it is in, it was always high.

    This is the summary of what I have understood sand what I have not so far. Thank you in advance for your patience and help.
    Last edited by yrch; - 21st January 2006 at 09:19.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If you are using a single phase (single winding) DC motor, then connect it across pins 3 and 6 of the L293D (as in the DATASHEET for the L293D).

    Then all you have to do is drive pin 2 HIGH and pin 7 LOW for the motor to turn one way, and reverse it with pin 2 LOW and pin 7 HIGH for the motor to turn the other way (subject of course to you turning pin 1 ENABLE HIGH).

    For Fast Motor Stop, Drive both Inputs LOW, or Drive both Inputs HIGH or Drive ENABLE pin LOW.

    It's all in the DATASHEET.

    Done, dusted, simple. So what's all this playing with PICs Registers for?

    ...it needs to run in one direction for 3 seconds, then stop for 1 second and then run in the opposite direction for 3 seconds again.

    Enable var PortB.0 ' Enable Pin 1
    DriveA var PortB.1 ' Drive Pin 2
    DriveB var PortB.2 ' Drive pin 7

    TRISB=%11111000

    Loop:
    Gosub AllStop
    Pause 1000
    Gosub RunOneWay
    Pause 3000
    Gosub AllStop
    Pause 1000
    Gosub RunOtherWay
    Pause 3000
    Goto Loop

    AllStop:
    Low Enable
    Low DriveA
    Low DriveB
    Return

    RunOneWay:
    High DriveA
    Low DriveB
    High Enable
    Return

    RunOtherWay:
    Low DriveA
    High DriveB
    High Enable
    Return

    End

  3. #3
    mns45's Avatar
    mns45 Guest


    Did you find this post helpful? Yes | No

    Default drive dc motor with pic 16F877

    Hi, I'm a beginner in this forum.
    I want to control a 12 Volt DC motor in constant speed. To do it, i will use half of H bridge. As i have two switching element, mosfet, i will have two gate signal. I want to do it by 16F877, know i have to learn that how i could convert an analog input to a digital. I have an potentiometer , i change the resistance and i set an analog value and pic understand it.
    The second question. I have to make pwm in constant frequency. Pic take the analog value from its leg (the first analog value for the speed which we set at first ) and there is a feedback system, feedback voltage from tako, pic compares the value comes from tako with we set at first and if neccessary it will change the duty cycle in constant frequency.
    Example: we set 100 mV to drive motor in 1400 rpm

    I want to get some examples in assemble (16F877) for analog digital converter. And i wanna know to make a pulse in constant frequency.
    I look at pic 16F877 datasheet but i think it is hard to solve problem by using datasheet. Some basic example will help me too much. Thanks very much. Please help me...

Similar Threads

  1. 16f877 with LM335 problem
    By CrazyCooter in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 17th April 2015, 07:31
  2. 16F877 HSERIN problem with 3th party software
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th March 2009, 18:11
  3. LCD problem with 16F877
    By alexx_57 in forum General
    Replies: 10
    Last Post: - 25th July 2007, 14:47
  4. problem with 16f877 and display
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th January 2007, 22:53
  5. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 11:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts