View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 537 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Apr 09, 2020 3:02 pm |
|
|
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: 9135 Location: Greensville,Ontario
|
|
Posted: Thu Apr 09, 2020 4:35 pm |
|
|
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: 1320
|
|
Posted: Thu Apr 09, 2020 5:47 pm |
|
|
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: 1903
|
|
Posted: Thu Apr 09, 2020 10:20 pm |
|
|
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: 19264
|
|
Posted: Thu Apr 09, 2020 11:44 pm |
|
|
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: 1320
|
|
Posted: Fri Apr 10, 2020 11:01 am |
|
|
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);
}
|
|
|
|
|