Attiny416 issue - unsure if really an issue

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


 

Using the TCB0 as an 8bit PWM, where the CCMPH = duty cycle and CCMPL = PWM freq.

 

A bug(?) was discovered when attempting to use the TCB0 CCMP register when writing 8 bit values to the high and low registers of this 16bit register.  I don't know if this is a bug or my misunderstanding.  Please see the listing below regarding my issue.

 

If I write test values:

    TCB0_CCMPL = 0x55;

    TCB0_CCMPH = 0xAA;

this works as expected (see listing - right image)

 

If I write test values:

    TCB0_CCMPH = 0xAA;

    TCB0_CCMPL = 0x55;

 

this does not work.  The low byte is not written.(see listing - left image)

 

Please explain whether this is a bug or my misunderstanding.

Thanks - Jim

 

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

OK - after doing some reading, I see that accessing the CCMP which is a 16bit register uses a TEMP register so that the both the H and L values are written simultaneously. 

So do I understand correctly that I must always write the CCMPL register first followed by the CCMPH register?

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

Yes, the order you read and write H and L bytes on 16-bit registers are important. It should be well documented in the datasheet.

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

Or just write to CCMP, the compiler knows the correct order to read/write 16 bit reg's.

 

i.e.

CCMP = 0xAA55;

or

CCMP = 0x55AA;

 

works everytime!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Earlier AVRs require the opposite order (write H then L, read L then H), which just emphasizes that you should let the compiler remember the correct order for you.

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

Now I know.  Thanks for the help.

Jim