How does everyone debug their code?


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HankMcSpank View Post
    This works intermittedly...

    HSEROUT [10,13," Increase Gain, ADCIN Value = ", DEC DC_Level_IN]

    ...about 4 times out of 10, I get a new line!

    I've tried changing the baud

    DEFINE HSER_BAUD 2400

    ...but I just get garbage when i do (yes, I'm changing the setting in the UART window too!). therefore I'm thinking this might the general flakiness of the internal oscillator &/or the quirkiness of the Microchip UART window?
    Have you tried sending 2 separate lines, 1 to clear or give a newline and the second with your data? I would put a little pause in between too. You might research CHAR_PACING too
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    In this order.
    hserout [whatever data, 13,10]

    this will work all the time as long as you have sufficient delay between all your HSEROUT, and as long as your baudrate is accurate.

    What you want is a ANSI terminal, those who accept ESC character, like the boring Hyperterminal, TeraTerm, RealTerm to name only but those. With an ANSI terminal, you can clear the screen, change font color, background color etc etc etc ( see http://www.pbpgroup.com/modules/wfse...hp?articleid=9 for reference)

    Unfortunately, PICKIT USART tool is not an ANSI one, so you have to deal with the pain or work around. If you're a bit familiar with Microsoft C#, you could modify Pickit USART tool (as it is open source anyways) to accept ESC characters, or to clear the screen when you receive, let's say, ASCII 225 or whatever else. That should be easy.
    <hr>
    I'll redo my explanation about USART tool debugging...

    Unless your current hardware don't use Serial communication, there's no need to use a switch, no need for HSEROUT either. What you do is to sit your PICKIT on the regular programming pins (MCLR, PGD, PGC) all the time, then you use DEBUG/SEROUT/SEROUT2 on PGD I/O. For this you must use TRUE mode.

    Clear enough now?

    I may try to post an example before going to sleep.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Here's a quickie example.

    Note: I cut the trace from the pot to RA0 on my board, soldered a wire to the pot output
    circuit so I can connect the output from the pot to other A/D input pins.

    This leaves RA0 free for serial debugging with the PICKit2 USART tool.

    Code:
    @ device pic16F690, intrc_osc_noclkout, bod_off, wdt_off, mclr_off, protect_off
    
    DEFINE OSC 4
    
    DEFINE DEBUG_REG PORTA
    DEFINE DEBUG_BIT 0      ' RA0 = TX out to PICKit2 programmer USART tool
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0     ' 1 = inverted, 0 = true
    
    DEFINE	ADC_BITS 10     ' Set number of bits in result
    DEFINE	ADC_CLOCK 1     ' Set clock source Fosc/8 "2uS"
    DEFINE	ADC_SAMPLEUS 50 ' Set sampling time in uS
    
    Q CON 1251              ' For 10-bit A/D +Vref = 5V : 5V/1023*256=1.251=Quanta
    ADval VAR WORD
    Result VAR WORD
    
    OSCCON = %01100000      ' 4MHz internal osc   
    ANSEL = %00000100       ' RA2 = A/D in, rest digital
    ANSELH = 0
    ADCON0 = %10001001      ' Right justify, channel AN2, A/D enabled
    CM1CON0 = 0
    CM2CON0 = 0
    
    PORTA = %00000001       ' serial out pin idles high
    TRISA = %00000100       ' RA2 in, rest out
    
    Main:
       ADCIN 2,ADval
       Result = ADval */ Q
       DEBUG "Raw = ",DEC ADval," Real = ",DEC Result DIG 3,".",DEC3 Result," V",13,10
       PAUSE 500
       GOTO Main
    
       end
    Regards,

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

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    In this order.

    Unless your current hardware don't use Serial communication, there's no need to use a switch, no need for HSEROUT either. What you do is to sit your PICKIT on the regular programming pins (MCLR, PGD, PGC) all the time, then you use DEBUG/SEROUT/SEROUT2 on PGD I/O. For this you must use TRUE mode.

    Clear enough now?

    I may try to post an example before going to sleep.
    I'm hearing what your saying, but without an example to follow, I'm still left wondering how this is achieved.

    To set out my stall again - programming is new to me - I'm more of an old analogue electronics type. I can relate to a switch! I took one look a the PICKIT2 UART Tool connectivity diagram....




    & one look at the PICKIT2 schematic...



    & saw that it only needed two pins switched...then I can simply go between programming mode & UART tool mode with the flick of a switch. In the absence of anything else meaningful 9to me at least), I followed up that path.

    I can't believe just how much of a struggle it is for a newbie to get a 16F690 (probably the chip most newbies are exposed to as it comes with the PICKIT2) to do somethign as bland as send some stuff over a serial connection! (I don't mean about the h/w aspect, I mean getting the correct 'include' files & config, the register settings, the quirks about baud rates when using internal oscillators (as most newbies do)...then there's the h/w aspect .....what a lot of work!

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    ok,et away with... I've got it working - it did indeed need separate lines with pauses inbetween. This seems to be the least i can get away with...

    ADCIN 0, DC_Level_IN ; Read the DC level as presented on RA0 (pin 19)
    pause 30
    HSEROUT [10]
    pause 30
    HSEROUT [13]
    pause 30
    HSEROUT [" Waiting for Threshold, DC Value In = ", DEC DC_Level_IN]


    many thanks to all who took the time to help - it really was appreciated.



    For the record, anyone finding this thread that's a newbie like me who wants their PICKIT2 board with an onboard PIC 16F690 to send serial data with the HSEROUT command, here's what I did (& to all you old hands, I'm sure there's a lot of stuff in here that ain't optimum - but it works for me!)...


    @MyConfig = _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
    @MyConfig = MyConfig & _MCLRE_ON & _BOR_OFF
    @ __config MyConfig

    Include "modedefs.bas"

    DEFINE OSC 4 ; sets the internal oscillator to 4MHZ (best for HSEROUT)

    ANSELH=0
    ANSEL=0
    VRCON = %00000000 ' turns the Vref Module OFF by CLEARING bit7, 6, 4
    CM1CON0 =0
    CM2CON0 =0
    CM2CON1 =0
    ADCON0.0 = 1 ' turns the AD Converter OFF by CLEARING bit0
    INTCON.0 = 0 ' clears the RABIF Flag (to 0), COULD be 1 on reset (unique to F690)
    TRISB.6 = 1 ' some s*** to do with serout that I don't fully understand!
    TRISB.7 = 1 ' more s*** to do with serout that I also don't fully understand!

    'serial Port stuff...
    rcsta.7=1 'SPEN serial port enable bit
    define HSER_RCSTA 90h
    define HSER_TXSTA 24h
    'DEFINE HSER_SPBRG 92
    DEFINE HSER_BAUD 2400 ;Set baud rate
    DEFINE HSER_CLROERR 1
    txsta.7=1 'CSRC : Clock Source Select bit 1 = internal clock
    txsta.6=0 'TX9 : 9-bit Transmit Enable bit 0 = 8 bit.
    txsta.5=1 'TXEN : Transmit Enable bit
    txsta.4=0 'SYNC : USART Mode Select bit 0=asynch
    txsta.3=0 ' N/A
    txsta.2=1 'BRGH : High Baud Rate Select bit
    txsta.1=0 'TRMT : Transmit Shift Register Status bit ( Read only )
    txsta.0=0 'TX9D : 9th bit of transmit data. Can be parity bit.


    TRISA=%11111111 ; set all Port A pins as inputs
    TRISB=%00000000 ; set all Port B pins as OUTPUTS
    TRISC=%00000000 ; set all Port C pins as OUTPUTS
    PORTA = %00000000 ' Clear the port register latches
    PORTB = %00000000
    PORTC = %00000000

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    OK, try another variant. Use your second schematic, and use the code provided by Bruce few post above.

    DEBUG is a software alternative to HSEROUT. DEBUG (like SEROUT & SEROUT2), allow you to use almost any I/O of your PIC. This avoid to use switches if your current design don't use those PGD/PGC pins (RA0 and RA1)... also called ICSPDATA and ICSPCLK on your schematic.

    Don't give up!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    OK, try another variant. Use your second schematic, and use the code provided by Bruce few post above.

    DEBUG is a software alternative to HSEROUT. DEBUG (like SEROUT & SEROUT2), allow you to use almost any I/O of your PIC. This avoid to use switches if your current design don't use those PGD/PGC pins (RA0 and RA1)... also called ICSPDATA and ICSPCLK on your schematic.

    Don't give up!
    Thanks for the encourgaement!

    Well, I revisited what Bruce posted up ....& what do you know - it worked!

    I then decided to incorporate Bruce's code into my own program - mucho grief ensued. However, if I'd taken a bit more care & actually slowly read your bit that I've bolded above, I'd not have lost two hours of my life! (I too cut the variable resistor wiper on the PICKIT2 board...but, alas, I soldered it onto pin RA1). Why isn't is a good idea to use RA1 for AtoD?


    Anyway, once I saw what you said, I resoldered the VR wiper onto RA2....everything turned out sweet (& no hardware switches either - that said, I reckon it wasn't totally wasted time, as I want to get some 'serial in' going down on a couple of my programettes soon)


    Many thanks to all!


    Hanks

  8. #8
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Just a little footnote...the debug command creates delay, which is significant in my PIC program.

    Basically, I have a coil winder program (the PIC counts pulses from magnets mounted on a spinning motor & then the PIC pulses out to a stepper which turns a helix (this feeds copper onto the main turning motor - a bit like this from 20secs in )

    Anyway, without any debug in my code...I get a nice neat wind of copper. But as soon as I use debug...the helix feeding copper wire onto the main turning motor, doesn't keep up ...end result is a lumpy wound coil - as soon as I take out the debug command...it runs fine again.

    This is a real downer, because I was using my new found 'Debug' method to put out important info onscreen (No of turns, number of steps until traversal changes direction etc).

    What are my options here?

    (I'm trying to avoid having to build a logic circuit to keep track of the PIC output pulses using hardware counters!)

Similar Threads

  1. N-Bit_MATH
    By Darrel Taylor in forum Code Examples
    Replies: 38
    Last Post: - 16th December 2010, 14:48
  2. debug not working with MPASM assempler
    By santamaria in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th March 2009, 07:51
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26

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