Is there a wise way to debug a large code?


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: Is there a wise way to debug a large code?

    Quote Originally Posted by CuriousOne View Post
    Forgot to mention, IC is 16F887A
    i got lost at this point


    THEN HPWM 2,150,2000 ?? 16F887A does not exist 16F887 has 1 ccp module

    then today


    I tried inserting HPWM 1,200,2000 at random places in main loop


    mind boggles
    Warning I'm not a teacher

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Is there a wise way to debug a large code?

    Not that this would fix your issue, but you have:
    Code:
    DIMMER: 'auto dim routine
    IF Z2=06 THEN HPWM 2,150,2000
    IF Z2=08 THEN HPWM 2,200,2000
    IF Z2=10 THEN HPWM 2,255,2000
    In this case I would have used:
    Code:
    Dimmer:
    IF Z2 = 06 THEN
     HPWM 2,150,2000
    ELSEIF Z2 = 08 THEN...
    What happens if Z2 = 07? Maybe use:
    Code:
    IF Z2 <= 06 THEN
     HPWM 2,150,2000
    ELSEIF Z2 <= 08 THEN...

  3. #3
    Join Date
    Feb 2013
    Posts
    1,158


    Did you find this post helpful? Yes | No

    Default Re: Is there a wise way to debug a large code?

    Well, there is no GOTO there is GOSUB, this was just a literal description of how it works.

    16F887 has two PWM modules, which can be output at 4 different channels, read the datasheet. You can adjust duty cycle individually, just frequency will be the same.

    From datasheet: - 10-bit PWM with 1, 2 or 4 output channels, programmable “dead time”, max. frequency 20 kHz.


    IF Z2=07 then nothing should happen and nothing happens

    For the cleanliness of experiment, I've built a completely new PCB today, and will check code for it at weekend.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: Is there a wise way to debug a large code?

    16F887 has two PWM modules
    apologies so it does
    Warning I'm not a teacher

  5. #5
    Join Date
    Feb 2013
    Posts
    1,158


    Did you find this post helpful? Yes | No

    Default Re: Is there a wise way to debug a large code?

    Well, the different build has no such issue, but while using same code, it also uses different pinout (ADC input is PORTE.2 instead of PORTA.0), so in next days I will try to check existing build for issues.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,158


    Did you find this post helpful? Yes | No

    Default Re: Is there a wise way to debug a large code?

    It is very interesting, as I unpacked the original board and put it on the table, it no longer had that issue.
    And after I packed the new board into small enclosure, it started to have exactly the same issue!
    I added some checks to code and here is what I've found.
    I'm using ADC to get the input from the keys.
    ADC IN is tied to VDD via +10K resistor, and there are two buttons, one pulls that IN to GND, another also pulls to GND, but via another 10K resistor.
    So when no button is pressed, ADC input reads 255. When 1st button is pressed - it is 0, and when 2nd button is pressed, it is about 127. (My code checks it to be above 100 and below 140)

    So, what happens? When I have PWM with duty cycle less than 170 (assuming HPWM 1,170,2000), the ADC input sporadically starts to read as 127, instead of 255! The lower PWM duty cycle is, often that happens.
    But this only happens when there are some wires connected to ADC input (even short ones, about 10cm). So I guess, this is an hardware issue, and adding 0.1uf capacitor to ADC IN should help?

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Is there a wise way to debug a large code?

    Obviously this is an EMI problem. Somewhere your circuits acts like a transmitter (PWM sharp signals are what it needs to do so).

    Maybe a wrong trace, maybe a cable that is in different place, who knows?

    Can you post pictures of both PCB sides and cabling? Sure big caps will help. Better find the source of the problem.

    Ioannis

Similar Threads

  1. DEBUG DEC DatVar vs DEBUG #DatVar
    By netstranger.nz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th March 2011, 22:26
  2. Replies: 0
    Last Post: - 18th November 2010, 19:50
  3. How does everyone debug their code?
    By HankMcSpank in forum General
    Replies: 30
    Last Post: - 18th June 2009, 07:41
  4. SERIN from a large string
    By earltyso in forum Serial
    Replies: 5
    Last Post: - 2nd May 2008, 23:23
  5. large displays
    By George in forum Off Topic
    Replies: 2
    Last Post: - 18th March 2007, 22:56

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