issue with DEBUG, please help


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2011
    Posts
    8

    Default issue with DEBUG, please help

    Hello,
    I am having issue with DEBUG which output garbage when used in a program, but using the same hardware and same declaration for debug_mode, baud... works OK with a tiny test program and I cannot figure out what I am doing wrong. I am quite beginner as well, so it might be something very simple I cannot see...

    The code is used to monitor the rotation of a windlass and measures the chain out on a boat. I then want to send back the data to a display in the boat, but as the display only accepts the GPS type signal, I use the SPEED channel to pass the data to the display.
    I have also HSEROUT included to check that the program does what it is supposed to do and all the outputs from HSEROUT are OK but not the DEBUG output.

    The code which is not working is just below. I am using interrupt from Darrel and the include "Write_Int.bas" is just the time_elapsed from Darrel from which I have removed what I don't need. I can post it if needed.

    The one working is at the bottom of this post.

    I could not figure out how to enter the code in the box as I see in other post, I apologize for the messy post.

    thanks,
    Olivier


    '************************************************* ***************
    '* Name : chaine *
    '* Author : Olivier Desport *
    ' Compiler : PICBASIC PRO Compiler 2.6
    ' Assembler : MPASM
    ' Target PIC : 40-pin 16F877A
    ' Hardware : olimex 20 MHz
    ' Oscillator : 20MHz external crystal * *
    '* Date : 11/16/2015 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    define OSC 20
    DEFINE LOADER_USED 1 ' Using boot-Loader
    Define HSER_CLROERR 1 'to automatically clear any buffer overflow of serial input
    Define HSER_BAUD 4800 'Used for debugging program, to be removed later
    define DEBUG_REG PORTD 'set D.3 to NMEA standard for DEBUG
    define DEBUG_BIT 3
    define DEBUG_BAUD 4800
    DEFINE DEBUG_MODE 1

    DEFINE WRITE_INT 1 'to halt interrupt during WRITE

    ADCON1 = %10010110 'Set PortA to digital
    TRISA = %11111110

    ;---------------------------------------------------------------------------
    ;wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
    wsave VAR BYTE $70 SYSTEM ' alternate save location for W
    ' if using $70, comment wsave1-3

    ' --- IF any of these three lines cause an error ?? ------------------------
    ' Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using --
    wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
    wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
    wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
    ' --------------------------------------------------------------------------

    LED var PORTA.0 ' Alias PORTA.0 to LED
    iturn var word ' rotation of windlass
    'to avoid negative number, 100 is added (100 = anchor on boat)
    x var word 'used for computation
    lchaine var word ' longueur de chaine sortie en dm
    calcoef var word 'calibration coefficient to go from iturn to chaine length
    bflag var bit ' flag turns ON when interrupt received
    onflag var bit ' 1 when windlass is ON
    wflag var bit 'set to 0 once iturn is written to RAM
    TimeFlag var bit 'set to 1 when counter reached time
    T0Count Var WORD
    gUP var PORTA.3 'connected to UP windlass command (1 when ON)
    gDOWN var PORTA.4 'connected to Down windlass command (1 when ON)
    sCal var PORTE.2 'switch to reset counter to zero (iturn to 100) (0 when depressed)

    hpwm 1,250,2500
    pause 1000
    hpwm 1,15,2500


    'initialization
    calcoef=288
    wflag=0
    timeflag=0


    ' read eeprom to load chaine position
    bflag=0
    write 0, bflag ' this WRITE comand is only to avoid a bug in the compiler
    read 10, word iturn

    bflag = 0
    hserout ["hello",10,"read=",dec iturn,10]

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    INCLUDE "Write_INT.bas" ' Elapsed Timer Routines

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler INT_INT, _Barbotin, PBP, yes
    INT_Handler TMR0_INT, _ToggleLED2, PBP, yes
    INT_Handler TMR1_INT, _ClockCount, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor

    INT_ENABLE INT_INT ; enable external (INT) interrupts
    INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
    INT_ENABLE TMR1_INT
    ENDASM
    OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
    Gosub ResetTime ' Reset Time to 0d-00:00:00.00
    Gosub StartTimer ' Start the Elapsed Timer


    Main:
    if sCal=0 then iturn=100 'reset chain counter when pressing ZERO switch

    if wflag and timeflag then 'windlass has stopped for over 3 seconds
    'has changed position previously and value has not been written yet,
    'so value needs to be written
    write 10, word iturn 'saving chaine position
    hserout ["writing",10]
    wflag=0 'indicates that RAM has been written
    timeflag=0 'reset time flag
    endif

    if bflag = 1 then 'interrupt received
    bflag = 0 'reset sensor/interrupt flag
    T0Count=0 'reset timer count
    wflag=1 'flag to indicates new value needs to be written
    onflag = 1 'Windlass motion detected
    if gUP = 1 then
    iturn = iturn -1
    else
    iturn = iturn + 1
    endif
    if iturn>=100 then
    x=iturn-100
    lchaine=x*calcoef 'en mm
    lchaine=lchaine/100 'en dm
    else
    lchaine=0
    endif
    hserout ["iturn=",dec iturn," chaine=",dec lchaine/10,".",dec1 lchaine,10]
    endif

    if SecondsChanged = 1 then
    hserout ["$GPVTG,0.0,T,0.0,M,",dec lchaine/10,".",dec1 lchaine,",N,0.0,K",10]
    debug "$GPVTG,0.0,T,0.0,M,",dec lchaine/10,".",dec1 lchaine,",N,0.0,K",10
    SecondsChanged = 0
    endif

    GOTO Main

    '---[INT - interrupt handler]---------------------------------------------------
    Barbotin:
    bflag = 1
    @ INT_RETURN

    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    ToggleLED2:
    T0Count = T0Count + 1
    if T0Count = 15000 then
    T0Count = 0
    timeflag=1
    endif
    @ INT_RETURN

    ' ################################################## #####################

    and using the same hardware, if I use this code, the DEBUG data makes sense. I cannot figure out what is wrong with the first code.

    define OSC 20
    DEFINE LOADER_USED 1 ' Using boot-Loader
    Define HSER_CLROERR 1 'to automatically clear any buffer overflow of serial input
    Define HSER_BAUD 4800 'Used for debugging program, to be removed later
    define DEBUG_REG PORTD 'set D.3 to NMEA standard for DEBUG
    define DEBUG_BIT 3
    define DEBUG_BAUD 4800
    DEFINE DEBUG_MODE 1

    i var word
    debug "Hello"

    i=0

    mainloop:
    i=i+1
    pause 1000
    debug "i=",dec i,10
    goto mainloop

  2. #2
    Join Date
    May 2011
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: issue with DEBUG, please help

    Doing some test, I realized that it is the instruction:
    OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone

    which makes the DEBUG to produce garbage, as if the baud rate was wrong. This line was taken from the example of Darrel for the clock. So it seems it affects the DEBUG instruction.
    Could someone explain me the root cause and how to overcome this issue.
    This is my first attempt at using timer and interrupt and I am really in unknown territory here. I will keep doing some reading but any help will be highly appreciated.
    thanks,
    Olivier

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: issue with DEBUG, please help

    Hi,

    If an interrupt occurs while the DEBUG statement is busy outputting data it will, as the mechanism name implies, be interrupted and since it's a bitbanged software timed routine its timing will be off which in turn means garbage data.

    Either use the USART ("manually" or with HSEROUT) to send the data or make sure to turn off or mask the interrupts WHILE the DEBUG statement is executing.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: issue with DEBUG, please help

    OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
    por value for OPTION_REG is 255 (0b11111111)

    OPTION_REG & $80 | 1 results in OPTION_REG =129 (0b10000001)
    that is not the result you are describing in your comment ; Set TMR0 Prescaler to 256, leave RBPU alone
    it also sets the int Interrupt to falling edge of INT pin
    for 256 prescaler OPTION_REG bits 0:2 = 0b111

    next issue your code is not posted in code tags which makes life difficult .

    what do you think will happen to the bit timing accuracy of a software timed serial output routine like debug when you interrupt it 100's of times per second

  5. #5
    Join Date
    May 2011
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: issue with DEBUG, please help

    Thank you for the explanation, it is clear now. I just need to modify my board now to use the USART instead

    And for next time in order to post code properly, what do you call code tags? Is it the "wrap QUOTE tags" option in the editor?

    thanks,
    Olivier

  6. #6
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: issue with DEBUG, please help

    Quote Originally Posted by Lazuli View Post
    And for next time in order to post code properly, what do you call code tags? Is it the "wrap QUOTE tags" option in the editor?
    Code:
    Nope.  You have to go the advanced editor (at least I do) and select 'Wrap CODE tags'.  Looks like this:  #
    Creates a window like this that you can scroll up and down in
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

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. debug issue?
    By Brian in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th March 2011, 04:27
  3. debug timeout issue 12F683
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th February 2010, 21:44
  4. How do I use DEBUG ?
    By kenpo in forum General
    Replies: 13
    Last Post: - 9th January 2008, 14:54
  5. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52

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