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

MCU 8 bits as 10 bits

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



Joined: 04 Jul 2010
Posts: 3

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

MCU 8 bits as 10 bits
PostPosted: Sun Jul 04, 2010 3:24 pm     Reply with quote

People,

I am developing a project of a robot position control. To begin with I am working on an engine modeling of a CC Engine with gearbox - I´ve already finished this part.
I am using a micro-controller 18F2480 to begin with. Its MCU is 8 bits. I would like to know how can I make it work internally as if it were 10 bits, that is to say, to make some type of masking.

Thanks,




Estou desenvolvendo um projeto para controle de posição de um robô. Primeiramente estou fazendo a modelagem de um motor CC com caixa de redução (já fiz).
Estou utilizando o microcontrolador 18F2480 a principio. Sua MCU é de 8 bits, gostaria de saber como faço para trabalhar internamente como se fosse 10 bits, ou seja, fazer algum tipo de mascaração.

Grato
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 4:08 pm     Reply with quote

Use int16 variables. Do a bitwise AND (& operator) with 0x03FF.
This will set the upper 6 bits to zero. The useful data will be in the
lower 10 bits.

Or, if you already know the int16 value has been set to a number
between 0 to 0x3FF (0 to 1023), then you don't need to mask it.
The upper 6 bits are already set to 0.
Vinicius



Joined: 04 Jul 2010
Posts: 3

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

PostPosted: Sun Jul 11, 2010 7:40 pm     Reply with quote

How to implement it in C using the CCS compiler? Has somehow or function (CCS) specifies?

Grateful
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 11, 2010 10:41 pm     Reply with quote

Use the data type 'int16' to declare your variables.

If you read byte values from i/o ports or eeprom, then use the make16()
function to combine the bytes into 16 bits. It's explained in the CCS
manual.

If you want to use the A/D converter, then configure to run in 10-bit mode
and load the result into a variable that has been declared as 'int16'.
This is explained in the CCS manual. Here is a sample program:
http://www.ccsinfo.com/forum/viewtopic.php?t=42763&start=1
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