View previous topic :: View next topic |
Author |
Message |
mahdifahime
Joined: 05 Jan 2013 Posts: 22
|
problem by Spontaneous pic |
Posted: Wed Feb 27, 2013 9:09 pm |
|
|
hello
I am working by pic16f72.
The program consists of a several functions.
My problem is with the micro After several days of working on their own.
Why are function calls Spontaneous?
The program uses the timer1 & interrupt timer1. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
mahdifahime
Joined: 05 Jan 2013 Posts: 22
|
|
Posted: Wed Mar 06, 2013 5:53 am |
|
|
Is not resolved problem.
I am work by interrupt timer1.
When a program is in the main function, sometimes order if{} will be ignored and inside order if{} runs. The problem is interrupt timer1. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Mar 06, 2013 6:35 am |
|
|
Can you post a SHORT complete compilable code which shows the problem?
Mike
EDIT Yes I know it's a lot to ask, but you don't give us much to work on. |
|
|
mahdifahime
Joined: 05 Jan 2013 Posts: 22
|
|
Posted: Thu Mar 07, 2013 8:12 am |
|
|
code is :
Code: |
#define led pin_c5
#define pushb pin_b2
int16 sh;int8 ll=0,zr=0;
#int_timer1
void Timer1_isr()
{zr+=1; ll+=1;
if(ll>=255){
sh+=1;}
tmr1on=1; set_timer1(65216);
}
//---------------------------------------------------------
void main(){int8 i; output_b(0b0);
setup_timer_1 ( T1_internal | T1_DIV_BY_1 );
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
set_tris_b(0b00000101);set_tris_a(0b0000011);
while(true){
//*******************push button*****************************************
if(input(pushb)){
sh=0;
output_low(led);
while(input(pushb)){
if (sh>300){
erase();
}
}
}
and Continuation program............
}
//----------------------------------------------------------------------
void erase(){ int16 i=0;
i=0;
while(i<1024){
output_high(led);
write_ext_eeprom(i,255);
delay_ms(2);i++; };
}
|
when the main loop program is running , this goes on:
Code: | if(input(pushb)){sh=0; output_low(led);
while(input(pushb)){if (sh>300){erase();}}} |
and then erase() function runs
but it must not happen.and it is because of timer1 interrupt.
what should i do to stop it?
Last edited by mahdifahime on Thu Mar 07, 2013 12:05 pm; edited 2 times in total |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Mar 07, 2013 8:45 am |
|
|
This is really confusing code. The formatting is so very poor that it makes it difficult to understand what any of it does. If I reformat that little piece of code I get this:
Code: |
if(input(pushb))
{
sh = 0;
output_low(led);
while(input(pushb))
{
if (sh > 300)
{
erase();
}
}
}
|
I think this is meant to detect if the button has been pressed, and then if its held for a time, depending on how often the timer1 ISR runs, then erase() is called. One obvious problem is that if the button is kept down erase() will be called over and over again as sh is never reset.
Also I notice that main starts like this:
that 'm:' is a label, so you must have a goto somewhere. Do you?
There's so much wrong with this code: short, meaningless variable names, very poor formatting, gotos to name only three, that I haven't seen anything like it since the early days of BASIC.
Good luck getting any of it to work!
RF Developer |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Mar 07, 2013 11:01 am |
|
|
I asked for SHORT COMPLETE COMPILABLE code.
I want something I can cut and paste without too much effort on my part.
After all, you're the one asking for help.
Also:-
You have not used the code button.
It preserves formatting which helps make code easier to read.
Mike
+++++++++++++++++++
He edited to use Code button after Mod's suggestion.
- Forum Moderator
+++++++++++++++++++ |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Mar 07, 2013 1:24 pm |
|
|
please post your master clock /delay statement
also
as coded the timer int is going to be called VERY frequently -
AND
when you call ERASE() - it's execution is bound to be much longer than any one timer #int period
unless the master clock is 5khz or so |
|
|
mahdifahime
Joined: 05 Jan 2013 Posts: 22
|
|
Posted: Thu Mar 07, 2013 11:48 pm |
|
|
asmboy wrote: | please post your master clock /delay statement
also
as coded the timer int is going to be called VERY frequently -
AND
when you call ERASE() - it's execution is bound to be much longer than any one timer #int period
unless the master clock is 5khz or so |
please give me an example that in loop interrupt timer1 write in external eeprom.
thanks |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Mar 08, 2013 6:11 am |
|
|
We always ask for a complete, compilable, program. That is because it makes it easier to us to just copy/paste your program, but also because then we have your fuses and delay statements.
So, as someone else already asked, please post your #fuses and #delay lines.
Code: | //*******************push button*****************************************
if(input(pushb)){
sh=0;
output_low(led);
while(input(pushb)){
if (sh>300){
erase();
}
} | Assuming your clock is running at a slow 2MHz, you will have to hold the push button for 4.9 seconds to activate erase, but at 20MHz it activates in just 0.49 seconds.
Do you see why we want to know your clock frequency?
Quote: |
please give me an example that in loop interrupt timer1 write in external eeprom. | Sorry, but I don't understand the question. Can you give a longer explanation of what you want to do? |
|
|
|