Jump to content
43oh

Recommended Posts

You know what they say about opinions, do you? :smile:

 

 

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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

Link to post
Share on other sites

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

Link to post
Share on other sites

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.

Link to post
Share on other sites

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?

Link to post
Share on other sites

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

Link to post
Share on other sites

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! 

Link to post
Share on other sites

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?

Link to post
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.

×
×
  • Create New...