Must reset PIC to get correct operation?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Must reset PIC to get correct operation?

    Below is a code that I am using to monitor inputs to a 16F870. As discussed in an earlier post, I am controlling and monitoring these inputs through a wireless link. When I activate them locally (by applying voltage right to the pin), it works well and I have no problems. When I control it with the wireless transmitter, I find that the PIC "locks" up and I have to reset it to work correctly. I found, through a lot of time experimenting, that using a nap or sleep command seems to correct the problem. I can't figure out why it's happening and I am not sure if it is hardware or software related. I don't think it's the relays because the transmitter and receiver are on seperate boards. I am suspect of the wireless transmission and I wonder if it is possible that the data or power of the transmitter is locking up the PIC. Anyhow, please take a look at my code but without the nap command at the end, it won't work correctly.

    Thanks,

    Chris



    @ DEVICE PIC16F870, HS_OSC, WDT_On, PWRT_ON, BOD_on, LVP_OFF , DEBUG_OFF, PROTECT_OFF

    DEFINE OSC 4
    DEFINE HSER_BAUD 2400
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_CLROERR 1
    ADCON1=7
    b1 var BYTE 'first of 4 vars to store verified good data
    b2 var BYTE
    b3 var BYTE
    b4 var BYTE
    C1 var byte
    C2 var byte
    C3 var byte
    C4 var byte
    start var byte 'first incoming byte - should be zero
    sum var WORD 'incoming checksum from the sending PIC
    datasum var BYTE 'used to add values of 4 incoming data bytes
    errorflag var bit 'flag to indicate bad data (1 = bad or untested data)

    TRISA=%11111111
    TRISB=%11111111
    TRISC=%10111111

    HIGH portb.3
    PAUSE 100
    MAINLOOP:


    if PORTA.5=0 THEN
    B1=0
    ELSE
    B1=1
    ENDIF
    if PORTA.2=0 THEN
    B2=0
    ELSE
    B2=1
    ENDIF
    if PORTA.1=0 THEN
    B3=0
    ELSE
    B3=1
    ENDIF
    if PORTA.0=0 THEN
    B4=0
    ELSE
    B4=1
    ENDIF
    C1=(B1*1)+(B2*2)+(B3*4)+(B4*8)


    if PORTB.1=0 THEN
    B1=0
    ELSE
    B1=1
    ENDIF
    if PORTB.5=0 THEN
    B2=0
    ELSE
    B2=1
    ENDIF
    if PORTB.4=0 THEN
    B3=0
    ELSE
    B3=1
    ENDIF
    if PORTB.2=0 THEN
    B4=0
    ELSE
    B4=1
    ENDIF
    C2=(B1*1)+(B2*2)+(B3*4)+(B4*8)

    if PORTC.0=0 THEN
    B1=0
    ELSE
    B1=1
    ENDIF
    if PORTC.1=0 THEN
    B2=0
    ELSE
    B2=1
    ENDIF
    if PORTC.2=0 THEN
    B3=0
    ELSE
    B3=1
    ENDIF
    if PORTC.3=0 THEN
    B4=0
    ELSE
    B4=1
    ENDIF
    C3=(B1*1)+(B2*2)+(B3*4)+(B4*8)

    if PORTC.7=0 THEN
    B1=0
    ELSE
    B1=1
    ENDIF
    if PORTC.5=0 THEN
    B2=0
    ELSE
    B2=1
    ENDIF
    if PORTC.4=0 THEN
    B3=0
    ELSE
    B3=1
    ENDIF
    if PORTB.0=0 THEN
    B4=0
    ELSE
    B4=1
    ENDIF
    C4=(B1*1)+(B2*2)+(B3*4)+(B4*8)
    GOSUB SENDATA


    GOTO MAINLOOP

    SENDATA:
    sum = C1+C2+C3+C4
    HSEROUT [30,C1,C2,C3,C4,sum.byte0]
    pause 40
    nap 0

    RETURN

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi Chris,
    I've no idea if this could cause the problem you describe... but you have the COFIG set to "HS", but seem to be using a 4MHz osc? (which I think would use the "XT" setting).


    @ DEVICE PIC16F870, HS_OSC, WDT_On, PWRT_ON, BOD_on, LVP_OFF , DEBUG_OFF, PROTECT_OFF

    DEFINE OSC 4
    Arch

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, Arch

    No Problem to use a Faster OSC config ... that only draws a little more current to the supply.
    Sometimes permits to use "lazy" Xtals ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    How about if you disable the watchdog timer?

    I know PBP add some CLRWDT instruction here and there but, i guess it worth a try. Unless you use a WDT interrupt, i guess you simply don't need it.

    Just a suggestion
    Code:
    if PORTA.5=0 THEN
    B1=0
    ELSE
    B1=1
    ENDIF
    you'll save codespace and increase your program speed if you use
    Code:
    B1=PORTA.5
    Maybe the HS mode can do something... maybe for some crystal brand and not on some other.
    Last edited by mister_e; - 29th May 2006 at 14:47.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Thanks for the help with the code (b1=portx.x), that will certainly save some space. I tried removing the WDT but I still had the same results. Now I need it because the NAP command is dependent upon the WDT....if I read the manual correctly. I'll try messing around with the clearwdt and wdt commands to see what happens.

    Thanks

  6. #6
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    Christopher4187

    You have a reset resistor on the chip for sure, what value? Also, with the RF, you do have the chip decoupled well?

    I designed a PIC circuit many years ago, and it worked great. It moved a servo to hide a plate on the back of a show motorcycle. And sometimes it would go nuts when the owner rode it. Turned out, he stored his Nextel celephone in the compartment the circuit was in, and the RF was resetting the PIC, and dropping the plate back down (init setting). I added some caps, and all fixed.

    Just a thought as you are wondering if HW/SW. Maybe drop a scope on the reset, and on the POWER pin and watch it..

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. Automatic VB6 to pic serial connection
    By arniepj in forum Code Examples
    Replies: 13
    Last Post: - 10th January 2008, 07:57
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

Members who have read this thread : 1

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