Content Template 20240715

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

SEO Template for new content

Target keywords: how to calculate delay in pic microcontroller in c

Page title
• Optimal title length: 55 characters
• Add at least one of your target keywords to your <title> tag, don't use each target keyword
more than 1 time: how to calculate delay in pic microcontroller in c

Meta description
• Optimal meta length: 160 characters

H1
• Add all your target keywords at least one time: how to calculate delay in pic microcontroller in
c

Text
• Try to acquire backlinks from the following domains: matrixtsl.com, c-plusplus.net
• Enrich your text with the following semantically related words: time delay, clock frequency
• Focus on creating more informative content. Recommended text length: 940.0
• Make sure that your text is easy to read with the Flesch-Kincaid readability test. The readability
score should be: 54.579039400940516
• Add at least one of your target keywords: how to calculate delay in pic microcontroller in c

When your content has been published, launch a SEO Ideas campaign to check if your content complies
with all on-page SEO factors and discover what else can be done to give your content a SEO boost.

Analyzed top-10-ranking rivals for your target keywords


how to calculate delay in pic microcontroller in c
1. https://forum.microchip.com/s/topic/a5C3l000000M525EAC/t249405
2. https://microcontrollerslab.com/timers-pic-microcontroller-delay/
3. https://stackoverflow.com/questions/77068057/how-to-calculate-delay-in-pic-mcu-in-pic-as
4. https://www.youtube.com/watch?v=mOq2LZuBlvY
5. https://www.edaboard.com/threads/how-to-calculate-delay-from-microcontroller-oscillator-
frequency.257971/
6. https://www.youtube.com/watch?v=bZLd8-RTxvU
7. https://electronics.stackexchange.com/questions/632593/how-to-use-a-variable-delay-in-
microchip-pic-microcontroller-mplab-x-without
8. https://www.engineersgarage.com/specific-time-delay-using-timers-of-pic-microcontroller/
9. https://www.edaboard.com/threads/1-sec-delay-in-pic16f877a.199831/
10. https://electronics.stackexchange.com/questions/247720/pic-microcontroller-delay-ms-no-
effect

See how competitors write about targeted keywords:


how to calculate delay in pic microcontroller in c
1. https://forum.microchip.com/s/topic/a5C3l000000M525EAC/t249405

2. https://microcontrollerslab.com/timers-pic-microcontroller-delay/
Timer1 can work as 16-bit timer or counter Readable and writable 8-bit registers (TMR1H and
TMR1L) Selectable clock source (internal or external) Alternate clock source can be provided at
Timer1 oscillator pins (T1OSO & T1OSI) Interrupt on overflow Timer1 can be multiplexed with
other peripherals like ADC and generates special event triggering for CCP (Capture, Compare and
PWM) events. Timer2 8-bit Timer and Period registers (TMR2 and PR2, respectively) Software
programmable pre-scaler (1:1, 1:4 and 1:16) Software programmable post-scaler (1:1 – 1:16)
Interrupt on TMR2 to PR2 match Optional use as the shift clock for the MSSP (Master Synchronous
Serial Port) module Timer3 Timer3 can work as 16-bit timer or counter Readable and writable 8-
bit registers (TMR3H and TMR3L) Selectable clock source (internal or external) Alternate clock
source can be provided at Timer1 oscillator pins (T1OSO & T1OSI) Interrupt on overflow Timer3
can be multiplexed with other peripherals like ADC and generates special event triggering for CCP
(Capture, Compare and PWM) events. Clock source of PIC microcontroller timers The simplest is
the TIMER0. For Timer configurations, it is important to know that how time delay is calculated by
the timer. Firstly the Timer clock source is set. Internal Clock Mode: The clock can be internal or
external. In the internal clock mode, Timer0 operates as a timer and uses the internal (FCPU) clock
with or without a pre-scaler. The pre-scaler is an integer value that divides the CPU clock to give the
Timer Clock, i.e., Timer Clock = FCPU/pre-scaler. When the pre-scaler is set to one or bypassed, the
timer runs on the same clock as the CPU is running. External Clock Mode: In this mode Timer0
operates as counter and counts on every rising or falling edge of the clock connected to the Timer’s
clock pin. How to Generate Delay using Timers Interrupts? We can use pic microcontroller timers
to generate delay, PWM and perform periodic tasks. Let’s see an example to generate delay. We will
take an example to calculate the time delay of 1 sec using 20MHz crystal oscillator with PIC
microcontroller. PIC 18F452 has ability for external as well as internal clock source but we are using
Timer0 with internal clock (Timer mode). Clock source frequency of crystal: Fosc=20 MHz=
20000000 Hz The PIC internally divides FOSC by 4 to get FCPU. Based on this we have clock cycle
and instruction cycle. The clock cycle is simply 1/FOSC while instruction cycle is 1/FCPU. FCPU=20
MHz/4 =5 MHz PIC18 has the ability to generate interrupt on overflow. It means that a bit called
Timer0 Interrupt Flag (TMR0IF) is set when TMR0 makes transition from 255 to 0. Prescaler Period
(if Prescaler = 1:256) Ftimer= 5 MHz/256 =19531.25Hz Single overflow of Timer0 will give this delay:
Ttimer = 1/19531.25 = 0.0000512 sec = 51.2 µs This means that when timer runs, it will take 51 µs
to increment its value at every count. Now we have to calculate the value to be filled in Timer
register to generate 1 sec delay. No. of count for 1 sec Delay = 1 sec/51 µs = 19531.25 = 4C4B H
The value to be filled in timer’s 16 bit register = FFFF – 4C4B= B3B4 H These values are filled in the
Timer register and it rolls over up to FFFF. The values are reloaded again to start timer for same
delay. Pic Microcontroller Timers Configuration Registers Every Timer has certain registers
associated, which must be configured for desired operations. The Timer register can have the
following bit length: 8 bit timers – These can count between 0-255 16 bit timers – These can count
between 0-65536 32 bit timers – These can count between 0-4294967296 The registers of Timer0
have been explained below. Timer0 Control Register This bit is set to high to enable the Timer0. 1
= Enable the Timer0 T08BIT: 8/16 bit mode selection bit This bit selects the Timer mode. 1 =
Timer0 is configured as an 8-bit timer/counter. 0 = Timer0 is configured as a 16-bit timer/counter.
TMR0CS: Timer0 Clock Source set Timer mode is selected by clearing the TMR0CS bit of the Control
register. 1 = T0 Clk 0 = Fosc/4 TMR0SE: Timer0 source Edge select The rising or falling transition
of the incrementing edge for either input source is determined by the TMR0SE bit in the Control
register. 1 = Increment TMR0 on high to low transition 0 = Increment TMR0 on low to high
transition PSA: Pre-scaler Assignment The pre-scaler is enabled by clearing the PSA bit of the
Control register. 1 = Pre-scaler not Assigned to TMR0 0 = Pre-scaler Assigned to TMR0 PS2, PS2,
PS0: Pre-scaler Rate Select bits There are eight pre-scaler options for the Timer0 module ranging
from 1:2 to 1:256. The pre-scaler values are selectable via the PS 2:0 bits of the Control register. In
order to have a 1:1 pre-scaler value for the Timer0 module, the pre-scaler must be disabled by
setting the PSA bit of the Control register. Timer0 Interrupt Control Register This bit is used to
enable/disable the Timer0 overflow interrupt. 1 = TMR0 Interrupt enabled 0 = TMR0 Interrupt
disabled TMROIF: Timer0 Interrupt Flag This is Timer0 overflow flag bit which is bit is set when
TMR0 register overflows. This bit is cleared by the software. 1 = TMR0 has overflowed 0 = TMR0
did not overflowed TMR0 (Timer0 Register) This register is divided into registers TMR0H TMR0L
Both registers are separately accessible thus Timer0 can work in both 8-bit and 16-bit modes. In
these registers, pre-calculated value for delay is filled. Working of PIC microcontroller timers
Timer0 can operate as a timer or as a counter. When the clock source is the instruction cycle clock, it
operates as a timer, and when the clock source is the T0CKI pin, it operates as a counter. When the
PIC18F452 reads the TMR0L register, the upper half of Timer0 is latched into the TMR0H register.
This ensures that the PIC18 always reads a 16-bit value where the upper byte and lower byte belong
to the same time. Circuit Diagram In this section, we will see an example to generate delay of 1
second using pic microcontroller timers. By using timer0, we will generate a delay and each LED will
turn on after every one second and rest of the LEDs will remain off. For example, this circuit
contains 8 LEDs. At the start, LED D1 will glow and rest of the LEDs will remain off. Similarly, after
another one second, LED D2 will glow and rest of the LEDs will remain off. This sequential pattern
continues, with each LED illuminating one by one after the duration of a single second. For
Programming: Firstly through T0CON register, we will select the Pre-scaler, Clock option and Mode
of Timer0. Then we fill the higher byte of Timer value in TMR0H and then fill lower byte value in
TMR0L Now set the TMR0ON bit to start the timer. Wait until the TMR0IF flag gets high As TMR0IF
gets high, we set it to zero and stop the timer by clearing the TMR0ON bit. To start the Timer0 again
repeat this process of placing higher byte and lower byte with help of while loop. MikroC Code
The code for this project is written in the MIKROC compiler and 8Mhz crystal is used in this project. If
you do not know how to use MikroC for Pic, you can refer to these tutorials: Pic microcontroller
programming in c using Mikroc Pro for PIC void main() { // Configure Port B as an output port
TRISB = 0; // Turn on the LED on PORT B pin 0 LATB = 0x01; // Configure Timer0 T0CON =
0x07; // Prescaler = 1:256, 16-bit mode, Internal Clock while (1) { // Values calculated for a
1-second delay with a 20MHz crystal TMR0H = 0xB3; // Place the higher byte in TMR0H
TMR0L = 0xB4; // Place the lower byte in TMR0L T0CON.TMR0ON = 1; // Turn Timer0
On // Wait until TMR0IF gets flagged while (INTCON.TMR0IF == 0); T0CON.TMR0ON =
0; // Turn Timer0 Off INTCON.TMR0IF = 0; // Clear Timer0 interrupt flag // Circular right
shift at PortB to shift the LED LATB = (LATB << 1) | (LATB >> 7); } } MPLAB XC8 Compiler Code
If you do not know how to use MPLAB XC8 compiler, you can follow this guide first: MPLAB XC8
Compiler – Write your First Program if you are using MPLAB XC8 compiler instead of mikroC for pic,
you can use this code: #include <xc.h> // Include the XC8 library for PIC18F series // Interrupt
Service Routine (ISR) for Timer0 void __interrupt() Timer0_ISR() { if (TMR0IF) { // Clear
Timer0 interrupt flag TMR0IF = 0; // Values calculated for 1 second delay with 20MHz
crystal TMR0H = 0xB3; // Placing the higher byte in TMR0H TMR0L = 0xB4; // Placing the
lower byte in TMR0L // Toggle the LED (Circular right shift at PortB) LATB = (LATB << 1) |
(LATB >> 7); } } void main() { // Configure Port B as an output Port. TRISB = 0; // Turn on
LED on PORT B pin 0 LATB = 0x01; // Configure Timer0 T0CON = 0x87; // Prescaler = 1:256,
16-bit mode, Internal Clock, Timer0 Enabled // Enable Timer0 overflow interrupt TMR0IE = 1;
// Enable global interrupts GIE = 1; while (1) { // Your main code can continue here
without blocking } } How Does Code Work? This line of code includes the necessary header file
for the XC8 compiler, which provides access to the functions and definitions specific to the PIC18F
series microcontrollers. #include <xc.h> // Include the XC8 library for PIC18F series An Interrupt
Service Routine (ISR) for Timer0 is defined in this section. The ISR will be executed whenever the
Timer0 interrupt flag (TMR0IF) is set. Inside the ISR, the code clears the Timer0 interrupt flag, loads
the TMR0H and TMR0L registers with specific values to create a 1-second delay, and toggles the LED
pattern connected to PortB using a circular right shift operation. void __interrupt() Timer0_ISR()
{ if (TMR0IF) { // Clear Timer0 interrupt flag TMR0IF = 0; // Values calculated for 1
second delay with 20MHz crystal TMR0H = 0xB3; // Placing the higher byte in TMR0H
TMR0L = 0xB4; // Placing the lower byte in TMR0L // Toggle the LED (Circular right shift at
PortB) LATB = (LATB << 1) | (LATB >> 7); } } In the main() function, the code sets up the
necessary configurations. The Port B is configured as an output port using the TRISB register. The LED
connected to PORT B pin 0 is turned on by setting the LATB register value to 0x01. The T0CON
register configures the Timer0. We write the value 0x87 to T0CON to set the pre-scaler to 1:256,
enable 16-bit mode, use the internal clock, and enable Timer0. We enable the Timer0 overflow
interrupt by setting the TMR0IE flag to 1. Finally, we enable global interrupts by setting the GIE flag
to 1. The main loop contains no blocking code and allows the program to perform other tasks while
the Timer0 interrupts handle the delay and LED toggling. void main() { // Configure Port B as an
output Port. TRISB = 0; // Turn on LED on PORT B pin 0 LATB = 0x01; // Configure Timer0
T0CON = 0x87; // Pre-scaler = 1:256, 16-bit mode, Internal Clock, Timer0 Enabled // Enable
Timer0 overflow interrupt TMR0IE = 1; // Enable global interrupts GIE = 1; while (1) {
// Your main code can continue here without blocking } } Demonstration Conclusion: In this
tutorial, we learned how to use PIC18F452’s Timer0 to obtain a delay of approximately 1 second.
Moreover, the timer can also be used to find the execution time of a function. Similarly, we can use
other timers by carefully considering their datasheets. Related content:

3. https://stackoverflow.com/questions/77068057/how-to-calculate-delay-in-pic-mcu-in-pic-as
We have no data for this page, because it isn't accessible for our crawler.

4. https://www.youtube.com/watch?v=mOq2LZuBlvY
We have no data for this page, because it isn't accessible for our crawler.

5. https://www.edaboard.com/threads/how-to-calculate-delay-from-microcontroller-oscillator-
frequency.257971/
You are using an out of date browser. It may not display this or other websites correctly. You should
upgrade or use an alternative browser . How to calculate delay from microcontroller oscillator
frequency? 1,381 Hi all, I have a PIC18F4550 with oscillator crystal 20MHz (C Compiler), I would
like to understand more on how to calculate 1 second delay from this 20MHz. Refering to thread
( https://www.edaboard.com/threads/193407/ ), Post #6,
--------------------------------------------------------------------------------------------------------- Hi, For having an
approximately 1 second delay i've ued a delay function same as the following: In a C compiler for
PIC (PIC18F4550-selected frquency 48MHz) the 1 second delay function is as below: void delay
(void){ unsigned long i;//(long in this compiler is 4 Bytes) for(i = 0;i<1000000;i++); }
--------------------------------------------------------------------------------------------------------- He mentioned that
he is using PIC18F4550-selected frquency 48MHz and his 1 second delay function is: void delay
(void){ unsigned long i;//(long in this compiler is 4 Bytes) for(i = 0;i<1000000;i++); } How do he
know that he need to loop for 1000000 times to get 1 second delay? Appreciate for any help given!
Thanks For any processor, there should be a bunch of papers that most engineers think of as
useless. These papers are sometimes called user manual, specs sheet, etc... In the user manual,
there should be sections stating explicitly how many clocks you need for one asm instruction. For
example: branch might be 5 clocks, 16-bit x 16 bits multiply = 5 clocks, etc... Now for one loop, you
have basically one compare, one increment (addition) and one jump. If you add these 3, then you
will know the number of clocks you need for an empty loop. In your example, it would mean that
the empty loop takes 48 clocks, which is not the case, I guess. It's very processor dependent and I
don't know PIC, but on the processors I am used to, one loop is about 10 clocks. If the loop needs 4
bytes values as in your case, that might be slightly higher, but for sure not 48 clocks. Dora. No,
not exactly. The reason is as follows. The program you quoted pretends that when you count up to
1 million with a clock frequency of 48 MHz (48 million clocks per second), then you will get a delay
of one second. If a million loop is achieved with 48 million clocks, then on loop is achieved in 48
clocks. As far as I know, the more instruction I have, the longer it takes to complete one loop, am I
right? Yes. And as this loop does nothing, I can't believe it takes 48 clocks. But again, I don't know
PIC. Dora.

6. https://www.youtube.com/watch?v=bZLd8-RTxvU
We have no data for this page, because it isn't accessible for our crawler.

7. https://electronics.stackexchange.com/questions/632593/how-to-use-a-variable-delay-in-
microchip-pic-microcontroller-mplab-x-without
We have no data for this page, because it isn't accessible for our crawler.

8. https://www.engineersgarage.com/specific-time-delay-using-timers-of-pic-microcontroller/
One Second Delay Generation by using internal Timers of Microchip Pic Microcontroller, xc8 compiler
with Mplabx Ide By EG Projects While working with microchip pic microcontrollers i came across a
situation where custom delay is required in seconds. I was working with pic18f4580 microcontroller,
Mplabx ide and xc8 compiler. I know that __delay_ms() and __delay_us() macros do exists for
generating delays. But i want to see how the timer configuration is done for one second delay. I want
to go through the whole process by my self. I read out the data sheet of pic18f4580 microcontroller
and found some relevant information that i am going to share with the microcontroller project
community. How to generate specific delay’s using Timers: The internal structure of Pic
Microcontroller’s Each pic microcontroller divides the input clock frequency from external crystal by
4, before supplying the clock pulse to internal peripherals. After dividing, the clock signal is supplied
to internal timers, ADC’s, GPIO’s, Processor and Uart etc. Suppose you attached an external 20MHz
crystal at XTAL pins. The input frequency/clock signal supplied to peripherals of pic will be 20/4=
5MHz. This 5Mhz frequency can further be divided to operate a particular peripheral on different or
desired frequency, by activating internal prescaler’s. Pic microcontroller internal clock timer
structure Pic Microcontroller Delay Calculation formula Pic Microcontroller Delay Calculation
formula Tick/Counter frequency Tick/Counter frequency is the final frequency on which the timer
is working. Timer Count Timer Count is the number of counts required to generate a particular
delay/frequency at output of microcontroller pin. Timer count is the final value to be loaded in
TMRxH and TMRxL Registers. Register Value Register Value must not be negative or grater than
65535. Since timer is a 16-bit and max 16-bit value is 65535 Lets calculate 1 second delay Suppose
we want to generate 1 second delay using timer-1 of pic16f877a microcontroller. An external crystal
with frequency Fosc = 20Mhz is used as clock source to microcontroller. We also want to activate
prescaler for reducing the clock speed supplied to microcontroller. We selected 1:4 Prescaler. Putting
the given values in formula given above yields out. Note: I am calculating value for 10 ms and then
running the 10 ms delay 100 times to produce 1 second delay. Pic input frequency= Fosc / 4= 20
Mhz / 4 = 5 Mhz Prescaler = 1:4 Delay required = Timer Count * Tick Counter frequency Timer
Count = Delay required / Tick Counter frequency = 10 m s/ 0.8 u s = 12.5 k = 12500 (Hexadecimal =
0x30D4) Register value = 65535 – 12500 = 53035 Value not negative and under 65535, its safe we
can use 12500. Timer counter value for 10 ms delay comes out to be 12500 which is in 16-bit range
and we can load it in our timer registers. If i directly calculate 1 second value for timer count it comes
out to be greater than 65535 hence 1 second delay can not be directly generated with the above
given information. We have to adjust prescaler or input frequency for directly generating 1 second
delay. For this tutorial i am only going with the 10 ms and running it for 100 times for 1 second delay.
Below is a test program in which i uploaded the above settings. Pic16f877a microcontroller is used in
the project. Xc8 compiler and MPLABx is used for code compilation. An external 20 Mhz crystal is
used as clock source. An led is connected at output of port-b pin#4. Timer-1 of pic16f877a is used to
generate 1 second delay. Led toggles after every 1 second. More advanced tutorials on
toggling/event triggering/blinking an led on specific time delay with pic microcontroller. Click the
below button to visit the tutorial/project.

9. https://www.edaboard.com/threads/1-sec-delay-in-pic16f877a.199831/
You are using an out of date browser. It may not display this or other websites correctly. You should
upgrade or use an alternative browser . 1 sec delay in pic16F877A please can some one tell how to
get an one sec delay in PIC16F877A. i'm glad if anyone can post me the assembly coding for that. i
used the following cording to get that delay.but unfortunately it was too fast. 1st i defined two
counters and put the following function to call when I want delay. delay please help me to come
up with this..because im stucked with this problem. :???: ;PIC Time Delay = 1.0000000 s with Osc =
4.000000 MHz DelayOneSecond 2,500 Code: ; Delay = 1 seconds ; Clock frequency = 4 MHz ;
Actual delay = 1 seconds = 1000000 cycles ; Error = 0 % cblock d1 d2 d3 endc ;999997 cycles
movlw 0x08 movwf d1 movlw 0x2F movwf d2 movlw 0x03 movwf d3 Delay_0 decfsz d1, f goto $
+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_0 ;3 cycles goto $+1 nop ; Generated by
http://www.golovchenko.org/cgi-bin/delay (December 7, 2005 version) ; Sat Jan 22 09:25:39 2011
GMT Here is the code generated by the site in the code. If you intend to use delay several times,
will waste microcontroller processing. The best alternative is to use delay under interrupt
conception. +++ If you intend to use delay several times, will waste microcontroller processing.
The best alternative is to use delay under interrupt conception. +++ I do not follow your reasoning
How will this waste processing time, if it is a routine that is called? Using the interrupt would create
an issue when you wanted a sec delay, what would you use for the interrupt trigger? 138,221 It's
a blocking routine, what Andre_teprom means is that while in the delay loop you are wasting time
that could be used more profitably. If you use one of the hardware timers to generate periodic
interrupts, you can create almost any delay you want and still run other tasks at the same time.
Looking at it from the opposite angle, if you use software loops to create delays and you also use
interrupts for something else, every interrupt will make to delay longer than you want it to be.
Brian. betwixt said: It's a blocking routine, what Andre_teprom means is that while in the delay
loop you are wasting time that could be used more profitably. If you use one of the hardware timers
to generate periodic interrupts, you can create almost any delay you want and still run other tasks at
the same time. Looking at it from the opposite angle, if you use software loops to create delays and
you also use interrupts for something else, every interrupt will make to delay longer than you want it
to be. Brian. Click to expand... I understand that whilst it doing the delay the pic is doing nothing
else, but the original post only states that they want a 1 sec delay, but not in what context (from his
status and the nature of the question, I would assume he is a beginner and interrupts may be too in
depth at this moment in time). John thank you evrybody..means a lot.. can anyone tell me how to
calculate that time delay using counter variable.. var2 equ 0Eh // define the variable in registers
your code Delay movlw 0xFF ;move 255 to w reg movwf var1 ;move 255 w reg to var1
movwf var2 ;move w reg to var2 Loop1 decfsz var1,1 ;check var1 is zero skip if zero goto
Loop1 ;goto loop 1 decfsz var2,1 ;check var2 is zero skip if zero goto Loop1 2,500 Hi If you
use the code above (in my earlier post), you should be able to get an idea of how the calculation
works. On a pic running at 4mHz, most instruction take 1 clock cycle to execute (1uS). There are a
few that take 2, ie Call, Return and Goto are a few. If you download the data sheet for the pic, they
contain the instruction set and the time taken to complete. Using the above details you can
calculate how long each loop run will take to process, and then calculate the overall time to
complete. If you use this link **broken link removed**, you can play around with delay loops and
look at the code produced to achieve the required delay. Hope that helps u can also use built in
function in mikro c pro compiler Delay_ms(2000); ms=milli seconds... just calculate and insert it
in the function .............. ---------- Post added at 16:28 ---------- Previous post was at 16:28 ---------- u
can also use built in function in mikro c pro compiler Delay_ms(2000); ms=milli seconds... just
calculate and insert it in the function .............. u can also use built in function in mikro c pro
compiler Delay_ms(2000); Yes you can, but the original post is using assembler, so it would appear
like that is the route he wants to take. And his request is for assembly code. ---------- Post added at
11:47 ---------- Previous post was at 11:29 ---------- Click to expand... The only problem with your
site is that it all appears to be using 'C' and as previously stated the OP is after assembler. Your site
does not really explain anything it just contains some code with the 'C' delay commands in them.
Some time ago I wrote a utility to help write assembler code for Pic16 series micros and posted it on
eda board here. It can generate code for delays of various lengths, if, while, loops conditionals, etc.
No install is needed, just extract all the files to a directory. Call the directory PicHelp or whatever you
like. Generates code for common constructs in programming. Please give it a go and see if it helps.
thanks alot everyone. I think i can manage it now, cz of ur helps. thank you very much.. :lol: 3,925
One better approach is to avoid the uP to hang only in the delay routine and just to wait the 1000ms
period to expire. The best solution is to use RTOS - in this case you can run several programs into a
single uP (I had in one of my projects with 16F876A 6 inndent tasks simultaneosly running). The best
RTOS for PIC uP is SALVO but you can find also many other RTOS (some even free). You'll be surprised
how powerful becomes the uP when you use RTOS and also your productivity will jump because all
programs become simpler and easier for maintanance. Once you start using RTOS you'll find out
that even without RTOS you could create a program structure which makes possible many different
tasks to executed in the same time. The main challenge is to convert the structure of the program in
such way that it always passes through some common point (you should not loop in single place or
branch). In this place you can put a check for the timer and if 1s expired ypu can execute something.
The structure of the program should look like: Code: void main(void) { while(1) { if
(TIMER1_Overflow) { ResetFlagTimer1(); prescall++; if (prescall > TIME1000ms)
{ prescall=0; //--------- here we pass every 1000ms DoSomething(); } DoTask1();
DoTask2(); ..... } } // endless loop } Separate tasks like DoTask1() could have individual state
machine and they never hold the program flow (like wait 1000ms) for long time. It will take some
time to modify your program but later you'll enjoy smooth

10. https://electronics.stackexchange.com/questions/247720/pic-microcontroller-delay-ms-no-
effect
We have no data for this page, because it isn't accessible for our crawler.

You might also like