Help PLEASE - Stuck on a project! 16F877A


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Location
    London
    Posts
    251

    Default Help PLEASE - Stuck on a project! 16F877A

    Hello, I am trying to make a system which should allow an operator to call for assistance from other departments. I have one code for my 16F877A for operator unit (RF Tx & Rx attached) & other code for another 877A for the department (RF Tx & Rx attached). There are 15 operators in total and 3 departments.
    If I can make the system work for 1 department, other two should be less pain.
    Working:
    When operator presses the button for assistance, corresponding LED in the department unit should glow, sending a confirmation signal to operator unit, once this confirmation is received, led at operator unit should blink. When anyone leaves the department to attend the operator, he presses a corresponding button at the department unit, which sends another signal to the operator unit making the blinking LED at operator unit to get stable. Then when work is finished at the operator’s machine, the operator presses the second button which sends another signal to the Department’s unit switching OFF the LED there and waits for the confirmation signal to arrive before it switches OFF its own led as well.

    Problem:
    Upto the knowledge I have, I have made this and tested the system many times and it works up till the person leaves the department and led at operator unit gets stable. After that system behaves erratically. I have even tried to arrange the code in such a way so that operator unit keeps sending the signal automatically if it does not receive the confirmation signal in a certain time. But the system fails most of the time and cannot put the led off at the department unit, despite of repeated signals from the operator unit.
    I attach the code for reference. Hope to find an answer soon.
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Anyone please?

  3. #3
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Update

    It seems that RX unit at MC Room hangs up when LED OFF siganl is transmitted, because when I interrupt the power supply of this unit and reconnect it, the LED gets off at MCH unit, which indicated to me that RX may hang up, and only receives signal from the MCH unit once reset takes place. Because the MCH unit is repeating the LED off signal all the time, the MC Room only captures it on reset.

    Is it possible that using DT_INT could be the problem?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Megahertz View Post
    Is it possible that using DT_INT could be the problem?
    No, but using them the wrong way sure will.
    Sitting in the interrupt handler sending serial data and pausing in a loop will stop anything else from happening in the main loop.

    By the time you exit the handler, the timer has overflowed again, and it'll jump right back to the handler again for more loops pauses and DEBUG output.

    Interrupts are meant to handle things immediately and fast.
    Not to trigger a long series of statements that take longer than the period between interrupts.

    Get in, do what you need to respond to the interrupt, then GET OUT.
    Let the main loop handle any pauses and debugs.

    99.9% of the time, there should never be a PAUSE in an interrupt handler.

    And you should use the USART for serial data, not DEBUG/IN.
    DT

  5. #5
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Thanks for the answer. I can see some light now at the end of the tunnel.
    Few questions I have, please try to answer them:
    1) My MCroom code sits at DEBUGIN statement at all times. And I have learnt that after the interrupt is handeled, program resumes from from the last statement which it was executing, which in my case is DEBUGIN. So how can I send
    Code:
    if z>0 THEN
         for x=1 to 30
           DEBUG "MT3",z,"C"
           Low Tx : Pause 10
         next x
         Low BUZ : z=0
     ......
    this signal if I do not put it in interrupts.

    2) I have used one calculator I found here in forum only to see what is the duration of interrupts. It comes to every 524mSec for TMR1 @ 16bit @ 1:8 prescaler. Based on that the MCRoom code only uses 300mSec for debug statement and that too only once. OK, I agree if I put pause statements in the ISR code, timer will runout again. but pause is only used once when the DEBUG is used in MCRoom code ISR, why it kind of hangs permanently after that?
    Because MC1 code is repeating that signal continuesly after certain interval. I cannot understand why the MCroom is unable to catch the LED OFF code later

    I hope I have explained my point, and apologies if confusion is still lingering. Please ask me for any clarification if needed.

    P.S: I don't have any knowledge about USART, I am a product design student actually and try to learn programming because I find it very interesting. I will learn about USART soon and apply it to these codes. I hope I can make this code work using DEBUG for now.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Megahertz View Post
    P.S: I don't have any knowledge about USART, I am a product design student actually and try to learn programming because I find it very interesting. I will learn about USART soon and apply it to these codes. I hope I can make this code work using DEBUG for now.
    Using the USART in PBP is not much different than using DEBUG or SERIN2, same syntax.
    Look to the PBP manual under HSERIN for starters and at the bottom of this page is an example to play with.
    http://www.melabs.com/resources/samples-pbp-general.htm
    The hardest thing with the USART at the beginning is setting it up.
    For that this is a handy tool
    PicMultiCalc
    http://www.picbasic.co.uk/forum/atta...achmentid=2957
    Dave
    Always wear safety glasses while programming.

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