Is there a wise way to debug a large code?


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,124


    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?

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    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

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


    Did you find this post helpful? Yes | No

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

    Yes I can post, but the issue is that in both cases PCBs are different - it is thru hole (and big) components in one case, and small and SMD components in another, but giving the same issue. I think, maybe this is RMW issue somehow? because say PORTA.1 is used as ADC IN, but PORTA.2 is used as a digital output, has MPSA42 transistor connected to it's pin.

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


    Did you find this post helpful? Yes | No

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

    I think, maybe this is RMW issue somehow?
    not at all likely , which pin is having its expected digitally "read back" value changed by a digital write to another pin on the the same port ?

    as ioannis suggests this is looks very much an EMI problem that could most likely could be ameliorated by having the switch circuitry of more suitable impedance and using appropriate adc conversion speed along with sample hold time and rate.


    with no schematic or code to look at it might just be bad code who would know
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

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

    Ok, here is the part of code which reads the keys:
    Code:
    adcin 7,ard
    if ard<130 then 'if any button is pressed
    ticker=ticker+1 'increase value and wait - debouncing
    pause 1
    endif
    if ticker>150 and ard<100 then  'if left button is pressed then next menu item
    menuitem=menuitem+1
    ticker=0 'reset debouncer
    endif
    if ticker>150 and ard<130 AND ARD>100 then  'if right button pressed, change the value
    CVLADI=CVLADI+1
    if cvladi>ulim or cvladi<dlim then cvladi=dlim
    ticker=0
    here is PCB

    Name:  herepcb.jpg
Views: 946
Size:  579.6 KB

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

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

    Ok, here is the part of code which reads the keys:
    pointless snippet . how is adc setup ?

    good luck trying to use adc value without passing it through a lpf

    a pic of blank pcb is not a schematic
    Warning I'm not a teacher

  7. #7
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

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

    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds

    Here is ADC setup. All PBP defaults.

    Unfortunately, I don't create schematics - I directly draw PCB, since I can read it in same way, as schematics

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, 21:26
  2. Replies: 0
    Last Post: - 18th November 2010, 18:50
  3. How does everyone debug their code?
    By HankMcSpank in forum General
    Replies: 30
    Last Post: - 18th June 2009, 06:41
  4. SERIN from a large string
    By earltyso in forum Serial
    Replies: 5
    Last Post: - 2nd May 2008, 22:23
  5. large displays
    By George in forum Off Topic
    Replies: 2
    Last Post: - 18th March 2007, 21:56

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