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.

AT89s52 as event counter

Status
Not open for further replies.

NRollick

Newbie level 5
Joined
Mar 28, 2018
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
64
hi,I want to design a 'event counter ' where I want to rise an interrupt flag exactly after 10 pulses and my input is continious.
I m using at89s52, counter1 is loaded with 16bit mode
with TL1=FEH AND TH1=FFH,TMOD=50H
INPUT IS FROM IR SENSOR,IF IR DETECT 10 TIMES THEN THE FLAG MUST BE HIGH,BUT IT IS NOT HAPENING WITH THE LOADED VALUE ON TH1 AND TL1....FOR INDICATION I AM USING AN LED ON P1.0,,, IT WILL GLOW IF TF1 VALUE IS 1....
 

**broken link removed**
**broken link removed**
the above links may help you .
 
Last edited:

The state of Gate control for timer1 is '0'in your code .
Then set TR1 bit HIGH to start counting.
 

the code is working properly in keil ver4 but after loading hex and IR SENSOR is connected AT P3.5....it is not giving result
IT MUST BE SUCH THAT ON COUNTING 10 TIMES FROM IR SENSOR ...IT MUST MAKE LED GLOW ....BUT ON CONTRAST ON DETECTION OF 1 TIME LED GLOWING....
 

Thinking to use timer2, capture mode...any sugestion would be helpful...
 

Hi,

what about posting
* your exact code
* your schematic
* informations like microcontroller clock frequency, supply voltage
* informations like signal minimum time between edges, signal levels
* and all other related informations.

Klaus
 


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//THIS CODE IS FOR 8051, AT89S52,CRYSTAL USED=11.0592 FREQUENCY
//IF IR DETECTS 10 TIMES THEN THEN THE PIN P1.4 MUST GO LOW
 
        ORG     00H
 
XC:     JB      P1.2,$                  //TO START PROGRAM
        SETB P1.4                          //LED ON                                                                     
Vv:     MOV     TMOD,#01010000B         //16 BIT COUNTER1 SELECTED
        MOV     TH1,#0FFH               ;LOADED  ON TH1 &TL1..FFF5
        MOV     TL1,#0F5H
        SETB    TR1                     //START COUNTER                         
VB:     JNB     tf1,vb                  //CHECK TF1 FLAG OVERFLOW
        CLR     P1.4                    //LED OFF                               
        clr      TR1                    //STOP TIMER                    
        clr     tf1                     //CLEAR TF1 FLAG
        
        SJMP    XC              
                
        END



IMG_20180511_144416.jpg
 

Hi,

The LED is (almost) all the time ON.
This is what your code says.

At line 7 you set the LED ON.
then it waits for 10 IR input edges.
At line 13 it shuts LED OFF
... but a couple of microseconds later
You jump to "XC" ...and at line 7 the LED is switched ON again.

--> The LED will go OFF, but your eyes and our brain isn´t fast enough to detect this couple of microseconds until it is ON again.

Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top