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 CCS Technical Support

frequency measure update rate
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Fri Sep 28, 2012 3:32 pm     Reply with quote

No - no extra holes for the missing cylinders, they built the block at the factory basically from the small V8 with the casting modified, but it still had the "V" angle of a V8. Engine had a few quirks, but in general good engine. I don't know how many of the V-6's out there were built the same way which was the basis of my original comment (I have the ability to run into these things it seems). Check out this link if you are curious about it:
http://en.wikipedia.org/wiki/Buick_V6_engine
Where they discuss the "198" being a derivative of the "215 Aluminum V8".

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Sep 29, 2012 1:56 am     Reply with quote

Quote:
You guys must be teachers.
Not necessarily, but we've been around a long time and seen it all before (in different forms).

I don't think your reciprocal method will work as it stands.

1) If B0 is high you will go into the routine, and start timing. But, B0 may have been high for a while, and you'll have missed some of the period. You need to wait for an edge, before you start counting.
2) How long do you think it takes to go round the timing loop? (Hint it's NOT 25 cycles).
3) To get best resolution you need to be counting instruction cycles, not slower software loop cycles.

Mike

EDIT Something else to watch out for. If the signal suddenly stops, there is a risk that any reciprocal method will freeze at its last reading, your original counting method will show zero after one gating period.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Sep 29, 2012 7:51 am     Reply with quote

Partial only, but some basic ideas:

Code:

//several things will depend on your clock rate and chip
//Need your setup stuff here

int32 timer=0;
#word timer_msw=timer+2
#word timer_lsw=timer
//define a variable to access the 16bit parts of 'timer'

#INT_TIMER1
void timer_overflow(void) {
   timer_msw++;
}

int1 wait_for_ccp() {
   int16 overflow=0;
   //wait for an edge to be detected on the CCP1 input
   //returns true if an edge is found within about 0.5seconds
   //false otherwise (stopped....).
   do {
       delay_us(10);
       overflow++;
   }while (!interrupt_active(INT_CCP1) && overflow<5000);
   if (overflow<5000) return (TRUE);
   return (FALSE);
}

void main(void) {
   int32 first_timer;
   int32 delta;
   float revs=0.0;
   //You will need your other configuration stuff here

   setup_timer_1(T1_INTERNAL, T1_DIV_BY_1);
   //set timer1 to count instructions
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   //We now have a 32bit timer potentially available

   setup_ccp1(CCP_CAPTURE_FE); //start the CCP
   //Use whichever edge is the best (rising or falling).

   do {
       //Now loop to take a time measurement from the CCP1 input
       clear_interrupt(INT_CCP1);
       revs=0.0;
       if (wait_for_ccp()==TRUE) {
          //Have seen an edge
          timer_lsw=CCP_1;
          first_timer=timer;
          //Now have a 32bit timer value stored for the first edge
          clear_interrupt(INT_CCP1);
          //Now wait for the second edge
          if(wait_for_ccp()==FALSE) {
             revs=0.0;
          }
          else {
             //If we get here, two successive edges have been seen
             timer_lsw=CCP_1;
             delta=timer-first_timer;
             revs=INSTRUCT_CLOCK/delta;
             //INSTRUCT_CLOCK needs to be #defined as the CPU instruction
             //clocks/minute
             //(for RPM output)
         }
      }
      //here have a value 'revs', giving the measured RPM
      printf("%6.1f",revs);
   }
}


Now, several things missing (clock rate etc.), and it could be made significantly faster updating, if once _one_ measurement is made, you only look for the next edge (currently times between a pair of edges).

However has multiple things 'done':

1) If a clock edge is not seen in just over half a second, gives '0'0' as the output.
2) Will also not therefore hang when the clock stops.
3) Counts in processor cycles, giving as much resolution as possible.
4) Counts in 32bits, so will support a huge range of speeds and CPU clocks.

Have almost certainly typed something wrong. Just typed 'as is' to show how this can be done. Pulse input needs to be coming in on the CCP1 input.

Best Wishes
nuno12345



Joined: 16 Jul 2008
Posts: 50

View user's profile Send private message

PostPosted: Sat Sep 29, 2012 4:58 pm     Reply with quote

any way to do it without ccp1? I really want to test this on 12F675 before the 16f88 arrives Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 29, 2012 5:31 pm     Reply with quote

Quote:
Any way to do it without ccp1?

Software-based "count" function:
http://www.ccsinfo.com/forum/viewtopic.php?t=41877
nuno12345



Joined: 16 Jul 2008
Posts: 50

View user's profile Send private message

PostPosted: Mon Oct 01, 2012 1:35 pm     Reply with quote

thank you pcm

I had already found that post here on the forums but I it works the same way get_timer does, at least I tried changing time and the frequency gets affected.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 01, 2012 1:50 pm     Reply with quote

Then do some simple math on the result and adjust it for the different oscillator
frequency.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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