TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
[Solved] dsPIC33EP: Input Capture at Low Frequency..
Dear All, I am using dsPIC33EP512MU810 for Input Capture running 60MHz with Timer 3 .Code working fine above 1KHz. Means Frequency 1KHz shown on 1KHz on LCD. I have unable modify code for 10Hz to 250Hz . Is it possible to modify for such a low frequency for Input Capture ?Please Check attachment.. --TS9
post edited by TS9 - 2018/02/14 08:05:16
|
du00000001
Just Some Member
- Total Posts : 1732
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/11 05:00:57
(permalink)
- The easy way: use the prescaler to scale the clock down to not more than 600 kHz.
- The difficult way: stay with 60 MHz and count timer rollovers.
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/11 06:03:21
(permalink)
Thanks for Update..
- The easy way: use the prescaler to scale the clock down to not more than 600 kHz.
How to slow down and calculate clock (For 600KHz) ? void Timer3Init(void) { TMR3 = 0; T3CONbits.TON = 0; T3CONbits.TCS = 0; // Set Timer freq = Fcy/2 T3CONbits.TCKPS = 0; // prescale 1:1 T3CONbits.TGATE = 0; T3CONbits.TSIDL = 0; T3CONbits.TON = 1; //Timer 3 Enable }
|
du00000001
Just Some Member
- Total Posts : 1732
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/11 06:29:23
(permalink)
Set timer3's prescaler to 1/256. this will result in a min. capture frequency < 5 Hz while still delivering sufficient numberical resolution @ 250 Hz.
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/11 09:05:39
(permalink)
du00000001 Set timer3's prescaler to 1/256. this will result in a min. capture frequency < 5 Hz while still delivering sufficient numberical resolution @ 250 Hz.
OK.. Means TCKPS= 0x11 will solve the issue? With Fosc= 60MHz. What will be Mathematical Expression Counts/Frequency from cap2 - cap1 in code as attachment in Msg # 1 ?
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/11 09:10:20
(permalink)
du00000001 Set timer3's prescaler to 1/256. this will result in a min. capture frequency < 5 Hz while still delivering sufficient numberical resolution @ 250 Hz.
OK.. Means TCKPS= 0x11 will solve the issue? With Fosc= 60MHz. What will be Mathematical Expression Counts/Frequency from cap2 - cap1 in code as attachment in Msg # 1 ?
|
du00000001
Just Some Member
- Total Posts : 1732
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/11 09:20:38
(permalink)
frequency = ((60000000/256)/counts);
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/11 09:22:07
(permalink)
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/12 04:33:04
(permalink)
I have tested on Setup. "Count" variable overflow below 100Hz. Any Solution for that..?
post edited by TS9 - 2018/01/12 08:05:04
|
du00000001
Just Some Member
- Total Posts : 1732
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/12 11:46:08
(permalink)
Overflow below 100 Hz ? Impossible if everything is set up accordingly. 60 MHz / 256 = 234375 Hz count rate. Will overflow @ about 3.6 Hz. Check where the overflow occurs! The prescaler might be wrong.
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/12 16:00:14
(permalink)
Thanks for update.. 1) My "Count" variable is unsigned int and 234375 is greater than 65536. 2) Also check my OSCInit(). 3) // Period = (1/FREQ) / (1/Fosc/2) // FREQ = (Fosc/2)/Period // Fosc/2 = 120MHz/2 = 60MHz Something might be wrong here. unsigned int cap1; // first capture variable unsigned int cap2; // second capture variable char results[100]; void Timer3Init(void) { TMR3 = 0; T3CONbits.TON = 0; T3CONbits.TCS = 0; // Set Timer freq = Fcy/2 T3CONbits.TCKPS = 0x11; // prescale 1:256 // T3CONbits.TCKPS = 0; // prescale 1:1 T3CONbits.TGATE = 0; T3CONbits.TSIDL = 0; T3CONbits.TON = 1; //Timer 3 Enable } void __attribute__ ((__interrupt__, no_auto_psv)) _IC1Interrupt(void) { cap1 = IC1BUF; // Read and save off first capture entry cap2 = IC1BUF; // Read and save off second capture entry LED2 ^= 1; IFS0bits.IC1IF = 0 ; // Reset respective interrupt flag } // To Run Oscillator 120MHz void OSCInit(void) { // Configure PLL prescaler, PLL postscaler, PLL divisor // ((8Mhz / N1) x 60) / N2 = 120Mhz // FOSC = 120Mhz // Fcy = 120Mhz/2 = 60Mhz = 60MIPS PLLFBD = 58; // M=60 CLKDIVbits.PLLPOST=0; // N2=2 CLKDIVbits.PLLPRE=0; // N1=2 // Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONH(0x03); __builtin_write_OSCCONL(OSCCON | 0x01); // Wait for Clock switch to occur while (OSCCONbits.COSC!= 0b011); // Wait for PLL to lock while (OSCCONbits.LOCK!= 1); }
Will overflow @ about 3.6 Hz.
How you calculate overflow @3.6Hz ? Please See entire code...as attachment ..
post edited by TS9 - 2018/01/12 16:24:04
|
du00000001
Just Some Member
- Total Posts : 1732
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/12 17:10:59
(permalink)
234375 is the timer/s frequency. Overflow will happen @ 65536/234375 - roundabout 3.6 (Hz). Or simply derived from your statement that you are able to measure 1 kHz with 60 MHz timer clock. Thus 60 MHz/256 clock result in a min. frequency of 1000/256 Hz. Is that really so difficult to get?
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
NorthGuy
Super Member
- Total Posts : 4833
- Reward points : 0
- Joined: 2014/02/23 14:23:23
- Location: Northern Canada
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/12 18:35:02
(permalink)
You can also use 32-bit input capture. They call it "cascade mode" in the docs.
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/12 21:26:31
(permalink)
Thanks
@du00000001.. Difficult to correlate What I am getting on 1KHz and 100Hz ?
@NorthGuy.. Is there any Example program for that.?
|
NorthGuy
Super Member
- Total Posts : 4833
- Reward points : 0
- Joined: 2014/02/23 14:23:23
- Location: Northern Canada
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/12 22:52:39
(permalink)
|
du00000001
Just Some Member
- Total Posts : 1732
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/13 03:04:42
(permalink)
@ 100 Hz you'll get a count of 2343, @ 1 kHz one of 234 (give or take on due to signal synchronization).
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/13 04:55:32
(permalink)
@du00000001...
I will check then update to you tomorrow.
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/13 04:56:02
(permalink)
Repeated
post edited by TS9 - 2018/01/13 05:23:23
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/13 04:56:03
(permalink)
Repeated
post edited by TS9 - 2018/01/13 05:23:44
|
TS9
Super Member
- Total Posts : 514
- Reward points : 0
- Joined: 2010/05/07 10:52:22
- Status: offline
Re: dsPIC33EP: Input Capture at Low Frequency..
2018/01/20 04:50:32
(permalink)
#define FOSC 120MHz #define Fcy 60MHz
I have checked again . Actually FOSC =120 MHz and Fcy = 60MHz. That may be Reason for overflow.
|