Compiling and code oddities


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    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.

  2. #2
    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]

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


    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.

  4. #4
    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

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    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