Compiling and code oddities


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190

    Default Compiling and code oddities

    I'm having trouble with a code error during compile of a test program I'm writing. Although I can't see what's wrong with the SHIFTOUT line, the PBP compiler says it excpected a ] when as far as I can see it's all there.

    I also have two pieces of counting code. One 'up' count is not incrementing at 99 but zeroing, the other 'down' code works ok but it's virtually the same code.

    Also, If I add any type of config lines then the compiler complains that it's 'Overwriting previous address contents'

    Code:
    shiftout 2,3,0,[ 07,2B,02,0C ]
    
    up:
    
      counter[0]=counter[0]+1
    if counter[0]>99 then 
        counter[0]=0
         counter[1]=counter[1]+1
         if counter[1]>99 then
           counter[1]=0
            counter[2]=counter[2]+1
             if counter[2]>99 then
              counter[2]=0
               counter[3]=counter[3]+1
                if counter[3]>99 then
                 counter[3]=0     ;reset to zero
             endif
           endif
        endif 
     endif 
    return
    
    down:
    
      counter[0]=counter[0]-1
    if counter[0]<1 then 
        counter[0]=0
         counter[1]=counter[1]-1
         if counter[1]<1 then
          counter[1]=99
            counter[2]=counter[2]-1
             if counter[2]<1 then
              counter[2]=99
               counter[3]=counter[3]-1
                if counter[3]<1 then
                 counter[3]=99
             endif
           endif
        endif 
     endif 
    return
    Last edited by tasmod; - 12th November 2012 at 16:38.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Your hexadecimal numbers need to be prefixed with a dollar sign ($).

    And we need to know your version of PBP to answer the overwriting previous address question.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Hi,
    You need a $-sign in front of values that are supposed to be interpreted as HEX. Then I suggest you spell out the pins instead of using constants - not that the constants won't work but it's much easier to read when it literally says which pins are being used - but that's just me. Ie:
    Code:
    SHIFTOUT PortB.2, PortB.3, 0, [$07, $2B,$02, $0C]
    Which counter isn't incrementing?

    The config has been covered numerous times.... If you're on a version prior to PBP3 (which I suspect you are) and want to set the CONFIG in your code you need to comment out the default CONFIG in .inc file for the chip you're using. If you search the forum you'll find several threads detailing exactly what to do.

    /Henrik.

    EDIT: Darrel beat me to it....

  4. #4
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Dohh too many hours at the keyboard !

    Hex:
    It was that way originally but I copied and pasted a new value from a calculator without thinking, then I was blinkered !

    In the program I do use alias but I removed them for the snippet line.

    Counting:
    The 'down' subroutine works perfectly.

    The 'up' routine will not increment the counter beyond 99 it rolls to zero. The Counter[1] (hundreds) is not incrementing.

    Config:
    I'm using 2.46 which I've had for ages. It has always accepted the config ok but now complains of overwriting address contents.
    I always assumed writing the config overrode the inc file as it always worked before.


    Overall, I'm trying to write my own routine to control a AD9850 DDS board.

    I have the board accepting a single frequency input word using the shiftout and next I need to get my head around the maths required to produce the 5 byte word from the formula. The DDS clock frequency in my case is 125,000,000

    The formula is:-
    5 byte Tuning word = (2^32 / DDS clock frequency in Hz) x Wanted Frequency in Hz

  5. #5
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    OK I have the config sorted.

    Up to now I've used external crystals so i had no problem but this time I wanted to use the internal osc on a 16f628. I've commented out the original and added my config line to the inc file for this project.

    I still can't see a problem with the "up" count routine. It rolls over at 99 and doesn't increment Counter[1]

    Have I done something silly. That wouldn't be unusual.

    I'm also having trouble with the SHIFTOUT line in operation, I seem to need it to loop at least once for the value to load. Not sure if that's the DDS board or a code quirk. After one loop where nothing happens, it will load a each frequency word straightaway.

    Code:
    dds:
          PAUSE 100
          SHIFTOUT ddsdata, ddsclock, 0 [$07, $2B,$02,$0C,$00]   ; send frequency word
          HIGH ddsload                                                                       ; load dds (turn on freq)
          LOW ddsload
          PAUSE 100
          SHIFTOUT ddsdata, ddsclock, 0 [$A0, $2B,$C2, $0C, $00]
          HIGH ddsload
          LOW ddsload
          goto dds

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


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Hi,
    I've tried your counting code here and it works fine. All I did was to run it in a FOR-NEXT loop 1000 times and sent the values over the USART each time thru the loop. When Counter[0] reaches 99 it rolls over to 0 and Counter[1] is incremented, and so on - just as expected. Take a look thru your program and make sure you aren't resetting Counter[1] by mistake somewhere.

    I have no idea about the DDS, but I'd try a proper reset cycle of it before trying to communicate with it.

    /Henrik.

  7. #7
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Thanks Henrik, I thought it should be working.

    I'll look closer to see if i reset Counter[1] although i don't think there is another reference to it in the rest of the code.

    The DDS board on switch on is reset automatically.

    I think I will experiment with using a small loop without display before the start of the program proper.

  8. #8
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Is it possible to use a string for the values in SHIFTOUT.

    I have freq bands values such as :-

    band:
    band1 = "$AA,$AA,$AA,$AA,$00"

    Would this work ?

    SHIFTOUT ddsdata, ddsclock, 0 [band1]

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


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Hi,
    No, at least not like that.
    You might want to take a look at this and perhaps this thread.

    /Henrik.

  10. #10
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Thanks Henrik,

    I've taken a different approach to sending the DDS Word. It now works fine in the test routine. I still had to add the two ddsloads at the beginning of code to 'wake up' the dds.

    The counting routine still steadfastly refuses to count up beyond 99, i've checked the code through and can't see anything that refers back to it.

    This is the code in progress so far. I'm using a asm routine as it is significantly faster for frequency update.

    I've yet to figure out how to generate the word value from the formula at the top of the code and display it correcty in frequency terms.

    I'm sure I read on the net someone had already done this in Pic Basic Pro but I can find no reference to code.

    Note: I left bits of info in for my own reference.

    Code:
    '****************************************************************
    '*  Name    : DDS Frequency Generator                           *
    '*  Author  : R J Lane G4NQX                                    *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 10/29/2012                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Uses ebay DDS board and rotary encoder            *
    '*          :                                                   *
    '****************************************************************
    
    ;Tuning word = (2^32 / DDS clock frequency in Hz) x Wanted Frequency in Hz
    ;Note:   2^32 = 4294967296 
    
    ;Gives 34.35947448 x freq wanted in Hz
    
    
    
    ;@__config _CP_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_INTRC_OSC_NOCLKOUT
    
    '                         Hardware Defines
    '                         ================
    '
    ;############################ LCD Display ############################
    
    Define LCD_DREG PORTB          ' Port for LCD Data
    Define LCD_DBIT 0              ' Use lower 4 bits of Port
    Define LCD_RSREG PORTB         ' Port for RegisterSelect (RS) bit
    Define LCD_RSBIT 6             ' Port Pin for RS bit
    Define LCD_RWBIT 5             ' Port Pin for RS bit
    Define LCD_EREG PORTB          ' Port for Enable (E) bit
    Define LCD_EBIT 4              ' Port Pin for E bit
    Define LCB_BITS 4              ' Using 4-bit bus
    Define LCD_LINES 2             ' Using 2 line Display
    Define LCD_COMMANDUS 2000
                                   ' Command Delay (uS)
    DEFINE LCD_DATAUS 50           ' Data Delay (uS)
    
    define OSC 04
    ;######################################################################
              
    ;##################### Control Buttons/Lines  #########################
         
    PB_1 var PortA.4              ' Take this pin low momentarily to change step
    PB_2 var PortA.3              ' Take this pin low momentarily to change band
    PB_3 var PortA.2              ' Take this pin low momentarily to RESET
    EncoderRight var PortA.1       ' rotary encoder pin
    EncoderLeft var PortA.0      ' rotary encoder pin
    
    
    ddsload var PortB.7           ' dds control word pin
    ddsdata var PortB.3           ' dds data input
    ddsclock var PortB.2          ' dds clock input
    
    ;#######################################################################
       
    fStep var byte     ; for step routine (later)
    fcount var byte
    Counter var word
    num var byte
    digitpos var byte        
    top var word
    x var byte
         
            CMCON=7      'sets 16f628 comparator pins to digital
            TRISA=%00011111       'Button & encoder inputs
     
          
    Counter = 0
    fcount = 0
    
    high ddsload    ;set ddsload 
    
    freq_0 var byte
    freq_1 var byte
    freq_2 var byte
    freq_3 var byte
    freq_4 var byte
    
    byte2send var byte
    bit_count var byte
    
    'CONFIGURE DISPLAY 
            pause 1000
            LCDOUT $FE,1    ' Clear screen
    
            ;lcdout $fe,$c0,dec5 counter        ; reset to zero on start
    
             pause 1000
           
             gosub band80m     ;required to kickstart dds ( Odd ?? )
             PAUSE 1000
             gosub band80m
            
    ddsfreq:
    
           ;
           ; TEST RUN  ############################################
           ;
           ;  
            lcdout $fe,$80,"160m" 
            lcdout $fe,$C0,"   1.800.000 Hz  "      
            GOSUB band160m
            PAUSE 15000
            
            lcdout $fe,$80," 80m"
            lcdout $fe,$C0,"   3.500.000 Hz  "
            GOSUB band80m
            PAUSE 15000
            
            lcdout $fe,$80," 60m"
            lcdout $fe,$C0,"  5.330.500 Hz  "
            GOSUB band60m
            PAUSE 15000
            
            lcdout $fe,$80," 40m"
            lcdout $fe,$C0,"   7.000.000 Hz  "
            GOSUB band40m
            PAUSE 15000
            
            lcdout $fe,$80," 30m"
            lcdout $fe,$C0,"  10.100.000 Hz  "
            GOSUB band30m
            PAUSE 15000
            
            lcdout $fe,$80," 20m"
            lcdout $fe,$C0,"  14.000.000 Hz  "
            GOSUB band20m
            PAUSE 15000
            
            lcdout $fe,$80," 17m"
            lcdout $fe,$C0,"  18.068.000 Hz  "
            GOSUB band17m
            PAUSE 15000
            
            lcdout $fe,$80," 15m"
            lcdout $fe,$C0,"  21.000.000 Hz  "
            GOSUB band15m
            PAUSE 15000
            
            lcdout $fe,$80," 12m"
            lcdout $fe,$C0,"  24.890.000 Hz  "
            GOSUB band12m
            PAUSE 15000
            
            lcdout $fe,$80," 10m"
            lcdout $fe,$C0,"  28.000.000 Hz  "
            GOSUB band10m
            PAUSE 15000
            
            LCDOUT $FE,1    ' Clear screen
            pause 10
            lcdout $fe,$c0,dec5 counter        ; reset to zero on start
            
            goto loop1
            
           ;
           ; TEST RUN  ############################################
           ;
           ;
          
    
    
    
    ;Rotary Encoder Code################################################
    
    loop1:
    if EncoderLeft=0 then                 'here is switch 1 of the rotary encoder
        ;counter = counter-1
        gosub down
    ; dds here
        gosub lcd
    endif
    
    if EncoderRight=0 then                 'here is switch 2 of the rotary encoder
        ;counter=counter+1
        gosub up
    ;dds here      
        gosub lcd
    endif
    
    goto loop1
    
    
    
    lcd:
    lcdout $fe,$c0,dec5 counter
    while (EncoderLeft=0 or EncoderRight=0):pause 10:wend
    return
    ;######################################################################
    
    
    up:
      counter[0]=counter[0]+1
    if counter[0]>99 then 
        counter[0]=0
         counter[1]=counter[1]+1
          if counter[1]>99 then
           counter[1]=0
            counter[2]=counter[2]+1
             if counter[2]>99 then
              counter[2]=0
               counter[3]=counter[3]+1
                if counter[3]>99 then
                 counter[3]=0     ;reset to zero
             endif
           endif
        endif 
     endif 
    return
    
    down:
      counter[0]=counter[0]-1
    if counter[0]<1 then 
        counter[0]=0
         counter[1]=counter[1]-1
         if counter[1]<1 then
          counter[1]=99
            counter[2]=counter[2]-1
             if counter[2]<1 then
              counter[2]=99
               counter[3]=counter[3]-1
                if counter[3]<1 then
                 counter[3]=99
             endif
           endif
        endif 
     endif 
    return
    
    
    ;band160m:      ;1.8 mhz
    ;freq_0 = $0E
    ;freq_1 = $B6
    ;freq_2 = $AF
    ;freq_3 = $03
    ;freq_4 = $00
    ;call  send_dds_word
    ;RETURN
    
    band160m:      ;1.8 mhz    TEST
    freq_0 = $E9
    freq_1 = $B7
    freq_2 = $AF
    freq_3 = $03
    freq_4 = $00
    call  send_dds_word
    RETURN
    
    band80m:       ;3.5 mhz
    freq_0 = $70
    freq_1 = $FE
    freq_2 = $2A
    freq_3 = $07
    freq_4 = $00
    call  send_dds_word 
    RETURN
    
    band60m:        ;5.3305 mhz
    freq_0 = $A1
    freq_1 = $B2
    freq_2 = $EA
    freq_3 = $0A
    freq_4 = $00
    call  send_dds_word
    RETURN 
    
    band40m:        ;7 mhz
    freq_0 = $E1
    freq_1 = $FC
    freq_2 = $55
    freq_3 = $0E
    freq_4 = $00
    call  send_dds_word
    RETURN 
    
    band30m:        ;10.1 mhz
    freq_0 = $A4
    freq_1 = $44
    freq_2 = $AF
    freq_3 = $14
    freq_4 = $00
    call  send_dds_word
    RETURN 
    
    band20m:        ;14 mhz
    freq_0 = $C2
    freq_1 = $F9
    freq_2 = $AB
    freq_3 = $1C
    freq_4 = $00
    call  send_dds_word
    RETURN
    
    band17m:        ;18.068 mhz
    freq_0 = $48
    freq_1 = $C3
    freq_2 = $00
    freq_3 = $25
    freq_4 = $00
    call  send_dds_word
    RETURN 
    
    band15m:         ;21 mhz
    freq_0 = $A4
    freq_1 = $F6
    freq_2 = $01
    freq_3 = $2B
    freq_4 = $00
    call  send_dds_word
    RETURN 
    
    band12m:         ;24.890 mhz
    freq_0 = $97
    freq_1 = $6D
    freq_2 = $F9
    freq_3 = $32
    freq_4 = $00
    call  send_dds_word
    RETURN 
    
    band10m:         ;28 mhz
    freq_0 = $85
    freq_1 = $F3
    freq_2 = $57
    freq_3 = $39
    freq_4 = $00
    call  send_dds_word 
    RETURN
    
      
    ; test freqs:
    ; Zero = $00,$00,$00,$00,$00
    ; 1Hz  = $22,$00,$00,$00,$00  - tested
    ;
    ; ############ 3 line dds freq routine in pic basic ###########################
    ;shiftout ddsdata,ddsclock,4,[$0E,$B6,$AF,$03,$00]   ; 1.8MHZ
    ;high ddsload                                        ;tuning word hex order reversed
    ;low ddsload 
    ;############################################################################## 
    
    asm
    _send_dds_word     
            movlw   _freq_0                 
            movwf   FSR          
    _next_byte
            movf    INDF,w             
            movwf   _byte2send          
            movlw   0x08              
            movwf   _bit_count 
    _next_bit
            rrf     _byte2send,f       
            btfss   STATUS,C          
            goto    _send0             
            bsf     PORTB,3                                    
            bsf     PORTB,2                              
            bcf     PORTB,2                                                 
            goto    _break                    
    _send0
            bcf     PORTB,3                                       
            bsf     PORTB,2                             
            bcf     PORTB,2                                                        
    _break
            decfsz  _bit_count,f       
            goto    _next_bit          
            incf    FSR,f             
            movlw   _freq_4+1        
            subwf   FSR,w              
            btfss   STATUS,C          
            goto    _next_byte         
            bsf     PORTB,7                
            bcf     PORTB,7                                                                    
    endasm
    
    return
    
    
    end     ; program end point

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


    Did you find this post helpful? Yes | No

    Default Re: Compiling and code oddities

    Hi,
    I think perhap this might have something to do with it:
    Code:
    fStep var byte     ; for step routine (later)
    fcount var byte
    Counter var word
    num var byte
    digitpos var byte        
    top var word
    x var byte
    The way you're using Counter in the code is as an array and it needs to be declared as such
    Code:
    Counter VAR BYTE[4]   'Four byte array, Counter[0]...[3]
    /Henrik.

Similar Threads

  1. Problem compiling EasyHID code
    By mindthomas in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th August 2010, 20:46
  2. compiling 12f675
    By MOUNTAIN747 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th November 2009, 01:22
  3. Replies: 14
    Last Post: - 31st March 2009, 12:04
  4. Replies: 1
    Last Post: - 21st February 2008, 15:36
  5. I need HELP with compiling!!!!!!
    By kenny_m in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th February 2008, 20:34

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