CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Unable to make 0 a variable in the program

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ömer Faruk



Joined: 15 Nov 2018
Posts: 42
Location: Çanakkale

View user's profile Send private message Send e-mail

Unable to make 0 a variable in the program
PostPosted: Fri Dec 21, 2018 7:33 am     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Fri Dec 21, 2018 8:07 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 21, 2018 8:57 am     Reply with quote

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: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 21, 2018 9:43 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 21, 2018 10:26 am     Reply with quote

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: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 21, 2018 10:42 am     Reply with quote

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: 1900

View user's profile Send private message

PostPosted: Fri Dec 21, 2018 10:51 am     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Fri Dec 21, 2018 10:52 am     Reply with quote

Big grin.... Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group