View previous topic :: View next topic |
Author |
Message |
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
Unable to make 0 a variable in the program |
Posted: Fri Dec 21, 2018 7:33 am |
|
|
Hello,
İ wrote a code that i want to calibrate a signal but although i equal the pulse variable to zero it take 255 value. When the program increases the pulse value increases to 1FF. İ am about to go crazy. İ need your help. What could be the problem ?İ use proteus vsm debugger that is why i know pulse is 255.
Here is the related part of my code.
Code: |
unsigned long int calibration=1;
unsigned long int main_counter=0;
unsigned long int pulse=0;
pulse++;
delay_ms(1000);
if(pulse == calibration)
{ main_counter++; pulse=0;}
|
Last edited by Ömer Faruk on Fri Dec 21, 2018 8:59 am; edited 2 times in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Dec 21, 2018 8:07 am |
|
|
How do you know?.
Presumably using a debugger?.
If so, are you sure you are looking at the right 'pulse'?.
Remember if pulse is declared in a function (main for example), in the
debugger, it'll be 'main.pulse', not 'pulse'.
It sounds suspiciously as if you are looking at the wrong variable.
Possibly there is more than one 'pulse' in your code.
You don't show us anything to go on. You use 'real_counter', but do not
show it's declaration, then you don't show us where your declarations
are actually made, relative to where they are used.
As a 'general comment', don't use declarations like 'long int'. Use
explicitly sized declarations like 'int16'. A 'long int' is a different size
on chips like the PIC24, compared to a PIC18, so can make it hard
to know what size a variable really is. |
|
|
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
|
Posted: Fri Dec 21, 2018 8:57 am |
|
|
Ttelmah wrote: | How do you know?.
Presumably using a debugger?.
If so, are you sure you are looking at the right 'pulse'?.
Remember if pulse is declared in a function (main for example), in the
debugger, it'll be 'main.pulse', not 'pulse'.
It sounds suspiciously as if you are looking at the wrong variable.
Possibly there is more than one 'pulse' in your code.
You don't show us anything to go on. You use 'real_counter', but do not
show it's declaration, then you don't show us where your declarations
are actually made, relative to where they are used.
As a 'general comment', don't use declarations like 'long int'. Use
explicitly sized declarations like 'int16'. A 'long int' is a different size
on chips like the PIC24, compared to a PIC18, so can make it hard
to know what size a variable really is. |
Hi i solved the problem. I used proteus as debugger. I think when i use proteus vsm proteus spoils hex file. Because i load the program into pic while proteus vsm debugger is open it didn't work. When closed vsm and proteus and load the program into pic this time pic worked. Do you have any idea about this ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Dec 21, 2018 9:43 am |
|
|
sure GET RID OF PROTEUS !!
Please read PIC101 sticky..
In future, when posting questions, say whether you're using real hardware or a simulator. This is CRITICAL information !!
Everyone knows Proteus is a flawed simulator, not to be used or trusted.
Jay |
|
|
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
|
Posted: Fri Dec 21, 2018 10:26 am |
|
|
temtronic wrote: | sure GET RID OF PROTEUS !!
Please read PIC101 sticky..
In future, when posting questions, say whether you're using real hardware or a simulator. This is CRITICAL information !!
Everyone knows Proteus is a flawed simulator, not to be used or trusted.
Jay |
You are right but i have to use proteus vsm because i dont know how to debug in real time. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Dec 21, 2018 10:42 am |
|
|
I've debugged in realtime for decades. It's easy...
1) design program
2) compile
3) download and run on a real PIC, observe what happens.
NO 'debugger' or 'simulator' accurately works 100% the way proper real World testing does. Unless you pay 10's of 1,000 of $$, none.
What I can't understand is the blind faith some have in Proteus, even though it's well known to be flawed, How can you trust something that will give false information.
Jay |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Dec 21, 2018 10:51 am |
|
|
temtronic wrote: | What I can't understand is the blind faith some have in Proteus, even though it's well known to be flawed, How can you trust something that will give false information. |
I believe the phenomenon may be explained by the principle detailed here: https://bit.ly/2T682ra |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Dec 21, 2018 10:52 am |
|
|
Big grin.... |
|
|
|