Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

timer2 explanation

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-8051 Archive
View previous topic :: View next topic  
Author Message
mtheriault2000

Bascom Member



Joined: 12 Oct 2005
Posts: 9

blank.gif
PostPosted: Wed May 31, 2006 4:52 pm    Post subject: timer2 explanation Reply with quote

Hello

I want to use the Timer2 and Int0 at the same time. I want to measure a minimum time that an event occured on the Int0. I just can't have both working together

I'm using a 82S8252 with a 10mhz crystal. I want to use the Timer2 as a time base for my programm. This part of prg is used to detect the presence of a thoot over a metal gear, validate it and increase or decrease a Position counter depending of the value of the Sens bit P0.4(sens of rotation).

To resolve bad reading cause by vibration, i want to use a Counter to validate the presence of the sensor over the gear .

The problem is that the timer2 stop working when an Int0 occured.

Any help whill be appreciated

Martin Theriault

Here is a copy of this part of my prog.

$regfile = 89s8252.dat
$crystal = 10000000
$large
Config Lcd = 20 * 4
Sens Alias P0.3
Gear Alias P0.4
Dim Stop_timer As Bit
Dim Mili_sec As Integer
Dim Seconde As Byte
Dim Counteur As Integer
Dim Position As Integer ' Position par rapport au début
Dim Int0_bit As Bit
Const Numberofthoots= 48
'Set Clkreg
Set Sens
Set Gear
Set Tcon.0 ' Trigger Int0 By Falling Edge.

Config Timer2 = Timer , Gate = Internal , Mode = 0 , Direction = Down
On Timer2 Timer2_int
Load Timer2 , 50000 ' 15 mili secondes

'Priority Set Int0
Enable Int0
Enable Interrupts
Reset Int0_bit
'enable the interrupt
On Int0 Count_gear
Cls
Reset Int0_bit
Position = 1
Mili_sec = 0
Seconde = 0
Enable Timer2
Start Timer2

Do
Home
Lowerline
Lcd Position ; " " ; "g: " ; Gear ; " sens:" ; Sens ; "i: " ; Int0_bit
Locate 3 , 1
Lcd Counter; " " ; Seconde ; " " ; Mili_sec

Loop
End

Count_gear:
Disable Int0
Mili_sec = 0
Compteur = 0
Seconde = 0
Start Timer2
While Mili_sec <= 10
Home
Lcd Mili_sec
If Gear = 0 Then
Incr Compteur
Else
Compteur = 0
End If
If Compteur > 5000 Then
If Compteur > 500 Then
If Sens = 1 Then
Incr Position
If Position > Numberofthoots Then
Position = 1
End If
Else
Decr Position
If Position < 1 Then
Position = Numberofthoots
End If
End If
End If
End If
Wend
'Set Int0_bit
Enable Int0
Set Tcon.0
Return

Timer2_int:
Incr Mili_sec
If Mili_sec = 100 Then
Incr Seconde ' 100*10 miliseconde = 1 seconde
Mili_sec = 0
End If
Reset T2con.7
Return
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-8051 Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum