Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PINGUINO32 High accuracy 80MHz frequency meter
25-01-2014, 01:24 AM,
#11
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hello All,

I have tried to build this code and am running into an issue. I am running pinguino IDE 959 on Windows 7 64 bit. When I run the build I get:

In file included from C:\x4-easy-rev959\source\main32.c:38:0:

C:\x4-easy-rev959\source\/user.c:50:6: warning: conflicting types for 'Tmr1Interrupt'

C:\x4-easy-rev959\source\/user.c:47:35: note: previous implicit declaration of 'Tmr1Interrupt' was here

C:\x4-easy-rev959\source\/user.c:61:6: warning: conflicting types for 'Tmr4Interrupt'

C:\x4-easy-rev959\source\/user.c:58:36: note: previous implicit declaration of 'Tmr4Interrupt' was here

C:\x4-easy-rev959\source\/user.c: In function 'Tmr1Interrupt':

C:\x4-easy-rev959\source\/user.c:74:1: error: interrupt handlers cannot be MIPS16 functions

C:\x4-easy-rev959\source\/user.c:74:1: error: interrupt handlers cannot be MIPS16 functions

I found this thread http://forum.pinguino.cc/showthread.php?tid=3971 which seems to describe the problem. The code in thread 3971 compiles and runs ok, and I get output on my USB com4. I then tried to incorporate the fixes into this frequency counter code and can get a clean build but then when the code runs the com4 port seems dead. I suspect that I am doing something incorrect somewhere ...

Here is my modified code:

/*-----------------------------------------------------
Author: Manzini Moreno
Date: 01/01/2013
Description:
Easy frequency meter which measure Peripheral clock fixed at 80MHz with Pinguino32
For measure external clock on P31 (Conn1.1) pin use T1CONSET=0x8002; instead of T1CONSET=0x8000; in init_timer1 function
Max internal error about +- 2 count +- 0,025ppm

01/01/2013 Ver. 1 Rev. 0 c. Moreno Manzini ( moreno at mediacom dot it )

Licence Creative Commons 3.0 http://creativecommons.org/licenses/by-sa/3.0/

Interrupt routines inspired to http://blog.pinguino.cc/?p=225

-----------------------------------------------------*/


#include <interrupt.c>




#define NumSample100mS 10 //1Sec total




unsigned int CounterO=0;
unsigned int VCounterRes=0;
unsigned int TmpCounterRes=0;
unsigned int VCounterO=0;
unsigned int TmpCounterO=0;
unsigned int CtnPulse100mS=0;
unsigned int PrevRes=0;
unsigned int ActRes=0;

DWORD Frequency;



// Put the ISR_wrapper in the good place
void __attribute__ ((nomips16)) ISR_wrapper_vector_Tmr1(void) __attribute__ ((section (".vector_4")));

// TMR1 Overflow Interrupt Function
void __attribute__ ((nomips16)) Tmr1Interrupt(void) __attribute__ ((interrupt));

// ISR_wrapper will call the Tmr1Interrupt()
void __attribute__ ((nomips16)) ISR_wrapper_vector_Tmr1(void) { Tmr1Interrupt(); }

// Put the ISR_wrapper in the good place
void __attribute__ ((nomips16)) ISR_wrapper_vector_Tmr4(void) __attribute__ ((section (".vector_4")));

// TMR4 Overflow Interrupt Function
void __attribute__ ((nomips16)) Tmr4Interrupt(void) __attribute__ ((interrupt));

// ISR_wrapper will call the Tmr4Interrupt()
void __attribute__ ((nomips16)) ISR_wrapper_vector_Tmr4(void) { Tmr4Interrupt(); }


// TMR1 Overflow Interrupt Function
void __attribute__ ((nomips16)) Tmr1Interrupt(void)
{
if (IFS0bits.T1IF) // Timer Interrupt flag
{
IFS0CLR=0x10; // Clear the timer interrupt flag
CounterO++; // increment the CounterO
}
}



// TMR1 Init Function
void init_timer1(void)
{
IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); // interrupt mode (interrupt.c)
T1CON=0; // reset timer 1 configuration
TMR1=0; // reset timer 1 Counter register (VERY DANGEROUS OPERATION USE ONLY AT INIT TIME)
PR1=0x0FFFF; // define the preload register
IPC1SET=0x7; // select interrupt priority and sub-priority
IFS0CLR=0x10; // clear interrupt flag
IEC0SET=0x10; // enable timer 1 interrupt
T1CONSET=0x8000; // start timer 1 and set prescaler to 1 internal clock
// decomment to measure external clock on P31 (Conn1.1) I/O pin
//T1CONSET=0x8002; // start timer 1 and set prescaler to 1 external clock
}



// TMR4 Overflow Interrupt Function
void __attribute__ ((nomips16)) Tmr4Interrupt(void)
{
TmpCounterRes = TMR1;
TmpCounterO = CounterO;
if (IFS0bits.T4IF) // Timer Interrupt flag
{
IFS0CLR=0x10000; // Clear the timer interrupt flag
CtnPulse100mS++; // increment the CounterO
if (CtnPulse100mS >= NumSample100mS)
{
VCounterRes = TmpCounterRes;
PrevRes = ActRes;
ActRes = TmpCounterRes;
VCounterO = TmpCounterO;
CounterO = 0;
CtnPulse100mS = 0;
}
}
}



// TMR4 Init Function
void init_timer4(void)
{
IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); // interrupt mode (interrupt.c)
T4CON=0; // reset timer 4 configuration
TMR4=0; // reset timer 4 Counter register (VERY DANGEROUS OPERATION USE ONLY AT INIT TIME)
PR4=31250-1; // define the preload register
IPC4SET=0x7; // select interrupt priority and sub-priority
IFS0CLR=0x10000; // clear interrupt flag
IEC0SET=0x10000; // enable timer 4 interrupt
T4CONSET=0x8070; // start timer 4 and set prescaler to 256
}



void setup()
{
System.setCpuFrequency(80000000); // should be 80 MHz
System.setPeripheralFrequency(80000000); // should be 80 MHz

init_timer1();
init_timer4();
}



void loop()
{
Frequency = VCounterO;
Frequency *= 65536;
Frequency += VCounterRes;
Frequency -= PrevRes;
CDC.printf("Freq= %u Hz , OvF= %d , Cnt= %d , Res= %d\n\r",Frequency,VCounterO,VCounterRes,PrevRes);
delay(1000);
}


Any help would be greatly appreciated.

Thanks,
Brett
Reply
25-01-2014, 08:01 AM,
#12
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hi


Mmmm, I compiled the program without problems with 960.

I think you select a wrong board, this program can work only on PIC32 boards.

Which board you have??


Bye Bye, Moreno
Reply
02-02-2014, 02:42 PM,
#13
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hello Moreno,

I have the pic32-pinguiono-micro from Olimex.

Thanks,
Brett
Reply
02-02-2014, 09:02 PM,
#14
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hi

The same board I use, in this case the problem is not on the program but elsewhere.

Check installation
Check selected board (Architecture 32-Bit PIC32 Pinguino Micro)


Bye Bye, Moreno
Reply
07-05-2014, 04:20 PM, (This post was last modified: 07-05-2014, 04:36 PM by Zarekx.)
#15
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hi.
Im used pinguino 32 OTG (https://www.olimex.com/Products/Duino/PI...e-hardware )
this board has not the pin con 1.1 available, how can I adapt the code using a digital pin?
Regards!
Thanks
Reply
07-05-2014, 09:33 PM,
#16
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hi

Is almost impossible make a frequency meter without a high frequency clock input, in this case T1CK, Pinguino 32 OTG use this pin for RTC oscillator.
The only possibility is use an external prescaler like a 74HC590 and connect Q0-Q7 on port E and Q7 on D7 pin, this pin can generate an interrupt on high to low transition.
In any case the result is very poor, the maximum frequency is about 25MHz and is very easy read wrong data on low order bit of the prescaler.

I think is more cheap buy an PINGUINO32-MICRO.


Bye Bye, Moreno
Reply
17-10-2014, 03:34 PM, (This post was last modified: 18-10-2014, 07:49 PM by EphManHox. Edit Reason: typo )
#17
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hi Moreno!
I'm new on Pinguino. I recently bought an olimex pic32 pinguino micro. Your project is very good. I was trying to modify your project in last 3 days. I'm trying to measure pulses in 1ms but i failured. First times there was a complying problem which was saying that;"function at exception vector X too large(x was 4 and 16)" i think it means interrupt isn't working. I solved this problem by installing an older version of ide(downgrade from X4.999 to X4.857) but now i'm seeing that my knowledge isn't enough for modify project!
So could you please show me how can i modify your codes for measuring pulses in 1ms. Thanks in advice,
Regards, Uygar
Reply
18-10-2014, 08:18 AM,
#18
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hi

999 version is no good for P32 board, is better you upgrade to 1004 version through SVN.
The SVN address is https://pinguino32.googlecode.com/svn/ide/x.4


If I understand correctly you want reduce the sample time to 1mS, correct??

If yes you modify the program in this manner:


1) Set postscaler counter to 0
//#define NumSample100mS 10 //1Sec total
#define NumSample100mS 0 //No PostScaler

2) In init_timer4 modify the prescaler timeout do 64 pulse 800nS
//T4CONSET=0x8070; // start timer 4 and set prescaler to 256
T4CONSET=0x8060; // start timer 4 and set prescaler to 64

3) In init_timer4 modify the counting period to 1250 (1250 * 800 = 1000000nS = 1mS)
//PR4=31250-1; // define the preload register
PR4=1250-1; // define the preload register

it's all.


Bye Bye, Moreno
Reply
18-10-2014, 07:55 PM,
#19
RE: PINGUINO32 High accuracy 80MHz frequency meter
Hi Moreno,
Thank you very much for your help. I'm downloading ver.1004 and going to do changes which you told. You are very helpful.
Regards, Uygar
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)