ATtiny202 - bits doubling

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any way how to double bits in the 4 bits nibble in XC8 compiler or AVR ASM ? E.g. from 0b00001110 I need to get 0b11111100. It will help me to encode data (~(x^0b10101010) with Manchester code. x is doubled bits value

This topic has a solution.
Last Edited: Tue. Mar 9, 2021 - 12:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since it's only a nibble then make a 4 bit LUT with the 16 one byte results. 

 

add:

0x00,0x03,0x0c,0x0f,

0x30,0x33,0x3c,0x3f,

0xc0,0xc3,0xcc,0xcf,

0xf0,0xf3,0xfc,0xff

 

 

Last Edited: Mon. Mar 8, 2021 - 11:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could probably do it with something resembling those clever multiply-based bit-reversal/interleaving hacks.  If you had convenient 32bit multiplies. :-(
the table lookup sounds much more reasonable!

https://graphics.stanford.edu/~s...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Have you checked out Appnote TB3218 ?  It shows a method of piping SPI thru a CCL to get Manchester out. Let the hardware do the heavy lifting.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its only at around 1k bits/s - so swings and roundabouts really. Easy enough to determine the bit flip when outputting it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another way is just brute-forcing it:

 

bst   r24, 3
bld   r24, 6
bld   r24, 7
bst   r24, 2
bld   r24, 4
bld   r24, 5
bst   r24, 1
bld   r24, 2
bld   r24, 3
bst   r24, 0
bld   r24, 1

I think (haven't checked) the table method will use slightly more flash than this, but the table lookup will also be faster.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found a solution, I simply calculated the results and stored the values in an array:

volatile uint8_t XNOR[16] = {0x55, 0x56, 0x59, 0x5A, 0x65, 0x66, 0x69, 0x6A, 0x95, 0x96, 0x99, 0x9A, 0xA5, 0xA6, 0xA9, 0xAA};

 

For value x = 0xA is the result 0x99 i.e.:

10101010 Mask
11001100 Replicated 4 bits 0xA (nibble) to full byte

------------

10011001  XNOR Result (see Binary Bitwise XNOR Calculator)

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just did what you asked for ;)

 

Add:

And for the other way perhaps look here :

 

www.avrfreaks.net/forum/cheesies...

 

OMG it's a 15 year old thread

Last Edited: Tue. Mar 9, 2021 - 10:22 AM