Mar 20, 2019 #1 A abhijith94 Newbie level 2 Joined Mar 20, 2019 Messages 2 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 32 hi, i am trying to write a pulse counter using PIC32, and my code is not working can someone please help me on this. Code C++ - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <plib.h> #include <string.h> #define BAUDRATE 115200 #define GetSystemClock() (80000000ul) #define GetPeripheralClock() (GetSystemClock()/(1 << OSCCONbits.PBDIV)) #define GetInstructionClock() (GetSystemClock()) int count=0; /* * */ void __ISR(_EXTERNAL_0_VECTOR, IPL2SOFT) Ext0ISR(void) { // step 1: the ISR count = count + 1; IFS0CLR = 1 << 3; } int main(int argc, char** argv) { //int count; char ct[10]; UARTConfigure(UART2, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART2, GetPeripheralClock(), 115200); UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); INTDisableInterrupts(); // step 2: disable interrupts at the CPU INTCONCLR = 0x1; // step 3: INT0 triggers on falling edge IPC0CLR = 0x1F << 24; // step 4: clear the 5 pri and subpri bits IPC0 |= 9 << 24; // step 4: set priority to 2, subpriority to 1 IFS0bits.INT0IF = 0; // step 5: clear the int flag, or IFS0CLR=1<<3 IEC0SET = 1 << 3; // step 6: enable INT0 by setting IEC0<3> INTEnableSystemMultiVectoredInt(); while(1) { itoa(count,ct,10); putsUART2("count is:"); putsUART2(ct); putsUART2("\n"); } return (EXIT_SUCCESS); }
hi, i am trying to write a pulse counter using PIC32, and my code is not working can someone please help me on this. Code C++ - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <plib.h> #include <string.h> #define BAUDRATE 115200 #define GetSystemClock() (80000000ul) #define GetPeripheralClock() (GetSystemClock()/(1 << OSCCONbits.PBDIV)) #define GetInstructionClock() (GetSystemClock()) int count=0; /* * */ void __ISR(_EXTERNAL_0_VECTOR, IPL2SOFT) Ext0ISR(void) { // step 1: the ISR count = count + 1; IFS0CLR = 1 << 3; } int main(int argc, char** argv) { //int count; char ct[10]; UARTConfigure(UART2, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART2, GetPeripheralClock(), 115200); UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); INTDisableInterrupts(); // step 2: disable interrupts at the CPU INTCONCLR = 0x1; // step 3: INT0 triggers on falling edge IPC0CLR = 0x1F << 24; // step 4: clear the 5 pri and subpri bits IPC0 |= 9 << 24; // step 4: set priority to 2, subpriority to 1 IFS0bits.INT0IF = 0; // step 5: clear the int flag, or IFS0CLR=1<<3 IEC0SET = 1 << 3; // step 6: enable INT0 by setting IEC0<3> INTEnableSystemMultiVectoredInt(); while(1) { itoa(count,ct,10); putsUART2("count is:"); putsUART2(ct); putsUART2("\n"); } return (EXIT_SUCCESS); }
Mar 20, 2019 #2 andre_luis Super Moderator Staff member Joined Nov 7, 2006 Messages 9,593 Helped 1,190 Reputation 2,399 Reaction score 1,207 Trophy points 1,403 Location Brazil Activity points 55,670 Re: interrupt based pulse counting for PIC 32 First step, define "my code is not working".
Mar 20, 2019 #3 KlausST Advanced Member level 7 Joined Apr 17, 2014 Messages 25,182 Helped 4,868 Reputation 9,757 Reaction score 5,545 Trophy points 1,393 Activity points 168,498 Re: interrupt based pulse counting for PIC 32 Hi, I assume the PIC has a hardware counter, if so: why don't you use it? Klaus
Re: interrupt based pulse counting for PIC 32 Hi, I assume the PIC has a hardware counter, if so: why don't you use it? Klaus
Mar 21, 2019 #4 A abhijith94 Newbie level 2 Joined Mar 20, 2019 Messages 2 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 32 Re: interrupt based pulse counting for PIC 32 I am able to build it but it's going to rest: jal_startup when I execute it. No I can't use hardware counter as I am trying to develop a program that counts the external pulses
Re: interrupt based pulse counting for PIC 32 I am able to build it but it's going to rest: jal_startup when I execute it. No I can't use hardware counter as I am trying to develop a program that counts the external pulses
Mar 21, 2019 #5 andre_luis Super Moderator Staff member Joined Nov 7, 2006 Messages 9,593 Helped 1,190 Reputation 2,399 Reaction score 1,207 Trophy points 1,403 Location Brazil Activity points 55,670 Re: interrupt based pulse counting for PIC 32 Could you clarify that enigma ? I am able to build it but it's going to rest: jal_startup when I execute it. Click to expand... By the way: What is working so far ? What is not working as expected ?
Re: interrupt based pulse counting for PIC 32 Could you clarify that enigma ? I am able to build it but it's going to rest: jal_startup when I execute it. Click to expand... By the way: What is working so far ? What is not working as expected ?
Mar 21, 2019 #6 KlausST Advanced Member level 7 Joined Apr 17, 2014 Messages 25,182 Helped 4,868 Reputation 9,757 Reaction score 5,545 Trophy points 1,393 Activity points 168,498 Re: interrupt based pulse counting for PIC 32 Hi, No I can't use hardware counter as I am trying to develop a program that counts the external pulses Click to expand... Please confirm: "you kow that a hardware counter can be used, but you don´t want to use it". What is the idea behind this? What benefit do you see in using a software counter instead of a hardware counter? Klaus
Re: interrupt based pulse counting for PIC 32 Hi, No I can't use hardware counter as I am trying to develop a program that counts the external pulses Click to expand... Please confirm: "you kow that a hardware counter can be used, but you don´t want to use it". What is the idea behind this? What benefit do you see in using a software counter instead of a hardware counter? Klaus