Do I need a pause?


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Try something like this:
    Code:
    IF mydata1=%01011001 THEN
    WHILE  mydata1=%01011001
    HIGH 1
    WEND
    ELSE
    LOW 1
    ENDIF
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2

    Default

    Thanks Joe for the example, I did try it but it locks up, let me explain. On the receiver I have read and reread what I have written, but I added a datagood LED that way I can see what is going on the the variable mydata1. When the momentary output stays on, datagood is also on so I don't think the mydata1 is %00000000 so what is your opinion. I removed the other outputs from the program to reduce the space here. Here is the receiver:
    INCLUDE "MODEDEFS.BAS"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, MCLR_OFF
    @ DEVICE pic16F628a, BOD_ON
    @ DEVICE pic16F628a, LVP_OFF
    @ DEVICE pic16F628a, CPD_OFF
    @ DEVICE pic16F628a, PROTECT_OFF
    DEFINE OSC 4
    mydata1 VAR byte
    mydata2 var byte
    address1 var byte
    address2 var byte
    checksum var byte
    chk_sum var byte
    'do I need vrcon=0 ?
    datagood VAR porta.2
    serpin VAR porta.1 'serial input pin
    PORTA = 0
    PORTB = 0
    trisa = %00000010
    trisb = %10000000
    CMCON=%00000111
    PAUSE 50

    loop:
    mydata1=%00000000
    gosub loop1
    CheckSum = (address1 + address2)
    CheckSum = CheckSum + (mydata1 + mydata2)
    IF checksum != chk_sum THEN loop
    IF mydata1 != mydata2 THEN loop
    IF address1 != address2 THEN loop

    IF (mydata1>0) && (checksum = chk_sum) THEN
    datagood = 1
    else
    datagood = 0
    endif
    if mydata1=%01010110 then loop2
    if mydata1=%10101111 then loop2
    if portb.0=1 then loop3
    goto loop

    loop2:
    if mydata1=%10101111 then high 0 'master relay turn on
    pause 50

    if mydata1=%01010110 then portb=0 'master relay turn off
    pause 50
    goto loop

    loop3:
    if mydata1=%01011001 then
    high 1 'portb.1 is on
    else
    low 1 'portb.1 is off
    endif
    GOTO loop


    loop1:
    SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
    Return

    And here is the tx:
    INCLUDE "MODEDEFS.BAS"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, MCLR_ON
    @ DEVICE pic16F628a, BOD_ON
    @ DEVICE pic16F628a, LVP_OFF
    @ DEVICE pic16F628a, CPD_OFF
    @ DEVICE pic16F628a, PROTECT_OFF
    define osc 4
    CMCON=%00000111
    trisb = %11111111
    trisa = %00010111
    chk_sum var byte
    dgood var porta.2
    serpin var porta.3
    nokey con %11111111
    synch con 254
    address con %00000001
    keyin var portb
    keydata var byte
    E VAR PORTB.0
    D VAR PORTB.1
    G VAR PORTB.2
    A VAR PORTB.3
    B VAR PORTB.4
    C VAR PORTB.5
    F VAR PORTB.6
    na VAR PORTB.7
    PreAmble CON $A5 ' 10100101 preamble
    findkey:
    if keyin != nokey then pressed
    goto findkey
    pressed:
    if A = 0 and B = 0 then p3
    if A = 0 then p1
    if B = 0 then p2
    goto findkey

    p1:
    if A = 0 then keydata = %01010110
    gosub validate
    gosub transmit
    goto findkey

    p2:
    if B = 0 then keydata = %01011001
    gosub validate
    gosub transmit
    pause 250
    if B = 1 then pause 10
    if B = 1 then keydata=%00000000
    gosub validate
    gosub transmit
    goto findkey

    p3:
    if A = 0 && B = 0 then keydata = %10101111
    gosub validate
    gosub transmit
    goto findkey
    validate:
    chk_sum = (address + address)
    chk_sum = chk_sum + (keydata + keydata)
    return
    transmit:
    serout serpin,N2400,[$55,$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,$AA,sy nch,address,address,keydata,keydata,chk_sum]
    return

    Thanks again
    Last edited by tazntex; - 22nd August 2008 at 21:18.

  3. #3

    Default

    I have looked over this for the last two days and when the output is stuck on the led I have for datagood is on so this tells me that mydata1 is not clearing. I've search this forum to see if anyone else has or had this kind of problem but could not find any information. Does anyone have any suggestions? Thank you

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default

    tazntex, What do you mean by this line?, if mydata1=%10101111 then high 0 'master relay turn on. What is "high 0"?

    Dave Purola,
    N8NTA

  5. #5

    Default

    tazntex, What do you mean by this line?, if mydata1=%10101111 then high 0 'master relay turn on. What is "high 0"?

    Good afternoon, Dave, mydata1=%10101111 is the data sent via the transmitter to the receiver, HIGH 0 is portb.0.

    '73 Dave, thanks for the reply.

  6. #6

    Default Update

    I've added a 250ms pause after high one and it seemed to be a little better, then I add a 500ms pause and it does not stick so much although this is not a cure.
    oop3:
    if mydata1=%01011001 then
    high 1 'portb.1 is on
    pause 500
    else
    low 1 'portb.1 is off
    endif
    GOTO loop

    Loop2 does fine its just noticable in loop3. I thought there might me something with PICBASIC PRO 2.50, i've already installed the A patch and went there today and they have a 2.50b patch. I didn't see anything that might affect what I am trying to accomplish here. I know there are a lot of people here on this forum with much, much more experience with microcontrollers than I'll ever have. I have search time and again to see if anyone has had similar problems but have not not found anything revelant to this type. Certainly someone sees what I have missed. Thank you
    Last edited by tazntex; - 26th August 2008 at 02:37. Reason: grammar

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default

    tazntex, That is not the way you would access a port pin (atleast I have never done it that way), You should access it by the way of "portb.0" or referencing everything from porta.0. Just saying "HIGH 0" would lend me to believe it would be accessing porta.0. Also I see you are turning off all of port b by the syntax "if mydata1=%01010110 then portb=0 'master relay turn off". Is this what you want to do? Why not just use an alias for the relay output like "Relay var Portb.0". Then all you need to do is use the syntax "Relay = 0 or Relay = 1" I would investigate your use of the port syntax before I placed any pauses into the code....

    Dave Purola,
    N8NTA

Similar Threads

  1. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 07:28
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 16:23
  3. Replies: 11
    Last Post: - 12th July 2008, 03:36
  4. Fade out LEDs question
    By Sam in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd June 2008, 11:50
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 04:46

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