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.

Periodical scan in PIC Micro

Status
Not open for further replies.

garimella

Full Member level 5
Joined
Aug 25, 2011
Messages
260
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
3,276
Hi

Iam using arduino and to scan and execute functions at regular interval, I use the following code
start=micros();
if((start-enD)>=(2000.0))
{
enD = micros();
......
my program starts here
}

I want similar settings in PIC. Using PIC24.
 
Last edited:

Hi,

It seems "micros()" is a value generated by the arduino using interrrupts.

--> use interrupts in your PIC24, too.

Or even simpler:
Setup a timer that repeatedly overflows every 2ms.
It just needs to set the interrupt flag .. not even necessary to run an ISR.

In main loop just wait for the Flag to be set, then clear the Flag and run the task.

****
If you need several tasks to be performed with different time intervals:
Find the greatest common divisor and run make the timer to set the flag at this GCD timing.
In main loop run increment a counter every time the flag is set.

Example:
TaskA: 20ms
TaskB: 100us
TaskC: 4ms

--> GCD=100us
TaskA: every 200 ticks
TaskB: every tick
TaskC: every 40 ticks

There are many ways for different requirements.
E.g. ..You may run one or three counters in an ISR...

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top