rpm counter using atmega8

Status
Not open for further replies.

likitha.b

Newbie level 5
Joined
Mar 4, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,370
hi,

can someone tell me how write a embedded c code to count rpm in atmega8 , but using interrupt.
 

enable the external interrupt pin on which sensor is supposed to attached and write subroutine to increase the "count" at that interrupt's vector address..
regards.
 
enable the external interrupt pin on which sensor is supposed to attached and write subroutine to increase the "count" at that interrupt's vector address..
regards.
int flag=1;
{
cnt++;
TCNT0=0x0ff;
flag=0;
rpm=cnt/12;
flag=1;
}
i have written this program to count the rpm will this be correct.
 

int flag=1;
{
cnt++;
TCNT0=0x0ff;
flag=0;
rpm=cnt/12;
flag=1;
}
i have written this program to count the rpm will this be correct.

you have posted a part of code this doesn't make any sense e.g timer is loaded why?? flag is set high and low... in short I don't get it completely...
better you explain your idea and earn the suggestion from others.
Regards.
 

Inside the interrupt routine you increment the counter and after required interrupt count has reached then you set a flag. You then execute some code in the while(1) loop of the main() function when the flag in the interrupt routine is set and you clear the flag in the while(1) loop.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ISR(){
If interrupt_flag_bit_of_mcu true
count++
If count == 1000
flag = 1
}
 
void main() {
 
      while(1) {
           if(flag == 1) {
                 flag = 0;
                 //do something
           }
 
      }
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…