moxi Posted August 3, 2006 Author Report Share Posted August 3, 2006 ok, it's the purpose of the CS/RCLK line that change..i will go on.... Quote Link to comment Share on other sites More sharing options...
moxi Posted August 4, 2006 Author Report Share Posted August 4, 2006 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 "|" ... Quote Link to comment Share on other sites More sharing options...
moxi Posted August 4, 2006 Author Report Share Posted August 4, 2006 btw: now my aout_lc output value, not the good ones ,but it's already a good things ... :) Quote Link to comment Share on other sites More sharing options...
stryd_one Posted August 4, 2006 Report Share Posted August 4, 2006 i can't find any information about the symbol "|" ...http://www.midibox.org/forum/index.php?topic=6981.msg45101#msg45101 :)Good to hear that it's behaving :) Let us know if you need a hand with the values. Quote Link to comment Share on other sites More sharing options...
moxi Posted August 4, 2006 Author Report Share Posted August 4, 2006 ok,so"AOUT_Load2SR(aout_value[0] | (0x3000" set to 1 the bits 15 and 16now ,what mean the "0" in the next expression "(0 << 14)) (to what is applied the << ? Quote Link to comment Share on other sites More sharing options...
moxi Posted August 4, 2006 Author Report Share Posted August 4, 2006 does that mean that the result of "aout_value[0] | (0x3000" is shifted? Quote Link to comment Share on other sites More sharing options...
audiocommander Posted August 4, 2006 Report Share Posted August 4, 2006 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) * 2256 << 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 Quote Link to comment Share on other sites More sharing options...
moxi Posted August 4, 2006 Author Report Share Posted August 4, 2006 hi,i'm ok with the operators, but (excuse me if i'm not enough clever) when i read:(aout_value[0] | (0x3000i understand that aout_value is ored with 0x3000but 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... Quote Link to comment Share on other sites More sharing options...
audiocommander Posted August 4, 2006 Report Share Posted August 4, 2006 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-valueAnyway, 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! Quote Link to comment Share on other sites More sharing options...
stryd_one Posted August 4, 2006 Report Share Posted August 4, 2006 install CH, a Console based C-EvaluatorNice, that's a handy tool! Thx AC.I must admit that I'm not too sure what bitshifting 0 does.... It just seems to be 0 ? Quote Link to comment Share on other sites More sharing options...
audiocommander Posted August 4, 2006 Report Share Posted August 4, 2006 Nice, that's a handy tool! Thx AC.:)ps: as it's hard to find, see http://www.softintegration.comand dl only the free version, because there's a commercial version, too!(woah :o ; I just read it can be integrated into TextWranger... that's cooool 8) ) Quote Link to comment Share on other sites More sharing options...
TK. Posted August 4, 2006 Report Share Posted August 4, 2006 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 channelI 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. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted August 5, 2006 Report Share Posted August 5, 2006 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 ;) Quote Link to comment Share on other sites More sharing options...
moxi Posted August 6, 2006 Author Report Share Posted August 6, 2006 i'm definitively out... :(if someone want to do the job, explaining how and why...that will be a great lesson... Quote Link to comment Share on other sites More sharing options...
stryd_one Posted August 6, 2006 Report Share Posted August 6, 2006 So is it still like before? It works but loads incorrect values? Quote Link to comment Share on other sites More sharing options...
moxi Posted August 6, 2006 Author Report Share Posted August 6, 2006 yes... Quote Link to comment Share on other sites More sharing options...
moxi Posted August 6, 2006 Author Report Share Posted August 6, 2006 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... Quote Link to comment Share on other sites More sharing options...
TK. Posted August 6, 2006 Report Share Posted August 6, 2006 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 MAX525This 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.25VDoes it work?Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
moxi Posted August 6, 2006 Author Report Share Posted August 6, 2006 hi,no,with 0x8080i get 0V on output 1 and 3, and 7.5V on 2 and 4with 0x4040i get 0V on output 1 and 3, and 1,50 on 2 and 4my outputs are 8/8 bit and 8/8bit, range from oV to 10v Quote Link to comment Share on other sites More sharing options...
TK. Posted August 6, 2006 Report Share Posted August 6, 2006 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=1O6=0O5=0O4=0O3=0O2=0O1=0O 0=0With 0x4040,0x4040 I would expect:O7=0O6=1O5=0O4=0O3=0O2=0O1=0O 0=0etc.Does AOUT_Load2SR shift the registers 32 or 16 times?Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
moxi Posted August 6, 2006 Author Report Share Posted August 6, 2006 With 0x8080,0x8080:first sr:O7=0O6=0O5=0O4=0O3=0O2=0O1=0O 0=0second 74hc595O7=1O6=1O5=0O4=0O3=0O2=0O1=0O 0=0third same as first, fourth same as second.with 0x4040,0x4040:first:O7=0O6=0O5=0O4=0O3=0O2=0O1=0O 0=0second:O7=0O6=0O5=1O4=1O3=0O2=0O1=0O 0=0third same as first, fourth same as second.i shift the registers 16 times Quote Link to comment Share on other sites More sharing options...
TK. Posted August 6, 2006 Report Share Posted August 6, 2006 A shorter form to write this is:76543210 76543210 76543210 7654321000000000 11000000 00000000 00110000Expected pattern is:76543210 76543210 76543210 7654321010000000 10000000 10000000 10000000How does the AOUT_Load2SR routine look like in the meantime?Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
moxi Posted August 6, 2006 Author Report Share Posted August 6, 2006 unsigned char loop_ctr; // loop counterunsigned int aout_sr0; // chain dataunsigned 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 MBCVAOUT_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_ Quote Link to comment Share on other sites More sharing options...
TK. Posted August 6, 2006 Report Share Posted August 6, 2006 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 DOUTstry this, it might work better:unsigned char loop_ctr; // loop counterunsigned int aout_sr0; // chain dataunsigned 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 MBCVAOUT_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. Quote Link to comment Share on other sites More sharing options...
moxi Posted August 6, 2006 Author Report Share Posted August 6, 2006 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 7654321000000000 11000000 00000000 11000000 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.