roadrunner84 466 Posted July 1, 2013 Share Posted July 1, 2013 You know what they say about opinions, do you? Yes, CCS doesn't have itoa, only ltoa Convert 1024: ltoa - 3,630 clock cycles intToAscii (rr84) - 400 clock cycles (you may want to check your code, I didn't get expected results) binaryToASCII (robg) - 100 clock cycles Convert 15: Itoa - 1,870 intToAscii - 380, no result binaryToASCII - 110 I had a bug indeed, replaced the && with || to fix it. Also I added the exception for the value 0. I guess my solution is a little slower (I intentionally did not optimise for speed, but for readability). I prefer (yes, that's an opinion) to have readable code over fast code. I could do some optimisations towards speed, but that sacrifices (some) readability. Quote Link to post Share on other sites
RobG 1,892 Posted July 1, 2013 Share Posted July 1, 2013 upsssss! so i need to add a positive voltage, right? Pretty much, you have to offset your input. I guess my solution is a little slower (I intentionally did not optimise for speed, but for readability). I prefer (yes, that's an opinion) to have readable code over fast code. I could do some optimisations towards speed, but that sacrifices (some) readability. I too prefer readable code, but there are situations when you just can't afford to use it. Quote Link to post Share on other sites
roadrunner84 466 Posted July 1, 2013 Share Posted July 1, 2013 This one should be somewhat faster void intToAsciiFast(unsigned short num, char* text) { char* index = text; const unsigned short decDigits[5] = {10000, 1000, 100, 10, 1}; if (num == 0) { text[0] = '0'; text[1] = 0; return; } for(const unsigned short* digits = decDigits; digits != decDigits + 5; ++digits) { *index = '0'; while(num >= *digits) { num -= *digits; ++*index; } if ((index != text) || (*index != '0')) index++; } *index = 0; } Unrolling the inner loop could speed thing up a bit too, but I guess I can't do that in C. Quote Link to post Share on other sites
RobG 1,892 Posted July 1, 2013 Share Posted July 1, 2013 Yep, works now. 352-354 clocks. Quote Link to post Share on other sites
muzay 0 Posted July 1, 2013 Author Share Posted July 1, 2013 Pretty much, you have to offset your input. I too prefer readable code, but there are situations when you just can't afford to use it. Adding an offset voltage seems working, but somehow it gives me 0000 in every 10 sec recording. Using your ascii code might be more useful, and i'll try to implete it into my code, thanks Quote Link to post Share on other sites
RobG 1,892 Posted July 1, 2013 Share Posted July 1, 2013 @@muzay, here are some examples of level shifters you can use (figure 6.11 and 6.12) muzay 1 Quote Link to post Share on other sites
muzay 0 Posted July 1, 2013 Author Share Posted July 1, 2013 @@muzay, here are some examples of level shifters you can use (figure 6.11 and 6.12) Thank you, i did the same circuitry, i hope it works... Quote Link to post Share on other sites
muzay 0 Posted July 2, 2013 Author Share Posted July 2, 2013 Yes, CCS doesn't have itoa, only ltoa Convert 1024: ltoa - 3,630 clock cycles intToAscii (rr84) - 400 clock cycles (you may want to check your code, I didn't get expected results) binaryToASCII (robg) - 100 clock cycles Convert 15: Itoa - 1,870 intToAscii - 380, no result binaryToASCII - 110 I have found my real trouble! ok, i summarize what i did before. Im sampling an anaolog data (data includes 0.1-200 Hz and -1 to 1 volts) using DAC. I used offset circuit to be able to read negative values. While testing the MSP430G2553, It works fine for different DC voltage samplings but when i used AC (sinusoidal) signal, i realized that the code gives me 8-9 data per second! whereas i need at least 500 or more data! my conversion is too slow! :-( Beein a poor coder, i need a real help, i'm in trouble...upss Quote Link to post Share on other sites
roadrunner84 466 Posted July 2, 2013 Share Posted July 2, 2013 You should be able to get 200 ksps. Probably your UART is slowing things down. Considering your UART runs at 9600Bdps, the data rate is 960 characters per second. Assuming you're writing a 4 digit number and a new-line you're using 6 characters per measurement. The maximum data rate over UART is then about 150 measurements. muzay 1 Quote Link to post Share on other sites
muzay 0 Posted July 2, 2013 Author Share Posted July 2, 2013 You should be able to get 200 ksps. Probably your UART is slowing things down. Considering your UART runs at 9600Bdps, the data rate is 960 characters per second. Assuming you're writing a 4 digit number and a new-line you're using 6 characters per measurement. The maximum data rate over UART is then about 150 measurements. I even could not have 150 samples. By increasing the baudrate, i could have enough sample over uart, right? Quote Link to post Share on other sites
roadrunner84 466 Posted July 2, 2013 Share Posted July 2, 2013 Yes, but then you'd need to use a separate serial cable. The UART driver on the Launchpad (not the MSP430, but the emulation part) can only do 9600 baud max. muzay 1 Quote Link to post Share on other sites
muzay 0 Posted July 2, 2013 Author Share Posted July 2, 2013 Yes, but then you'd need to use a separate serial cable. The UART driver on the Launchpad (not the MSP430, but the emulation part) can only do 9600 baud max. Im using a blueetooth module, not a cable actually. I realized that i have button debounce delay, i made it only 10 cycle, but it gave me only 10 data per second. So the part that im trying to contert integer value of ADC to char is slow for me, i sould try the other version, integer to ASCII ones..and I should change the baudrate of my code and also baudrate of B/T module (no idea how to do). lets try if i can impelement it into my code, lol.. thank you Quote Link to post Share on other sites
RobG 1,892 Posted July 2, 2013 Share Posted July 2, 2013 Change your clock to 16MHz ( BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; ) and update UCA0BR0, UCA0BR1, and anything else that relies on the clock accordingly. This will speed up some tasks, like int to ASCII conversion. muzay 1 Quote Link to post Share on other sites
muzay 0 Posted July 2, 2013 Author Share Posted July 2, 2013 Change your clock to 16MHz ( BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; ) and update UCA0BR0, UCA0BR1, and anything else that relies on the clock accordingly. This will speed up some tasks, like int to ASCII conversion. Thanks @@RobG, it worked pretty well for now, ill try if it is able to sample my data! Quote Link to post Share on other sites
muzay 0 Posted July 8, 2013 Author Share Posted July 8, 2013 Change your clock to 16MHz ( BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; ) and update UCA0BR0, UCA0BR1, and anything else that relies on the clock accordingly. This will speed up some tasks, like int to ASCII conversion. @@RobG, i could somehow achieve to sample my data and send it over uart via bluetooth module. Thank you all helping me. I realized that with launchpad 2553 i cannot achieve more than 9600 baudrate! When i want to use 38400 baudrate, should i change my launchpad? is it really not possible to speed it up? Quote Link to post Share on other sites
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.