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.

[SOLVED] PIC16F877A: Timer1 Interrupt Problem! (Maybe a different problem from the rest!)

Status
Not open for further replies.
First thing I see is that you have two instances of while(1).

I don't see why you would have while(1) in void manualmode, in this case, once you call void manual mode, it will never return.

Would you like to tell me in plain words what will your design do?

PS: Don't worry, I'm downloading Battlefield Bad Company 2 on steam so I have all the time in the world. :D
 

ok here i go:

i am trying to design a dish drying machine. so i have two options to deal with: auto mode and manual mode. i'm concentrating on my manual mode now as it only needs a time limit to decide on by the user. with that i can configure how fast and how hot i want my fan and heating element to be. at the moment, i am concentrating on fixing my fan to run on a fixed time. that's why i am here now having this interrupt issue, cause i want to have accurate timing.

wow! awesome! :)
 

very good, I understand.

Do you have an oscilloscope?

When you run the code what happens, does it respond to the button presses?

Does it show anything?
 

um regarding the while(1) in manual mode, i need that to display my times in a cycle 10 seconds>20 seconds>30seconds>etc>10seconds again. without it, it's not looping around it.

When i program my pic, i plug it in, it shows a black line of boxes. It does not show anything else. I don't have an oscilloscope :\
 

Go to Mibbit.com - Easy and fast Webchat and launch the webchat, enter your username and join #EDAboard channel.

We can communicate faster, no password needed.

---------- Post added at 02:04 ---------- Previous post was at 02:02 ----------

um regarding the while(1) in manual mode, i need that to display my times in a cycle 10 seconds>20 seconds>30seconds>etc>10seconds again. without it, it's not looping around it.

But what if someone wants to go back, you will have to reset the pic to bring it back to the main loop.
 

alright on the way! umm i never thought of that.. i'll reconsider configuring this.

---------- Post added at 10:34 ---------- Previous post was at 09:09 ----------

Code:
#include <pic.h>
__CONFIG (0x3F32);
#define led1			RB1
#define led2			RB2

unsigned int varinc;
unsigned long counter;

void main(void)
{	TRISB = 0b00000000;
	TMR1H = 11;             // preset for timer1 MSB register
	TMR1L = 220;		// preset for timer1 LSB register
	counter = 0;
	T1CKPS1 = 1;   // bits 5-4  Prescaler Rate Select bits
	T1CKPS0 = 1;   // bit 4
	T1OSCEN = 0;   // bit 3 Timer1 Oscillator Enable Control bit 1 = on
	T1SYNC = 1;    // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
	TMR1CS = 0;    // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
	TMR1IE = 1;         // enable Timer1 interrupts
  	PEIE = 1;          // bit6 Peripheral Interrupt Enable bit...1 = Enables all unmasked peripheral interrupts
	GIE = 1;           // bit7 global interrupt enable
	TMR1ON = 1;    // bit 0 enables timer
	while(1);
}

void interrupt ISR(void)
{
	if(TMR1IF)
   {
      varinc++;
	  led1=~led1;
      if(varinc==10)
    {
		counter++;
		led2=~led2;
		varinc = 0;
    }
      TMR1IF=0;
	  TMR1H=11;
	  TMR1L=220;
   	}
}
 

hey stan4, the interrupts finally working i guess. i added in the while(counter<10) {} part, and yeah, it worked :D i used a stopwatch to guide my counting, and all of it are quite accurate :) if you can, meet me in the EDAboard channel so we can talk more about the next thing i want to propose on doing? thank you!
 
Last edited:

@stan4, if i don't happen to see you today, i want to ask, can i turn on my motor while my interrupts are working?
i tried just now with this code:

Code:
void tenminutes(void)
{
	TMR1ON=1;
	while(counter<10)
{	
	motor_1 = 1;
	motor_speed = 115;
	lcd_clr();								// clear LCD screen 				
	lcd_goto(0) ;							// set the position of message to be displayed
	send_string("Drying In     ");			// send message to be displayed
	lcd_goto(20);							// set the position of message to be displayed
	send_string("Process.     ");

	if(counter>=10)
{
	motor_1 = 0;
	motor_speed = 0;
	lcd_clr() ;								// clear LCD screen 				
	lcd_goto(0) ;							// set the position of message to be displayed
	send_string("Drying Is     ");			// send message to be displayed
	lcd_goto(20);							// set the position of message to be displayed
	send_string("Complete!     ");
}
}
}

and the result isn't so good: when i select the time i want, the motor only moved for like 0.1ms, stopped, and resets itself to main menu where i have to select manual or auto mode again.

i kept trying by selecting time and run it till it came to a point where my LCD displayed alot of rubbish characters, but my motor still won't turn, and kept resetting to main menu. there was once where my motor turned vigorously like mad and stop. that's just it. and it never ran for 10 seconds :\

what do you think i can do? btw timer1 interrupt is working fine. i think i should demonstrate my LCD + PIC on a PCB now.. breadboard's a little unstable. gonna sleep now it's 2.15am :)
 

I have been away most of the day so my apologies for not replying sooner.

Where you saw "while(1);" at the end of an initialization it indicated the program flow should stop at that point and only the interrupts should work. Remember that interrupts can force the program to go to their service routine and afterward return to their previous instructions. What the programmer intended was that the "while" would jump to itself forever, effectively doing nothing but when an interrupt was triggered, it would still run the ISR and then return to the "while" again later.

The reason I suggested the extra variable was that without seeing the remainder of your code, I suspected you might be updating the LCD continuously while waiting for your counter to increment. If that had been the case, my code would have taken you to update the LCD only once as "counter" increased in value. Now I have seen the remaining code I can see my suspicion was wrong.

I can't help via "Windows Live Messenger", it is banned form all my computers and I use Linux anyway! I have Skype if it helps but it doesn't run unless I manually start it.

Brian.
 

@stan4, if i don't happen to see you today, i want to ask, can i turn on my motor while my interrupts are working?
i tried just now with this code:

Code:
void tenminutes(void)
{
	TMR1ON=1;
	while(counter<10)
{	
	motor_1 = 1;
	motor_speed = 115;
	lcd_clr();								// clear LCD screen 				
	lcd_goto(0) ;							// set the position of message to be displayed
	send_string("Drying In     ");			// send message to be displayed
	lcd_goto(20);							// set the position of message to be displayed
	send_string("Process.     ");

	if(counter>=10)
{
	motor_1 = 0;
	motor_speed = 0;
	lcd_clr() ;								// clear LCD screen 				
	lcd_goto(0) ;							// set the position of message to be displayed
	send_string("Drying Is     ");			// send message to be displayed
	lcd_goto(20);							// set the position of message to be displayed
	send_string("Complete!     ");
}
}
}

and the result isn't so good: when i select the time i want, the motor only moved for like 0.1ms, stopped, and resets itself to main menu where i have to select manual or auto mode again.

i kept trying by selecting time and run it till it came to a point where my LCD displayed alot of rubbish characters, but my motor still won't turn, and kept resetting to main menu. there was once where my motor turned vigorously like mad and stop. that's just it. and it never ran for 10 seconds :\

what do you think i can do? btw timer1 interrupt is working fine. i think i should demonstrate my LCD + PIC on a PCB now.. breadboard's a little unstable. gonna sleep now it's 2.15am :)

Well congratulations on your success. :!:

The code you're showing for "tenseconds" function seems ok.

I think you might have a problem with your power supply, because the only way for the PIC to go back to the first loop is by means of a RESET, or a power cycle. I think that when you turn your motor on, inmediately somehow your pic loses it's power supply and resets to the beginning :p.

If you test without the motor connected and your PIC still resets, you might have a problem with your motor drive circuitry; I recommend you to use separate power supplies for the PIC and for the power stage.

I'll be around. My timezone is GMT-6; I think we can perfectly have a chat again, I can be online after 6:00 PM (which should be 8:00 AM for you).

See you, gotta work :grin:
 
Last edited:

Come back flowcharts all is forgiven...
(I highly recommend Crystal Revs if you can afford it)

There's been some good advice in this thread but you seem to be chasing your tail a bit. I'm prone to doing that myself.

Just a suggestion

At this point I'd stop everything and write 2 short programs that do very little.
(Think of them in your head as two new seperate jobs - it helps me to do it that way maybe it will help you)

1. A short routine to output a character to the display.

2. A short interrupt routine that just flashes a led or otherwise toggles something simple.

Once you have both working you can say you know how to make both aspects
of your application work correctly and will have tested the hardware works ok.

Then you can use the 2 programs as templates and insert your actual code
into them.

At this point anything going wrong should be easy to spot.

jack
 

hi guys! i'm sorry for my long absence from the thread. i have been having my mid-term examinations for the past 2 weeks, so yeah i am back. Just to update all of you, i have begun PCB designing, and may begin fabrication as soon as this Friday.. i guess i'll be spending x'mas indoors doing my project :\ anyhow i would like to wish betwixt, stan4, and 123jack a merry x'mas and happy new year :)

@betwixt, i'm glad you are back here to help me! although your suspicion was wrong, it's ok, new things learnt everyday :)

@stan4, thank you! my friends too pointed out that that it should be my power supply issue. they mentioned that sharing power sources will cause a heck of a noise if i am using a motor together, and it will reset. Exactly what you said right here! :) i am glad i got 2 same responses from separate parties! yay! i will update you soon. i hope this message reaches you!

@123jack, hi there, i get what you mean :) i was really beating around the bushes as well. the problem was quite obvious yet it slipped through :\ thanks to stan4, he assisted me very well :) your suggestion did cross my mind a few times before, but my frustration overpowered me to keep focusing on my problem at hand. i guess i should be more patient. i will remember your advice! many more issues yet to come i think.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top