CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Tabulation

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Calamar



Joined: 07 Sep 2003
Posts: 60
Location: Buenos Aires (Argentina)

View user's profile Send private message Send e-mail MSN Messenger

Tabulation
PostPosted: Mon May 29, 2006 7:24 am     Reply with quote

Someone know how to improve this:

(clock = 10 mhz, pulseTicks = width pulse,
rateFactor = 1 * 2 500 000
or
rateFactor = 60 * 2 500 000
or
rateFactor = 3600 * 2 500 000
or
rateFactor = 86400 * 2 500 000)




Code:
   if(timeUnitBuffer != timeUnit)
   {
      timeUnitBuffer = timeUnit;
      switch(timeUnit)
      {
      case 0:
         rateFactor = 250000000.0 / kFactor;
      break;
      case 1:
         rateFactor = 150000000000.0 / kFactor;
      break;
      case 2:
         rateFactor = 900000000000.0 / kFactor;
      break;
      case 3:
         rateFactor = 21600000000000.0 / kFactor;
      break;
      default:
      break;
      }
   }
      rate = rateFactor / (float) pulseTicks;

      if( rate > 99999.0 )
         sprintf(strLineB,"   99999 %s/%c", strVolumeUnit[volumeUnit], strTimeUnit[timeUnit]); 
   
      else
      if( rate >= 1000.0 ) 
      sprintf(strLineB,"      %5.0f %s/%c",rate, strVolumeUnit[volumeUnit], strTimeUnit[timeUnit]);

      else
      if (rate >= 100.0)
      sprintf(strLineB,"      %3.1f %s/%c", rate, strVolumeUnit[volumeUnit], strTimeUnit[timeUnit]);

      else
      if (rate >= 10.0)
      sprintf(strLineB,"      %2.2f %s/%c", rate, strVolumeUnit[volumeUnit], strTimeUnit[timeUnit]);

      else
      if (rate > 0.0009)
      sprintf(strLineB,"      %1.3f %s/%c", rate, strVolumeUnit[volumeUnit], strTimeUnit[timeUnit]);
   
      else
         sprintf(strLineB,"          0 %s/%c", strVolumeUnit[volumeUnit], strTimeUnit[timeUnit]);
}

_________________
Best Regards
Daniel H. Sagarra
La Plata (Argentina)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 29, 2006 3:41 pm     Reply with quote

Tell us what your goal is, or what your project is about.
Also, Microchip floating point only has about 7 digits of resolution.
I'm not sure, but it looks like you may be assuming that it has 15
digits of resolution.
Calamar



Joined: 07 Sep 2003
Posts: 60
Location: Buenos Aires (Argentina)

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon May 29, 2006 4:58 pm     Reply with quote

I'm currenty using a capture module to measure
frecuency (10Mhz clock), the resolution requiered
is 0.1Hz, range 1.0 - 999.9 Hz --> 5 digits


Code:
#INT_TIMER3
void tmr3_isr()
{
   rollOver++;
   if(rollOver == 20) pulseTicks = 0;
}

#INT_CCP2
void ccp2_isr()
{
   static int16 startTime, endTime;
   endTime = CCP_2;
   pulseTicks = ( 0x10000 * rollOver ) - startTime + endTime;
   startTime = endTime;
   rollOver = 0;
}



f = 2 500 000 00 / pulseTicks
^
|---------- Frecuency scaled * 100

but..... the measure could be represented in: seconds, minutes, hours, days

f = f * 1 or
f = f * 60 or
f = f * 3600 or
f= f * 86400

after that I divide f by kFactor (int32 type it was scaled by 100)

r = f / kFactor

(rate = frecuency * 100 / factor * 100)

now what I want is a right tabulation with 5 digit for any value of r,
for example

17456
1344.3
785.31
34.444
1.3546
0.0008
_________________
Best Regards
Daniel H. Sagarra
La Plata (Argentina)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 29, 2006 5:45 pm     Reply with quote

Quote:
I'm currently using a capture module to measure frequency

Normally, a tachometer displays the speed in RPM (revolutions per minute).
Why do you care about seconds, hours, and days ?
Is this a tachometer project ? What device are you measuring ?
Calamar



Joined: 07 Sep 2003
Posts: 60
Location: Buenos Aires (Argentina)

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue May 30, 2006 5:54 am     Reply with quote

it's a flow computer, the signal
may come from a few diferents
types of sensors: TTL/CMOS, HALL,
COIL, take a look at:

http://www.fluidwell.com/f010.html?fseries
_________________
Best Regards
Daniel H. Sagarra
La Plata (Argentina)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group