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.

Switch Statement for PIC Microcontroller

Status
Not open for further replies.
No, I am not counting manually. For manually counting you have to use the webpage link I provided. it shows for Timer0. For Timer1 you have to change to 16 bits. Max value 256 is replaced by 65536 and Timer releload value is split into high byte and low byte. If you want I can show you Timer1 calculation example for 300 ms.
 

No, I am not counting manually. For manually counting you have to use the webpage link I provided. it shows for Timer0. For Timer1 you have to change to 16 bits. Max value 256 is replaced by 65536 and Timer releload value is split into high byte and low byte. If you want I can show you Timer1 calculation example for 300 ms.

Actually i already tried the calculation by referring some online example as below:

Interrupt time: 300ms
Clock Freq : 4MHz
Prescaler: 8

300ms * (4Mhz)/ (4*8) = 37500

65535 - 37500 = 28035

TMR1H = 28035/256 = 109
TMR1L = 15535 - (256*109) = 131

TMR1L should be 15536 - (256*109) = 132;
My question is, where did 15536 and 256 come from?
Some tutorial also mention that for prescaler, I need to calculate the division ration as 500000/8 = 62500.
But I am wondering what is this value for.
Do you mind to explain these to me?
 

No, I am not counting manually. For manually counting you have to use the webpage link I provided. it shows for Timer0. For Timer1 you have to change to 16 bits. Max value 256 is replaced by 65536 and Timer releload value is split into high byte and low byte. If you want I can show you Timer1 calculation example for 300 ms.

Hi, Okada, I still have some doubt on the code.
In sample that you provided for me, you set the Timer1 interrupt time to be 300ms.
is this means that the LED on off delay is 300ms?
 

Yes. The Timer1 interrupt occurs once every 300 ms and once every 300 ms the LED is toggled. It is a non-blocking code. when Timer register overflows then TMR1IF_bit is set and when this bit is set interrupt service routine (ISR) is called and the code inside ISR is executed and after that code execution returns to where it was earlier. So, ISR is services in a short time say 1 ms every 300 ms and then while(1) loop will be executing other times and so button press can be detected.
 
Yes. The Timer1 interrupt occurs once every 300 ms and once every 300 ms the LED is toggled. It is a non-blocking code. when Timer register overflows then TMR1IF_bit is set and when this bit is set interrupt service routine (ISR) is called and the code inside ISR is executed and after that code execution returns to where it was earlier. So, ISR is services in a short time say 1 ms every 300 ms and then while(1) loop will be executing other times and so button press can be detected.

Ok. and i was thinking about what if i want to make the LED blinking for 1s interval.
I tried with the calculation and i realize the value is more than 65536.
Is that any other method for this?
 

If you are using a 4 MHz crystal then make a 500 ms timer1 delay and then use a counter in ISR. If this counter is 2 then it means 1 second has elapsed. Check for this condition and toggle the LED.
 
If you are using a 4 MHz crystal then make a 500 ms timer1 delay and then use a counter in ISR. If this counter is 2 then it means 1 second has elapsed. Check for this condition and toggle the LED.

i see. I will try it out then. thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top