Migrating Processors: clock registers not setting correctly

Beta Testing discussion on mikroC PRO for AVR.
Post Reply
Author
Message
rrsquez
Posts: 117
Joined: 23 Feb 2011 21:35

Migrating Processors: clock registers not setting correctly

#1 Post by rrsquez » 19 Jan 2016 00:30

Hello, I have a problem migrating from the ATmega128A to the ATmega2561. I honestly think I have found a valid BUG.

I have a project that works well with the ATmega128A at 8Mhz. I took a sample board and dropped in an ATmega2561 which is pin-compatible. I use nothing but identifier labels to access port pins (no hard coded address anywhere).

The problem is that the ATmega2561 board moves proportionally slower. For example, leaving the setting at 8Mhz, the unit move 8X slower. If I use 4MHz, it moves 4X slower. If I use 1MHz, it works perfectly.

By 8X and 4X slower, I'm referring the time delays and baud rates I have observed.

I have another post regarding the Ow_Read() command. If I use 1Mhz for either processor, it doesn't work correctly. At first I thought these were separate issues, but now I see they are both related to the system clock.

By the way: I am using the internal RC oscillator.

Thank you, Richard V

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Migrating Processors: clock registers not setting correc

#2 Post by filip » 19 Feb 2016 09:33

Hi,

Have you tried toggling the CKDIV8 fuse bit ?

Regards,
Filip.

rrsquez
Posts: 117
Joined: 23 Feb 2011 21:35

Re: Migrating Processors: clock registers not setting correc

#3 Post by rrsquez » 22 Mar 2016 21:36

Hello Filip. Changing the ClockDiv8 signal was the very first thing I did. After reading through Atmel's datasheets I found that I need to add some code to make the migration from the 128K part to the 256K part. I added in this code and all is well.

Here is my code:
// ***************** Support for ATmega2561 only. This will not work with the ATmega128A *****************
// Set up CPU clock
CLKPR = 0x80; // Set Bit 7 to 1 and all other bits to 0. This fixed the clock speed issue
CLKPR = 0x0; // Must be done within 4 cycles of the above command
// Disable JTAGEN
MCUCR = 0x80; // Disable JTAGEN //
MCUCR = 0x80; // Must be written twice, within 4 cycles
// *************************** END Support for ATmega2561 ***************************

Now I know this is the wrong forum to ask this, but how I do I create the BASIC version of the above code?

Thank you, Richard V

Post Reply

Return to “mikroC PRO for AVR Beta Testing”