1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Reset on 18F4520

Discussion in 'Oshonsoft' started by camerart, Aug 15, 2016.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I'm using a PIC 18F4520. Is there a difference between initialising (switch on) and MCLR reset? When I start my program, after initialising, is doesn't give the correct result, If I reset it after initialising it works ok. If I need to reset it every time I switch on, can I simply add a connection from say PIN2 to PIN1 (Reset) then include a delay before resetting PIN1 with PIN2 by taking it low for a second?
    Camerart.
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Sounds like the oscillator is taking too long to stabilize... Are you using an external or the internal Osc?
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi C,
    Look at and add before the start of the 18F4520 Program code, lets know what you get.

    While
    OSCCON.IOFS=0 ; osc stabilised bit,
    Wend

    Be aware that Oshonsoft may not be setting the variables to what you are expecting, when the programs first runs.

    E
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.

    Hi,
    External 20MHz crystal.
    I'll check Eric's suggestion tomorrow. I think he's correct, that some of the variables seem wrong until I reset and try a second time without switching off.
    C.
     
  6. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi E,
    I tried:
    While
    OSCCON.IOFS=0 ; osc stabilised bit,
    Wend

    Wouldn't compile.
    I tried:
    While OSCCON.IOFS=0 ' osc stabilised bit, (note comma)
    Wend

    This compiled, but the PIC wouldn't start.
    I also tried moving these lines down to just before the variable settings.
    Thanks, C.
     
  7. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi C,
    Please post your code listing.
    The semicolon I use was to signify a comment, Oshonsoft uses an 'apostrophe'.

    E
     
  8. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,
    Comma, apostrophe:oops: I've been concentrating on your SDcard problem.

    Here's my code: (Tracker, and still playing with it)
    C.
     

    Attached Files:

  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi C,

    The program you have posted does not have the OSCCON statement.????
    E

    This is a clip from my code
    TRISA = 0x0f
    TRISB = 0x01
    TRISC = %00000000
    TRISD = %00001111
    LATD = %00001111

    TRISE.0 = 0 'rsvd for RTC
    TRISE.1 = 1
    Symbol dht = TRISE.2 'dht22

    PORTB = 0
    LATB = 0

    ADCON0 = 0x03 '4 *adc
    ADCON1 = 0x0b
    ADCON2 = %10100100

    T1CON.TMR1ON = 0
    PIE1.TMR1IE = 1

    While OSCCON.IOFS = 0
    Wend


    Lcdinit
    Lcdout "TXA "

    Hseropen 9600
    Hserout "TXA ", CrLf

    TMR1L = 0xdc ''0xfc '' 0xdc
    TMR1H = 0x80 ''0x80 '''0x0b

    Enable High
    Enable Low
    INTCON.GIE = 1
    INTCON.PEIE = 1

    T1CON.TMR1ON = 1
    int_cnt = 18 'fast 1st txd

    main_loop: 'idling loop, interrupts are enabled
     
  10. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Here's the top of my code with the two places I tried the OSCCON lines.
    C.
     

    Attached Files:

  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi C
    Are you trying to run the program in simulation with the osccon statement.?
    If so, it will not get past the osccon, as Oshonsoft IDE does not recognise the osccon.iofs
    E
     
  12. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi E,
    No, in circuit. You will notice just after the DIMs, there are flashing LEDs, which don't flash when the OSCCON is in either position.
    Does OSCCON also with Crystals
    C.
     
  13. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi C,
    I will double check by using my 18F4520 set up, let you know.
    E

    Update:

    The OSCCON.IOFS only works for the Internal Osc block.
    When using an external xtal, the programmed PIC hangs up at the OSCCON statement.
     
    Last edited: Aug 17, 2016
  14. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    It took a while, but now it's obvious to me that I can't reset MCLR using PIN 2 connected to it and a delayed 'push button' as it would reset and stay in that loop.
    I'll just have to press the reset button. No problem!
    Thanks, C.
     
  15. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    It could be a problem due to a slow rise time of Vdd at power on.?
    Try scoping the Vdd to the PIC at power On.
    E
     

    Attached Files:

    • A08.gif
      A08.gif
      File size:
      87.3 KB
      Views:
      85
    • A09.gif
      A09.gif
      File size:
      47.2 KB
      Views:
      78
  16. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi E,
    Would this also be the case after reset? Reason! After many complete restart tests, I am finding that this happens after reset too.
    I am sending simulated NMEA sentences (See bottom of the program) to the PIC using a macro from a computer terminal. Briefly, I press the IND button as first BASE sentences the sentences are fed into the PIC, which puts the first set of NMEA BASE sentences into BASE, then after release, the sentences are at a 100Mtr range, copying a remote GPS sentence. The first part ELEVATION always seems to work, but if things aren't perfect, when it gets to the AZIMUTH sentences it goes haywire. Once correct, I can reset or not and it always works ok.
    EDIT: With my ancient oscilloscope, it looks as the voltage goes steady quickly, and with reset, there's no flicker.
    C.
     
    Last edited: Aug 19, 2016
  17. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    Hi C.
    You say that you are using the list of test messages at the end of the program.
    E

    If you use this message as an input, note it is 90 characters long plus crlf = 92
    $GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47


    Your buffer is only 80 long!
    Dim str1(80) As Byte 'UART RXD buffer array

    There is also an over length buffer error trap.
    getmsg: 'read and save GPGGA msg
    If PIR1.RCIF = 0 Then Goto getmsg
    char = RCREG
    str1(rxi) = char
    rxi = rxi + 1
    If rxi > 80 Then Goto get_neo 'msg bfr over run
    'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
    If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
    Goto getmsg
    eomsg:
    If rxi < 60 Then 'invalid msg
    Goto get_neo
    Endif

    '$GPGGA,BASEDEGREE.00, 1000.00000, N, 00100.00000, W, 1, 10, 0.94, 000.0, m, 47.8, m,, * 47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '$GPGGA,BASEDEGREE.00,1000.00000,N,00100.00000,W,1,10,0.94,000.0,M,47.8,M,,*47
    '
     
  18. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,
    Is this ok?
    Dim str1(95) As Byte 'UART RXD buffer array

    There is also an over length buffer error trap.
    getmsg: 'read and save GPGGA msg
    If PIR1.RCIF = 0 Then Goto getmsg
    char = RCREG
    str1(rxi) = char
    rxi = rxi + 1
    If rxi > 95 Then Goto get_neo 'msg bfr over run
    'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
    If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
    Goto getmsg
    eomsg:
    If rxi < 60 Then 'invalid msg
    Goto get_neo
    Endif

    C.

     
  19. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi Eric,
    Is this ok?

    Dim str1(95) As Byte 'UART RXD buffer array

    There is also an over length buffer error trap.
    getmsg: 'read and save GPGGA msg
    If PIR1.RCIF = 0 Then Goto getmsg
    char = RCREG
    str1(rxi) = char
    rxi = rxi + 1
    If rxi > 95 Then Goto get_neo 'msg bfr over run
    'If char = 0x3f Then Goto eomsg '(0x3f = ?)SIM>>>>>>>>>>>>>>>>>>>>>>>>>>>.
    If char = 0x0a Then Goto eomsg '(0x0a = LF)CIRCUIT>>>>>>>>>>>>>>>>>>>>>>>>
    Goto getmsg
    eomsg:
    If rxi < 60 Then 'invalid msg
    Goto get_neo
    Endif

    C.

     
  20. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,411
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I've changed the 'over length buffer trap to the above settings, with the same result.
    I'm guessing that the problem may be to do with having the serial port FTDI cards connected to the USB, so the power is never off. I have had similar problems before.
    Once I get the simulation working by repeating the start-up procedure, is stays working ok, until disconnected. I can work with that.
    Thanks.
    C.
     
  21. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,238
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    You could do that, but why are you using such a long ,BASEDEGREE.00 field in the string.?
    E

    Update:
    Why are there Spaces in the message.??
     

Share This Page