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

Counting pulses (freq. counter) on an I/O pin example?
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
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Apr 09, 2020 3:02 pm     Reply with quote

Ttelmah wrote:
The PIC24 can count over 20MHz. Have one doing this.
You are sure you are not enabling SYNC?. If this is enabled, it limits the
count frequency, because counts won't be recorded till the next edge on the
internal oscillator. The maximum supported with sync disabled is specified by
the maximum high and low times for the input pin. Typically 40nSec
for the cycle, so 25MHz.


Only if CCS has it on by default. I am unaware of that.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 09, 2020 4:35 pm     Reply with quote

re: Only if CCS has it on by default

Murphy's Laws of Programming

1) never ever trust 'defaults'.....
2) other programmer's idea of what should be defaults will never be what YOU think they should be.....
3) their defaults will always impact your code the worst possible way....
jeremiah



Joined: 20 Jul 2010
Posts: 1314

View user's profile Send private message

PostPosted: Thu Apr 09, 2020 5:47 pm     Reply with quote

Ttelmah wrote:
The PIC24 can count over 20MHz. Have one doing this.
You are sure you are not enabling SYNC?. If this is enabled, it limits the
count frequency, because counts won't be recorded till the next edge on the
internal oscillator. The maximum supported with sync disabled is specified by
the maximum high and low times for the input pin. Typically 40nSec
for the cycle, so 25MHz.


Are some PIC24's able to do async counting on timers other than timer1? Most of my chips only allow for async on timer1 and sync on any of them. I don't have any newer ones though to compare.
newguy



Joined: 24 Jun 2004
Posts: 1899

View user's profile Send private message

PostPosted: Thu Apr 09, 2020 10:20 pm     Reply with quote

jeremiah wrote:
Are some PIC24's able to do async counting on timers other than timer1? Most of my chips only allow for async on timer1 and sync on any of them. I don't have any newer ones though to compare.


I know it's not a '24, but the PIC18LF26K40 can support an async input on all timer modules. Probably a pretty good chance that there are some 16 bit PICs that do too.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Apr 09, 2020 11:44 pm     Reply with quote

On the ones I'm using, you have to use Timer1, if you want async.
With PPS this is not an issue, since you can swap timer usage basically
at will. The same is true on the PIC33 as well.
I suspect Allen, will have to reorder his timers, so that the fast count uses
timer1.
This is a classic 'read the data sheet' one, where you must check what the
hardware can do before selecting which peripheral to use....
jeremiah



Joined: 20 Jul 2010
Posts: 1314

View user's profile Send private message

PostPosted: Fri Apr 10, 2020 11:01 am     Reply with quote

Ttelmah wrote:
On the ones I'm using, you have to use Timer1, if you want async.
With PPS this is not an issue, since you can swap timer usage basically
at will. The same is true on the PIC33 as well.
I suspect Allen, will have to reorder his timers, so that the fast count uses
timer1.
This is a classic 'read the data sheet' one, where you must check what the
hardware can do before selecting which peripheral to use....


Okie dokie! That was what was confusing me then. I saw that he was using combined 2&3 for 32bit timer values, so the discussion on making it async was throwing me. My experience so far is also that only timer1 has async counting, which seems to match your experience on the PIC24 targets you use as well.

So if he wanted to use timer1 and 32bits he might consider using an interrupt and doing something like:

Code:

static volatile unsigned int16 g_timer1_high = 0;

#int_timer1
void timer1_isr(){
   g_timer1_high++;
}

unsigned int32 get_timer1_32(){
   
   volatile unsigned int16 low;
   volatile unsigned int16 high;

   // This do-while loop catches the case where
   // the get_timer1() value has rolled over right
   // after you read the interrupt value, so you missed
   // an update to it and need to reread.
   do{
      // Read high before low to avoid rollover issues
      high = g_timer1_high;
      low  = get_timer1();
   while(high != g_timer1_high);

   return make32(high,low);

}
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