DeepBlueSky 8 Posted December 11, 2014 Share Posted December 11, 2014 Last updated: May 07, 2015 May 07: added SBM-20 background CPM value vs 1kg potassium salt and python code to log the data. April 26: added deadtime image. April 23: updated to 75 paodaf 1 Quote Link to post Share on other sites
cubeberg 540 Posted December 11, 2014 Share Posted December 11, 2014 @@DeepBlueSky - **edit -that's what I get for not reading your code. Looks like there might be an issue with sprintf - https://github.com/energia/Energia/issues/249 Maybe try switching to unsigned int which holds up to ~65k? Quote Link to post Share on other sites
DeepBlueSky 8 Posted December 11, 2014 Author Share Posted December 11, 2014 Changing to "unsigned int counts;" doesn't help. Quote Link to post Share on other sites
enl 227 Posted December 11, 2014 Share Posted December 11, 2014 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. DeepBlueSky and cubeberg 2 Quote Link to post Share on other sites
DeepBlueSky 8 Posted December 11, 2014 Author Share Posted December 11, 2014 Thanks, this helped to solve first of the two problems Quote Link to post Share on other sites
spirilis 1,265 Posted December 11, 2014 Share Posted December 11, 2014 Isn't there a "%u" option to tell sprintf/printf/etc. to interpret it as unsigned? cubeberg 1 Quote Link to post Share on other sites
DeepBlueSky 8 Posted December 11, 2014 Author Share Posted December 11, 2014 Isn't there a "%u" option to tell sprintf/printf/etc. to interpret it as unsigned? If I try %u it only goes up to 2^16, if I use %ld it goes up to 10 digits or so, so much better. Quote Link to post Share on other sites
spirilis 1,265 Posted December 11, 2014 Share Posted December 11, 2014 If I try %u it only goes up to 2^16, if I use %ld it goes up to 10 digits or so, so much better. Ah right, agreed, didn't fully read the first post I think %lu may work too for going up to ~4 billion with unsigned long's. DeepBlueSky 1 Quote Link to post Share on other sites
DeepBlueSky 8 Posted December 11, 2014 Author Share Posted December 11, 2014 Ah right, agreed, didn't fully read the first post 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); } Quote Link to post Share on other sites
enl 227 Posted December 11, 2014 Share Posted December 11, 2014 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) DeepBlueSky 1 Quote Link to post Share on other sites
igor 163 Posted December 11, 2014 Share Posted December 11, 2014 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.) DeepBlueSky and bluehash 2 Quote Link to post Share on other sites
DeepBlueSky 8 Posted December 12, 2014 Author Share Posted December 12, 2014 Updated first post with proper function now and added images, enjoy Quote Link to post Share on other sites
paodaf 2 Posted April 18, 2015 Share Posted April 18, 2015 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. bluehash and DeepBlueSky 2 Quote Link to post Share on other sites
DeepBlueSky 8 Posted April 20, 2015 Author Share Posted April 20, 2015 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 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.