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] TMR0 problem in PICBASIC PRO

Status
Not open for further replies.

alokdaga

Member level 2
Member level 2
Joined
Feb 10, 2011
Messages
44
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Visit site
Activity points
1,479
I have enabled tmr0 in 16f72. I am using the following code:

Code:
DEFINE OSC 4
i var byte
ADCON1=7

Include "modedefs.bas"

op var porta.0
led var porta.1
'
Date	var byte
Month	var byte	
Year	var byte
Hour	var byte
Minute	var byte
Second	var byte
TICKS VAR BYTE

   ' Set TMR0 to interrupt every 16.384 milliseconds
  OPTION_REG = $55 ' Set TMR0 configuration and enable PORTB pullups
   INTCON = $a0     ' Enable TMR0 interrupts
   On Interrupt Goto tickint

LOW LED
Main:
Toggle OP
pause 4000
 GOTO MAIN

tickint:
DISABLE
   ticks = ticks + 1          ' Count pieces of seconds
   If ticks < 61 Then tiexit  ' 61 ticks per second (16.384ms per tick)

' One second elasped - update time
   ticks = 0
   second = second + 1
	TOGGLE LED
   If second >= 60 Then
      second = 0
      minute = minute + 1
      If minute >= 60 Then
         minute = 0
         hour = hour + 1
      Endif
   Endif
  

tiexit:
   INTCON.2 = 0    ' Reset timer interrupt flag
   INTCON.1=0
   Resume

End

If I do not use the pause command in main loop - LED toggles rightly else it does not... Can anybody guide suitable...
 

hi,
If I understand your post correctly, without the pause 4000, the LED is not toggling correctly.??
Code:
Main:
Toggle OP
pause 4000
 GOTO MAIN

The main loop has a much shorter time period than 16mSec, so it will toggle the OP at a fast rate and when the tickint occurs the toggled state could be High or Low.
Only toggle OP when an interrupt has occurred, set a flag bit when interrupted.

Is this what you are asking.??
E
 

Hi,

In PBP, an interrupt cannot happen while the pause statement is being executed.

If you really need a 4 second pause, nest 2 or more loops, exch with a much smaller pause duration to get a total of 4 seconds.

Regards.
 

Yes... that is the problem .... when using Pause - interrupt is not happening.... any way to solve that? as My time count will get disturbed if interrupt is not generated properly...

- - - Updated - - -

hi,
If I understand your post correctly, without the pause 4000, the LED is not toggling correctly.??
Code:
Main:
Toggle OP
pause 4000
 GOTO MAIN

The main loop has a much shorter time period than 16mSec, so it will toggle the OP at a fast rate and when the tickint occurs the toggled state could be High or Low.
Only toggle OP when an interrupt has occurred, set a flag bit when interrupted.

Is this what you are asking.??
E

With the pause - the interrupt does not happen.. any way out to solve this?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top