Jump to content

error compiling c app


moxi
 Share

Recommended Posts

  • Replies 106
  • Created
  • Last Reply

Top Posters In This Topic

hi,

another (stupid) question:

could you explain what mean

"AOUT_Load2SR(aout_value[0] | (0x3000 | (0 << 14)), aout_value[4] | (0x3000 | (0 << 14)));"

(i've learn how work the "if" fonction, what means " ll " and "<<") ; i know that "AOUT_Load2SR(aout_value[0]" call AOUT_Load2SR, that's ok, but i can't find any information about the symbol "|" ...

Link to comment
Share on other sites

moxi,

please read the link that stryd posted carefully.

bitshifting and bitmanipulating is a bit strange (;D) at first, you have to get used to it to use it well.

in short:

256 >> 2  moves 256 2 bits to the right which is the same as a division (value gets lower as bits "shrink"):

(value / 2) * 2

256 << 2  where in contrast each bitshift to the left is the same as a multiplication (value gets greater as the bits "expand"):

(value * 2) * 2

| (OR) and & (AND) are bitshifting operators that are described in depth by stryd_one on the page he's linking!

the best is, to get yourself either a programmer's calculator where you can see what it does immediately and/or install CH, a Console based C-Evaluator (that means you can type "unsignd char c = 32 >> 1;" and see the result immediately!

When working with MIOS and PICs you'll have to learn about this anyway...

Best regards,

Michael

Link to comment
Share on other sites

hi,

i'm ok with the operators, but (excuse me if i'm not enough clever) when i read:

(aout_value[0] | (0x3000

i understand that aout_value is ored with 0x3000

but when i read:

(0 << 14)

first i don't understand first where come from this "0", secondly, i don't understand why we are bitschifting "0"

i'm learning, feel free to don't reply if you think it's obvious...

Link to comment
Share on other sites

AOUT_Load2SR(aout_value[0] | (0x3000 | (0 << 14))

I can imagine, that it would make sense, if you could exchange the 0 by another number, then you need the << 14 to make a 14-bit value out of it... maybe that 0 is connected to something hardware-related?

...and you're not exactly bitshifting '0', see the brackets: you're ORing 0x3000 with a 14 bit-value

Anyway, it does not hurt...

...and it shows you that you're dealing with a 14-bit number:

it is crucial in all cases to keep track of the variable's bit-sizes and convert it if necessary to an other expected size. I don't know how often it happen to me that a function did not do or return what I expected, because I forgot to typecast it explicitely!

Link to comment
Share on other sites

I must admit that I'm not too sure what bitshifting 0 does.... It just seems to be 0 ?

In the other lines it's 1, 2, 3  - it just selects the output channel

I must say, in the meantime I find it funny which details can be discussed on a code I hacked in within 10 minutes ;-) Most of this stuff is just "standard programming". Some lines might look strange when they are out of context, but they make sense when you see the whole code and compare it with the MAX525 datasheet.

Best Regards, Thorsten.

Link to comment
Share on other sites

I must say, in the meantime I find it funny which details can be discussed on a code I hacked in within 10 minutes ;-) Most of this stuff is just "standard programming". Some lines might look strange when they are out of context, but they make sense when you see the whole code and compare it with the MAX525 datasheet.

hehehe I know what you mean mate, I was thinking that to myself too :) I think we spent a great deal of time and effort in attempting to reverse-engineer the working of your existing drivers, instead of just reading the datasheet and making it work like the timing diagrams. The lesson I learned here is that your existing code will help us, but we should get the basic idea in our head first, so that we don't get distracted by the reverse engineering process, and miss the point entirely...

IE: Read the datasheet, then write the code....not....Write the code, and then consult TK's code to find out why our code doesnt work, and then check the datasheet, then write some more code ;)

Link to comment
Share on other sites

what i've understood from the datasheet of max525 and 74hc595( if i'm right),

it's that the 74hc595 need 8 bit value and the max525 need 16bit value, but in the 16 bit , only 12 are used to hold the value...

but i'm still lost...

Link to comment
Share on other sites

Thats correct. The usage of 74HC595 is easier, because all bits are directly transfered to the output, there is no command register, and no channel multiplexer like on the MAX525

This means in other words: when you shift in 8 bits, and toggle the RCLK, the bits will be visible at the output ports.

When two 74HC595 are chained, like on the AOUT_LC module, you need to shift in 16 bits, and toggle RCLK thereafter.

And when multiple AOUT_LC modules are chained (which means n*2 74HC595 chained), you need to shift in n*2*8 bits and toggle RCLK thereafter.

This can be very easily debugged.

Just replace all the stuff inside AOUT_Update with a single call of the AOUT_Load2SR function.

I don't know, if you are using 16 or 32 bit shifting in the meantime, but at the beginning just write following:

void AOUT_Update(void)
{
  AOUT_Load2SR(0x8080, 0x8080);
}
[/code]

now you should see 2.5V at the R-2R ladder output.

(I assume that you are using the 2*8 bit configuration of the AOUT_LC module)

When you are writing:

  AOUT_Load2SR(0x4040, 0x4040);

you should see 1.25V

Does it work?

Best Regards, Thorsten.

Link to comment
Share on other sites

After the values are shifted, which logic levels do you measure at the output pins of the 74HC595s?

With 0x8080,0x8080 I would expect:

O7=1

O6=0

O5=0

O4=0

O3=0

O2=0

O1=0

O 0=0

With 0x4040,0x4040 I would expect:

O7=0

O6=1

O5=0

O4=0

O3=0

O2=0

O1=0

O 0=0

etc.

Does AOUT_Load2SR shift the registers 32 or 16 times?

Best Regards, Thorsten.

Link to comment
Share on other sites

With 0x8080,0x8080:

first sr:

O7=0

O6=0

O5=0

O4=0

O3=0

O2=0

O1=0

O 0=0

second 74hc595

O7=1

O6=1

O5=0

O4=0

O3=0

O2=0

O1=0

O 0=0

third same as first, fourth same as second.

with 0x4040,0x4040:

first:

O7=0

O6=0

O5=0

O4=0

O3=0

O2=0

O1=0

O 0=0

second:

O7=0

O6=0

O5=1

O4=1

O3=0

O2=0

O1=0

O 0=0

third same as first, fourth same as second.

i shift the registers 16 times

Link to comment
Share on other sites

A shorter form to write this is:

76543210 76543210 76543210 76543210

00000000 11000000 00000000 00110000

Expected pattern is:

76543210 76543210 76543210 76543210

10000000 10000000 10000000 10000000

How does the AOUT_Load2SR routine look like in the meantime?

Best Regards, Thorsten.

Link to comment
Share on other sites

unsigned char loop_ctr;    // loop counter

unsigned int aout_sr0; // chain data

unsigned int aout_sr1;

void AOUT_Load2SR(unsigned int sr0_value, unsigned int sr1_value)

{

  aout_sr0 = sr0_value;

  aout_sr1 = sr1_value;

__asm

        bcf    CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK ; clear clock COPIED FROM MBCV DRIVER

;; bcf AOUT_LAT_CS, AOUT_PIN_CS ; activate chip select NOT NEEDED FOR AOUT_LC

;; I believe that the below might be able to be ignored for the AOUT_LC?

;; you will notice that the instructions are sometimes arranged

;; in a special order to ensure proper output signals - for example:

;; between a rising and a falling SCLK edge there is at least one

;; other instruction to ensure that the high pulse of the SCLK

;; is longer than 100 nS (the MAX525 datasheet specifies at least 40 nS)

banksel _loop_ctr

movlw 16            ; init loop counter ONLY 16 BIT FOR _LC

movwf _loop_ctr, 0

;; This is the same as the original AOUT driver with the names changed, and the latching copied from the MBCV

AOUT_Load2SR_Loop:

banksel _aout_sr0

bcf CV_AOUT_LC_LAT_DOUT, CV_AOUT_LC_PIN_DOUT ; set DOUT depending on current MSB

btfsc _aout_sr1+1, 7, 0

bsf CV_AOUT_LC_LAT_DOUT, CV_AOUT_LC_PIN_DOUT

rlcf _aout_sr0+0, F, 0 ; start to shift the 16-bit value

rlcf _aout_sr0+1, F, 0 ; second step for the 16-bit shift

rlcf _aout_sr1+0, F, 0 ; third step for the 16-bit shift

rlcf _aout_sr1+1, F, 0 ; last step for the 16-bit shift

bsf CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK ; rising clock edge MOVED FOR AOUT_LC DRIVER

bcf CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK ; falling clock edge

    bsf CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK ; rising clock edge MOVED FOR AOUT_LC DRIVER

bcf CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK ; falling clock edge

banksel _loop_ctr

decfsz _loop_ctr, F, 0 ; loop 16 times ONLY 16 BIT FOR _LC

bra AOUT_Load2SR_Loop

    bsf    CV_AOUT_LC_LAT_RCLK, CV_AOUT_LC_PIN_RCLK ; latch SID values

bcf CV_AOUT_LC_LAT_DOUT, CV_AOUT_LC_PIN_DOUT ; clear out pin (standby)

    bcf    CV_AOUT_LC_LAT_RCLK, CV_AOUT_LC_PIN_RCLK ; release latch

_

Link to comment
Share on other sites

Seems that you are accessing the wrong registers, they have a "0" access type instead of "BANKED" ("1") like in the original and like in stryd_one's example.

This explains also, why you don't see the expected pattern at the DOUTs

try this, it might work better:


unsigned char loop_ctr;    // loop counter
unsigned int aout_sr0; // chain data
unsigned int aout_sr1;
void AOUT_Load2SR(unsigned int sr0_value, unsigned int sr1_value)
{
  aout_sr0 = sr0_value;
  aout_sr1 = sr1_value;

__asm
        bcf    CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK  ; clear clock  COPIED FROM MBCV DRIVER
  ;; bcf  AOUT_LAT_CS, AOUT_PIN_CS  ; activate chip select  NOT NEEDED FOR AOUT_LC

  ;; I believe that the below might be able to be ignored for the AOUT_LC?
  ;; you will notice that the instructions are sometimes arranged
  ;; in a special order to ensure proper output signals - for example:
  ;; between a rising and a falling SCLK edge there is at least one
  ;; other instruction to ensure that the high pulse of the SCLK
  ;; is longer than 100 nS (the MAX525 datasheet specifies at least 40 nS)

  banksel _loop_ctr
  movlw  32            ; init loop counter  FOR 2 AOUT_LC modules
  movwf  _loop_ctr, BANKED

  ;; This is the same as the original AOUT driver with the names changed, and the latching copied from the MBCV
AOUT_Load2SR_Loop:
  banksel _aout_sr0
  bcf  CV_AOUT_LC_LAT_DOUT, CV_AOUT_LC_PIN_DOUT  ; set DOUT depending on current MSB
  btfsc  _aout_sr1+1, 7, BANKED
  bsf  CV_AOUT_LC_LAT_DOUT, CV_AOUT_LC_PIN_DOUT
  rlcf  _aout_sr0+0, F, BANKED      ; start to shift the 16-bit value
  rlcf  _aout_sr0+1, F, BANKED      ; second step for the 16-bit shift

  rlcf  _aout_sr1+0, F, BANKED      ; third step for the 16-bit shift
  rlcf  _aout_sr1+1, F, BANKED      ; last step for the 16-bit shift

  bsf  CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK  ; rising clock edge  MOVED FOR AOUT_LC DRIVER
  bcf  CV_AOUT_LC_LAT_SCLK, CV_AOUT_LC_PIN_SCLK  ; falling clock edge

  banksel _loop_ctr
  decfsz  _loop_ctr, F, BANKED      ; loop 32 times
  bra  AOUT_Load2SR_Loop


    bsf    CV_AOUT_LC_LAT_RCLK, CV_AOUT_LC_PIN_RCLK  ; latch SID values
  bcf  CV_AOUT_LC_LAT_DOUT, CV_AOUT_LC_PIN_DOUT  ; clear out pin (standby)
    bcf    CV_AOUT_LC_LAT_RCLK, CV_AOUT_LC_PIN_RCLK  ; release latch

}

[/code]

Best Regards, Thorsten.

Link to comment
Share on other sites

ok,

i don't know why , but the banked was causing the error "symbol not previously defined", so i've replaced by 0 in my first file, now i've corrected that (i've replaced the banked by "1").

the pattern i get now (with 0x8080,0x8080):

76543210 76543210 76543210 76543210

00000000 11000000 00000000 11000000

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share


×
×
  • Create New...