Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 28, 2024, 07:53:47 19:53


Login with username, password and session length


Pages: [1]
Print
Author Topic: interupt problems  (Read 3135 times)
0 Members and 1 Guest are viewing this topic.
manoj
Inactive

Offline Offline

Posts: 4

Thank You
-Given: 8
-Receive: 0


« on: March 12, 2008, 12:05:36 12:05 »

hi
pls see my program to count the period between two  pulses.I didn,t get anything and I think the interrupt is not working. pls helplong int x=0,y=0,tmpl=0,tmph=0,oldstate=0;

 long int x=0,y=0,tmpl=0,tmph=0,oldstate=0;
 long int j;
 char count[10];
 void main (){
 Lcd_Init(&PORTB);
 TRISA=255;
 TRISB=0;
 INTCON.GIE=1;
 INTCON.PEIE=1;
 PIR1.TMR1IF=0;
 PIE1.TMR1IE=0;



if(Button(&PORTA,0,1,0)) oldstate=0;
 if (oldstate&& Button(&PORTA ,0,1,1)){
 PIE1.TMR1IE=1;
 T1CON.TMR1ON=1;}

 while(PIR1.TMR1IF==0){
 T1CON.TMR1ON=0;
 INTCON.GIE=0;
 INTCON.PEIE=0;
 PIR1.TMR1IF=0;
 PIE1.TMR1IE=0;}
  tmpl=TMR1L;
  tmph=TMR1H;
  y=1000000*x;
  j=(tmpl+tmph+y);
  IntToStr(tmpl,count);
  Lcd_Cmd(LCD_CLEAR);
  Lcd_Cmd(LCD_CURSOR_OFF);
  Lcd_Out(1,2,"HEART RATE:");
  Lcd_Out(2,3,count);
  }
   void interrupt(){
   while(PIR1.TMR1IF){
   x++;
   PIR1.TMR1IF=0;}
   }
   
Logged
vovchik02
Junior Member
**
Offline Offline

Posts: 62

Thank You
-Given: 43
-Receive: 13



« Reply #1 on: March 13, 2008, 06:51:20 06:51 »

You don't show type of compiller.

In firtht part of code you activated interrupt,in second half turn off timer?   and wait int TMR1IF(if T1CON.TMR1ON=0 then  TMR1IF never set 1).

 Interrupt rotine isn't correct. See appNote  for You compiller and MCU.
Use simulator for test code.
GOOD luck!
Logged
veiledcavalier
Newbie
*
Offline Offline

Posts: 11

Thank You
-Given: 8
-Receive: 0


« Reply #2 on: March 14, 2008, 10:39:52 22:39 »

1-if u r using ccs try to use wizard, i know it seems bad, but just try something simple as a start

2- try not to put all ur code as a one block, divide it into subblocks which make it easier for debugging
Logged
Bugman
Guest
« Reply #3 on: March 24, 2008, 10:10:16 22:10 »

hi. make your code more readable by commenting it and using miningfull aliasis. when programming   a ucontroler in C try to hide the specifities of your controler by using some #defines. this will be very helpfull for some one else ho want to your code. try to comment your code and send it back please.

Posted on: March 24, 2008, 06:54:07 18:54 - Automerged

taking my time looking this code, i have many remarks:
    - the first part are initialisations (no poblemo);
    - in the second part, you rwite "if(Button(&PORTA,0,1,0)) oldstate=0;
                                              if (oldstate&& Button(&PORTA ,0,1,1)){
                                                   PIE1.TMR1IE=1;
                                                   T1CON.TMR1ON=1;}"
         there you assign a value 0 to oldstate, i think, when there is no action on the input.
         that means "oldstate" always have the value 0 when executing the next "if". that make        the stement "oldstate&& Button(&PORTA ,0,1,1)" allways false.
        - look at the begining of the thid part. you start it by "while(PIR1.TMR1IF==0)". this is always true because you disable your timer in the next line, the count is blocked.
        - desabling interupts is not at the right place, i think.
do you see those errors or wrong i am?
Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #4 on: March 25, 2008, 05:33:44 17:33 »

You don't call Yr. interrupt routine from main... Have a look at Yr. compiler manual for details abt. interrupt handling
Logged

Code Warrior
jasonix
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 48
-Receive: 3


« Reply #5 on: March 27, 2008, 06:30:54 18:30 »

HI, manoj its very important read carefully datasheets about micro you are using, e.g. if is the 16f84 or 16f628 or 16f87x. For f84 or f628 you can use the RA4 with internal counter TMR0 or RB0 to work directly with external interruption configurable in INTCON. I think the main problem is in Hardware and not in the source code (program).
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC