Jump to content
Coder

Timing With Unsigned Char Vs Char

Recommended Posts

Hello,

 

sorry, i found a problem, that i can't understood. Hope someone can help me...

 

I used following code:

 

##########

unsigned char cFilter = 0x80;
for (char c=0; c<8; c++)
{

ToggleOutput(); // toggle a output on the pic
cFilter >>= 1; // or /=2; Same result
}
##########

I connected a Oszi on the output and look at the screen. I saw that the output toggle not on a staibe frequency. It startet slow and with every toggle faster (half time).

 

After some tests i found out, that some changes set the code in correct function:

##########

char cFilter = 0x80;
for (char c=0; c<8; c++)
{

ToggleOutput(); // toggle a output on the pic
cFilter >>= 1; // or /=2; Same result
}
##########

 

Could someone explain me, why this is like that.

In the manual we could read: "Use unsigned data types wherever you can, and signed only when necessary"

 

Thank you for your help.

Coder

Share this post


Link to post
Share on other sites

Coder,

 

The reason to use unsigned data types where possible is because extra work has to be done with signed data types such as sign extension.

 

One thing that might give what you describe is aliasing. What is the sample rate of your Oscilloscope (needs to be at least 2x the frequency you try to measure), if its too low then you get beating effects that make frequencies appear much lower than they are.

Maybe the signed code was so much slower that the frequency produced did not then suffer from aliasing issues.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...