Compiling and code oddities


Closed Thread
Results 1 to 11 of 11

Hybrid View

  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,604


    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,604


    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.

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