Writing good/proper code


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    For me - I find it's easier to maintain large programs when they're broken into smaller
    modules. With PBP I break tried & tested routines off into include or .bas files.

    Then the majority of main routines using these include files end up being smaller more
    managable programs. So you're not scrolling through thousands of lines of code in the
    main routine.

    One of the best examples here would be to look at all the neat stuff produced by Darrel
    Taylor. He writes enormous utility routines as .bas or include files.

    One example is DT_INTS-18.bas. It's around 949 lines of code. If code is specific to a
    main project, I'll leave it in the main program. Generic utilities I'll place in include files
    and just reuse them in other programs.

    Over time you'll build up large tried & tested utility routines that you'll rarely need to debug
    or worry about anymore, so the main programs get a LOT easier to write, maintain & debug.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Hi all,

    dont want to hijack this thread but Bruce just mentioned a good idea with the modules thing.

    My question is simple:

    Is there a thread or tutorial that teaches one to build include or .bas files ?

    .

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


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Nice work Dave. Perfect links to great reasons.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5


    Did you find this post helpful? Yes | No

    Default Refresh all registers often

    I was getting random resets and crashes like you describe but now I always refresh all TRIS, PORT and ADCON, CMCON, etc every time through the main loop or at least once per second.

    As processors get smaller, run at lower voltages and faster, the impact of nearby static, lightning, fluoroescent light and electrical motor transients, cosmic rays, etc, etc all get worse.

    My code runs over a year now without any hangs after I refreshed as above. The WDT approach is also helpful and can be used to increment a value in EEROM at each hard reset so you can analyse later if you got any WDT events but don't rely just on the WDT to save your code.

    HTH
    BrianT

  6. #6
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Good code & schmitt trigger pins

    Thanks for the advice to date.

    I'm not clear what use should be made of the Watch Dog timer?

    Assume that no activity after X Seconds means something is wrong and re-start? Or is there more to this?

    On a new additional subject: ST input pins. Recently I wanted to use the hysterisis of the ST pins and did a test to check the thresholds.
    Found that PORTB.0 (used as an interrupt INT0) was way off spec for the chip PIC18F8722:

    Go off at 1.6 V
    Go on at 2.7 V

    The spec gives:
    Go off at 1.5 to 1.3 V
    Go on at 3.0 to 3.4 V

    Test voltages supplied via a 10k pot and measured with a good meter - my new FLUKE! The differences are considerably outside spec. Anyone else had difficulties with the ST pins?

    Regards Bill Legge

  7. #7
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Hi Bill,

    You got the WDT right.

    I must say that i've gone through more than my share of Microchips datasheets and i can't remember ever seeing anything else than the usual 0,2-0,8Vdd spec for ST inputs. So if you're running your pic on 5v, anything less than 1v(0,2*Vdd) is guaranteed to be read as a 0(low) by the pic. Anything above 4v(0,8*Vdd) is guaranteed to be seen as 1(high). Everything in between is to be considered as unknown. This means that your trippoint should be found somewhere in this region. It does not say anything about the amount of hysteresis. I haven't checked this for many years but when i did i found that the trippoint was just below 0.5Vdd and the hysteresis was quite small (<100mv). My memory may be way off though.

    So, if i need an input with a specified trippoint and a specified ammount of hysteresis i use a comparator(or op) with external resistors.

    /Ingvar

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 22:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  5. Writing code for battery operated projects
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th June 2005, 04:39

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