Jump to content
DeepBlueSky

Low power Geiger counter with MSP430G2553 (Last updated: May 07, 2015)

Recommended Posts

Use long int (or long unsigned) and use `ld'  (lowercase ell d )instead of `d' in the format string for sprintf. `d' is standart int. `ld' is long int.

 

 

The only info sprintf has about the type is from the format string, so if you spec standard int, whatever the param is, even if it is a long, will be interpreted as a standard int.

Share this post


Link to post
Share on other sites

Ah right, agreed, didn't fully read the first post :D

 

I think %lu may work too for going up to ~4 billion with unsigned long's.

Thanks, you are right, it goes up to 2^32 ? 1, whereas ld doesn't.

void loop() {
  counts=4294967296-1;
  sprintf(string,"%ld",counts);
  myScreen.text(0,0,string);
  sprintf(string,"%lu",counts);
  myScreen.text(0,1,string);
  delay(100000);
}

Share this post


Link to post
Share on other sites

don' bother float.... If the value won't overflow (less than about 650*10^6 decimal), mult by 3 than divide by 100. The mult by three can be done as `(i<<1)+i'. This will give an int value truncated.

 

 

You can avoid the div by 100 completely. After the sprintf, insert a decimal point before the last two digits. This requires that the value is >= 100 decimal, or there won't BE anything before the last two digits. This can be handled by forcing leading zeroes for 3 dig if value is <100 (using a condition and two sprintf's... one for each case)

Share this post


Link to post
Share on other sites

 

Hi all,

 

2. Problem: how to convert an number into a float point number, e.g. if I want to multiply counts variable by 0.03 and display it?

 

 

I take it the built-in sprintf doesn't handle floats?

If want to do it without using floats - could do something like:

unsigned long long count3 = 3 * counts;
sprintf(string,"%lu", (unsigned long)(count3/100) );
myScreen.text(0,1,string);
add code to print the decimal point in the right position
sprintf(string,"%u", (unsigned) (count3 % 100));
print this in the appropriate location

That is just the skeleton - would have to fill in the printing code (and conditionals to handle 0 fractional part, etc.)

Share this post


Link to post
Share on other sites

The compensation function works fine :) Thank you for sharing it.

407387 CPM its non compensated value triggered by several Am-241 pieces placed on SBT-11 mica window, see the photos. The software displays compensated dose rate of 8.00mSv/h with 190uS dead time and 0.0057 conversion fator.

post-45578-0-26353100-1429368058_thumb.jpg

post-45578-0-44471000-1429368063_thumb.jpg

Share this post


Link to post
Share on other sites

The compensation function works fine :) Thank you for sharing it.

407387 CPM its non compensated value triggered by several Am-241 pieces placed on SBT-11 mica window, see the photos. The software displays compensated dose rate of 8.00mSv/h with 190uS dead time and 0.0057 conversion fator.

 

Thanks :)

I'm not sure but I think compensating 407387 CPM with 190

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×