View previous topic :: View next topic |
Author |
Message |
Vinicius
Joined: 04 Jul 2010 Posts: 3
|
MCU 8 bits as 10 bits |
Posted: Sun Jul 04, 2010 3:24 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 04, 2010 4:08 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Vinicius
Joined: 04 Jul 2010 Posts: 3
|
|
Posted: Sun Jul 11, 2010 7:40 pm |
|
|
How to implement it in C using the CCS compiler? Has somehow or function (CCS) specifies?
Grateful |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 11, 2010 10:41 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|