• AVR Freaks

Hot!Bonehead part IV

Author
jweir43
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2019/05/22 13:43:05
  • Location: Grass Valley, 60 miles north of Sacramento
  • Status: offline
2019/08/15 18:30:25 (permalink)
0

Bonehead part IV

I've been bashing my head and wasting electrons for two straight days now. There must be something wrong with my code because the damned LED just sits there dark as sin. Can anybody lead me into the path of righteousness on this sucker? Thanks, Jim

' Name : 7segjw1.bas
' Compiler : PICBASIC PRO Compiler 3.1
' Assembler : MPLAB X IPE v5.15
' Target PIC : 16F630
' Hardware : Lab Protoboard
' Oscillator : Internal 8 MHz.
' Keywords : 7 segment display
' Description : PICBASIC PRO program to blink an LED connected
' to PORTC.0 about once a second.
' PORTC.0 is pin 10 of the 16F630.

#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
#ENDCONFIG 

TRISA = %001000
TRISC = %000000

SA var PORTC.0 ' Alias PORTC.0 to SA

mainloop:
High SA ' Turn on segment A connected to PORTC.0
Pause 500 ' Delay for .5 seconds

Low SA ' Turn off segment A connected to PORTC.0
Pause 500 ' Delay for .5 seconds

Goto mainloop ' Go back to loop and blink LED forever

End


Tags: None
 

The Titanic was built by expert engineers and a reputable company.  The Ark was built by amateurs at home.
#1

15 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Bonehead part IV 2019/08/15 18:37:02 (permalink)
    +1 (1)
    You won't find many people here who know much about PICBASIC.
     
    You have enabled the MCLR pin. Does the "Lab Protoboard" have a pullup on that pin?
     
    Do you have a debugger? e.g. a PICkit3 ?
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    jweir43
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2019/05/22 13:43:05
    • Location: Grass Valley, 60 miles north of Sacramento
    • Status: offline
    Re: Bonehead part IV 2019/08/15 18:51:52 (permalink)
    0
    10K from Vdd to MCLR
     
    Pickit 4, but not a clue how to use it for debug.  I've spent HOURS online trying to find a comprehensible explanation of how to use it for debut..
     
    Thanks,
     
    Jim

    The Titanic was built by expert engineers and a reputable company.  The Ark was built by amateurs at home.
    #3
    1and0
    Access is Denied
    • Total Posts : 9607
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Bonehead part IV 2019/08/15 19:47:18 (permalink)
    +2 (2)
    Turn off the Watchdog Timer in your config bits, and turn off the analog feature on RC0.
    #4
    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Bonehead part IV 2019/08/15 20:11:11 (permalink)
    +1 (1)
    1and0
    Turn off the Watchdog Timer in your config bits,

    Bingo. That will be it.
     

    and turn off the analog feature on RC0.

    Will be required as soon as the code starts controlling more bits in PORTC.
    Won't be causing this immediate problem.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    newfound
    Super Member
    • Total Posts : 1837
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: online
    Re: Bonehead part IV 2019/08/15 20:18:24 (permalink)
    +1 (1)
    1and0
    Turn off the Watchdog Timer in your config bits, and turn off the analog feature on RC0.


    No analog on the 16F630 but the watchdog timer issue should be addressed. Even so, I would still expect the LED to flash as the timeout period would be > 2 seconds with the default OPTION_REG settings.
     
    Also, the internal oscillator for this part is 4MHz, not 8MHz as in the source code comments.  
     
    Not convinced that the watchdog timer issue is everything wrong here though it does need to be corrected for the LED to flash at the expected timing.
    #6
    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Bonehead part IV 2019/08/15 20:27:54 (permalink)
    +1 (1)
    newfound
    No analog on the 16F630

    Good point!
     

    but the watchdog timer issue should be addressed. Even so, I would still expect the LED to flash as the timeout period would be > 2 seconds with the default OPTION_REG settings.

    If the OP has told PBPRO the chip is running at 8MHz when it's really 4MHz, then those pause delays are probably giving one second pauses. Still you'd expect to see something if the WDT takes 2 seconds to kick in.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    1and0
    Access is Denied
    • Total Posts : 9607
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Bonehead part IV 2019/08/15 20:31:56 (permalink)
    +1 (1)
    newfound
     
    No analog on the 16F630

    You are correct. I was looking at the "Pinout Description" table and did not realize the AN4 in RC0/AN4 is for the 16F676 only.
     

    but the watchdog timer issue should be addressed. Even so, I would still expect the LED to flash as the timeout period would be > 2 seconds with the default OPTION_REG settings.

    I am not familiar with PicBasic, but what determine Pause 500 to be 0.5 second delay?
     
    <edit> From PicBasic Pro compiler manual, "PAUSE assumes an oscillator frequency of 4MHz. If an oscillator other that 4MHz is used, PBP must be told using a DEFINE OSC command."
     
    post edited by 1and0 - 2019/08/15 20:38:10
    #8
    PStechPaul
    Super Member
    • Total Posts : 2375
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: Bonehead part IV 2019/08/15 21:12:00 (permalink)
    0
    How is the 7 segment display connected to the PIC? PC0 (pin 10) should connect to segment A through a resistor of about 200-500 ohms, and the common cathode should connect to Vss (GND). What voltages are you measuring on pin 10?

     
    #9
    newfound
    Super Member
    • Total Posts : 1837
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: online
    Re: Bonehead part IV 2019/08/16 00:36:20 (permalink)
    0
    1and0
    newfound
     
    No analog on the 16F630

    You are correct. I was looking at the "Pinout Description" table and did not realize the AN4 in RC0/AN4 is for the 16F676 only.
     

    but the watchdog timer issue should be addressed. Even so, I would still expect the LED to flash as the timeout period would be > 2 seconds with the default OPTION_REG settings.

    I am not familiar with PicBasic, but what determine Pause 500 to be 0.5 second delay?
     
    <edit> From PicBasic Pro compiler manual, "PAUSE assumes an oscillator frequency of 4MHz. If an oscillator other that 4MHz is used, PBP must be told using a DEFINE OSC command."
     

    On this PIC when the internal oscillator is used there is no option to apply anything to modify the frequency thus the Fosc will be 4MHz. There is no postscaler or PLL etc. Therefore the LED, all else being equal, should flash twice then the device will reset after ~2.3 seconds (128 * 18ms) via the WDT and the whole cycle repeat. 
     
    The irony here is that it is a good thing that it is not even working to this extent as this behavior would appear to the naked eye to be the desired result and the issue of not clearing (or disabling) the WDT would go unnoticed. 
     
    To my reading of it all, there is nothing obviously wrong with the code. However, I must also plead ignorance of the workings of the basic complier. 
     
    If we had it in front of us I'm sure we could fix it in (tens of?) minutes but it is all bit of a dark art when we don't know about the workings of the compiler.
     
    Maybe the code should be posted on the PIC basic forum?  
     
     
     
    #10
    1and0
    Access is Denied
    • Total Posts : 9607
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Bonehead part IV 2019/08/16 05:59:33 (permalink)
    0
    OP's code is almost identical to this, so I think the code is okay. It is probably a hardware issue.
     
    http://melabs.com/samples/LABX1-16F887/blinkx.htm
     
     
    #11
    mpgmike
    Super Member
    • Total Posts : 252
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: Bonehead part IV 2019/08/16 06:34:13 (permalink)
    +1 (1)
    The Watchdog Timer isn't an issue as PBP automatically clears is for you.  You must tell it NOT to if you want to do it yourself.  The PAUSE command assumes PAUSE 1000 = 1 second.
     
    The native IDE for PBP is MicroCode Studio.  Although the marketing claims you can write PBP in the MPLABX IDE, Charles Leo of ME Labs (Creator of PBP Basic) told me awhile ago that PBP hasn't worked well with MPLABX since version 3.60.  Try copy/pasting your code into the MicroCode Studio IDE and program it from there.  Furthermore, features like Simulation and Debug never really worked well in MPLABX for PBP.  The MicroCode Debug "feature" uses the UART function (if your PIC has one) to bounce info back & forth.  I never used it.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #12
    jweir43
    New Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2019/05/22 13:43:05
    • Location: Grass Valley, 60 miles north of Sacramento
    • Status: offline
    Re: Bonehead part IV 2019/08/16 15:30:02 (permalink)
    0
    Problem solved.   I shouldn't be teaching this stuff with stupid mistakes like this but a simple 100 nf capacitor from Vdd to Vss cured the problem.
     
    mpgmike
    Try copy/pasting your code into the MicroCode Studio IDE and program it from there.  

    Studio won't accept a PICkit 4 as the programmer unless you've got some sneaky way to make it "see" the programmer.
     
    Jim

    The Titanic was built by expert engineers and a reputable company.  The Ark was built by amateurs at home.
    #13
    mpgmike
    Super Member
    • Total Posts : 252
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: Bonehead part IV 2019/08/16 15:59:57 (permalink)
    0
    You could develop the code in MicroCode Studio, Compile, then use MPLABX IPE and import the .hex and burn it that way.  At any rate, I'm glad you solved your issue.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #14
    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Bonehead part IV 2019/08/16 16:01:38 (permalink)
    +1 (1)
    .. and never ever omit the supply bypass capacitors.
    We usually just assume they have been fitted.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #15
    dan1138
    Super Member
    • Total Posts : 3190
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Bonehead part IV 2019/08/16 16:16:10 (permalink)
    +1 (1)
    ric
    newfound
    No analog on the 16F630

    Good point!

    There is no ADC in the PIC16F630 but there is a comparator that is enabled at Power-On-Reset so until the code turns of the comparator RA0 and RA1 cannot be used as digital inputs.
     
    This is not important to this thread yet.
    #16
    Jump to:
    © 2019 APG vNext Commercial Version 4.5