Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Interrupt based pulse counting for PIC 32

Status
Not open for further replies.

abhijith94

Newbie level 2
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);
}

 

Re: interrupt based pulse counting for PIC 32

First step, define "my code is not working".
 

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

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

Could you clarify that enigma ?

I am able to build it but it's going to rest: jal_startup when I execute it.

By the way: What is working so far ?
What is not working as expected ?
 

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
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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top