AMcTools Forum 
  HomeHelpSearchLogin  
 
Pages: 1 2 
Send Topic Print
ATmega168 Peripheral Models (Read 43623 times)
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
ATmega168 Peripheral Models
09/15/09 at 23:06:18
 
I think I have the TIMER0 model finished. This is for use with the new "ATmega168b" AVR which uses the external .ini and .dll files for user defined peripherals. If anyone wants to start testing with it, keep in mind that all the other peripherals are still using the old builtin models that don't quite match the 168.

All waveform and output compare modes should work. The TSM & PSRSYNC bits in GTTR are emulated. The PRTIM0 bit in PRR is emulated.

When modifying registers manually from the GUI, keep in mind that OCR0A/B are double-buffered in PWM waveform modes. Changing it in the GUI will actually change the value in the buffer (might seem confusing at first). You may have to right click on the register and select "Modify / browse" from the pop-up menu so your changes are atomic.
Back to top
« Last Edit: 01/03/10 at 07:03:30 by ThVortex »  
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
ATmega168 TIMER0/2 Models
Reply #1 - 10/09/09 at 08:51:16
 
TIMER2 is now supported (including asynchronous operation) by my user AVR peripherals. The new dlls/ini and a detailed description are available at:

http://sites.google.com/site/thvortex/vmlab/useravr
Back to top
 
 
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #2 - 01/03/10 at 07:10:57
 
I just added support for the 16-bit TIMER1. The attached zip file contains updated INI/DLL files and source code that should be copied to the "mculib" directory. The same files can also be downloaded from my website.
Back to top
 
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #3 - 02/26/10 at 20:38:04
 
I now have the ATmega168 watchdog fully implemented. I think someone on the forum was trying to use it and had problems with the old internal model. The attached zip file contains updated INI/DLL files that go in the "mculib" directory. The source code is available on my website.

Back to top
 
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #4 - 03/23/10 at 05:19:25
 
The analog comparator is partially implemented. All bits in ACSR are emulated included ACIC which allows using the comparator as the input capture for TIMER1. The only missing functionality is the multiplexed input on the negative side (AIN1) of the comparator. That won't be available until I have the A/D converter finished.

The following bug also exists: if the analog comparator interrupt was enabled by writing ACIE=1 in the ACSR register, and the AVR was reset using the RESET pseudo-pin, a watchdog timeout, or one of the "Force RESET" buttons in the "Special Purpose" register window, then the comparator interrupt will remain enabled even though the ACIE bit is initialized to zero after the reset. This should be fixed in the next VMLAB release.
Back to top
 
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #5 - 03/24/10 at 05:49:29
 
I just figured out a workaround for the interrupt bug involving resets and ACIE=1. This should no longer be a problem. The updated DLLs are included.
Back to top
 
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #6 - 07/01/10 at 09:43:40
 
I now have the EEPROM component emulated in a DLL. You can download the file directly from [url=http://thvortex-vmlab.googlecode.com/files/useravr-0.6.zip]here[/url] (it's too large to attach). Notice that one of the .dll files goes in the "bin" directory while the rest go into "mculib".

For those who can't access [url=http://sites.google.com/site/thvortex/vmlab]my website[/url] from China, here is an excerpt describing the new component (split across two posts):
[list]
[*] All bits in the EECR are emulated, and all programming modes defined by EEPM are supported. The level triggered ERDY interrupt is emulated.
[*] The component will not simulate any EEPROM programming delay to speed up the simulation (the EEPE bit in EECR always reads 0), unless the "Simulate erase/write time" option in the GUI is checked.
[*] The "Save" and "Load" buttons in the GUI can be used to transfer the EEPROM memory contents to and from a file at any time. Supported file formats include Intel HEX, Motorola S-Record, Atmel Generic, and raw binary data. The "Erase" button can also be used to reset the EEPROM to a fully erased $FF state.
[*] The "View" button will open a separate hex editor window to allow manual editing of the EEPROM memory contents. Right clicking in the editor window opens a context menu with commands to copy the current data selection to the Windows clipboard in several formats and to display a "Find" dialog box, allowing searches for UTF-8/16 string patterns and for hex data in either little or big endian layout. The editor also supports a multi-level Undo/Redo (currently only accesible from the context menu and not via Ctrl+Z or Ctrl+Y) and has support for selection filling (typing hex or ASCII characters while a selection is active will change all the bytes included in that selection).
[/list]
Back to top
 
 
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #7 - 07/01/10 at 09:46:02
 
And now for the limitations:
[list]
[*]Due to a bug in the current VMLAB version, none of the GUI buttons in the control will respond to mouse clicks until the project file is built at least once (using the Project->Build menu item or the F9 shortcut key). Afterwards, the buttons will continue to work normally until a new project file is opened.
[*]In the next VMLAB version, the "Persistent" checkbox will be enabled and the EEPROM memory contents will be automatically preserved across multiple simulation runs.
[*]On real AVR hardware, the Flash and EEPROM memories cannot be programmed at the same time. Currently VMLAB neither detects nor enforces this restriction.
Back to top
 
 
WWW   IP Logged
mixjoe
YaBB Newbies
*
Offline

I Love YaBB 2!

Posts: 10

Re: ATmega168 Peripheral Models
Reply #8 - 08/18/10 at 08:25:44
 
ATmega168 seems not implemented yet the FastPWM with ICR1=TOP
(Mode 14, Tab.15-4, ds ATmega168).

Could you give me confirm?

Thanks
Back to top
 
 
  IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #9 - 08/18/10 at 18:13:19
 
To use the new models I wrote, you'll have to use this in your project:

[tt].MICRO "ATmega168b"[/tt]

Without the "b" you end up using the builtin model which doesn't support the new style timers. Of course, make sure you also have the latest versions of my DLL files in your "mculib" directory.
Back to top
 
 
WWW   IP Logged
mixjoe
YaBB Newbies
*
Offline

I Love YaBB 2!

Posts: 10

Re: ATmega168 Peripheral Models
Reply #10 - 08/18/10 at 18:24:52
 
I copied files as described and added "b"
but I have several issues:

1) Clock is set to 8MHz:

[code]>>: Selected 8MHz calibrated internal RC oscillator (CKSEL fuses = 0010)[/code]

evend if I specified my system clock with the directive .CLOCK

2) Unable to set to 1 WGM13 bit of TCCR1B. Please, would you so kind to verify this code:

[code]
#include <avr/io.h>





int main (void)

{


  DDRB |= (1 << PB1);  // set PB1(OC1A) as output
  ICR1 = 399;  // Ts=1ms @ fc=4MHz
  OCR1A = 99;  // d.c.=10% (Ton=.1ms)
  TCCR1A |= (1 << WGM11);  // non inv. - fast PWM (ICR1=TOP) WGM11=1

 TCCR1B |= (1 << WGM13) | (1 << WGM12); // no presc. - fast PWM (ICR1=TOP) WGM13:2=1

TCCR1A |= (1 << COM1A1);

TCCR1B |= (1 << CS10);

  while(1)
;

}


[/code]

In VMLAB I view  TCCR1B as:

[code]
00001001
[/code]

while, according the above code,
it should be (for FastPWM with ICR1=TOP):

[code]
00011001
[/code]

and infact VMLAB releaves configuration as FastPWM 9bits

And finally I have a strange warning in VMLAB log:

[code]
[PC = $006C, Time =    0.79 ms, {TIM}]: TIMER is in PWM mode: some OC pin not defined as output
[/code]

The TCCR1B issues happens also using ATmega168 builtin model so I was thinking it was a bug still not fixed.

Regards
Back to top
 
 
  IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #11 - 08/18/10 at 20:52:14
 
AVRs ship with the CKSEL fuses set to 0010 which selects the 8Mhz internal clock. The component emulates the same behavior and ignores the .CLOCK directive unless you specify a different fuse setting like this:

[tt].MICRO "ATmega168b CKSEL=0000"[/tt]

Now it will honor the .CLOCK directive although the clock will still get divided by 8 because of the default CKDIV8=0 fuse. So what you really want is:

[tt].MICRO "ATmega168b" "CKSEL=0000 CKDIV8=1"[/tt]

[hr]
As far as the timer issue, I don't think you have my latest DLLs. Looking through my code, I never print that exact warning message. I have a similar message but it is worded as ""OCnA enabled but pin not defined as output in DDR".

Make sure that in the "Peripherals" window you see "TIMER1: TIMERN_168.DLL". You can also go to my [url=http://sites.google.com/site/thvortex/vmlab/useravr]AVR Peripherals[/url] webpage and compare the TIMER1 screenshot to what you see.

On that same website you'll find a "useravr-0.6.zip" file that contains the latest version of my DLLs.

Finally, double check that you have the right #include in your .c file with the definitions for this micro. I noticed you have ICR1 and OCR1A in your code, but these are 16 bit registers. I would have expected a compile error unless you use OCR1AH, OCR1AL, ICR1H, or ICR1L.
Back to top
 
 
WWW   IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #12 - 08/19/10 at 03:16:13
 
Sorry, disregard my last comment about ICR1 and OCR1A. I'm used to programming the AVR in assembly where you would have to load the low and high registers separately. Of course, the C compiler can just define them as a "short" and generate the proper instruction sequence. Your code looks fine.

One more thing. There was another message thread on the forum called [url=http://www.amctools.com/cgi-bin/yabb2/YaBB.pl?num=1268936245]'atmega168b' supported for assembler only[/url]. You may have to rename the .ini file like described in that thread to use the new DLL models with a C compiler.

Back to top
 
 
WWW   IP Logged
mixjoe
YaBB Newbies
*
Offline

I Love YaBB 2!

Posts: 10

Re: ATmega168 Peripheral Models
Reply #13 - 08/19/10 at 11:57:35
 
[quote author=6C6B6D66757A686C1F0 link=1253052379/0#11 date=1282161134] On that same website you'll find a "useravr-0.6.zip" file that contains the latest version of my DLLs.[/quote]

I think to have found where is the issue.

I'm running VMLAB on Linux (through Wine) and, as you well know, case matters. So, your DLL files have different case from the built in ones. Then when I extract your ini file it hasn't overwritten the builtine ini file.

So your:

[code]AtMega168b.ini[/code]

is case different from than builtin:

[code]ATmega168b.ini[/code]

I think VMLAB read build version instead of newer one.

PS Hope I explained well and sorry for my little english :)

UPDATE: [b]Now all works fine[/b]! Deleting the builtin ATmega168b.ini, your library is correctly used!

But...I had to change the code. ICR1 must be set after I set FastModePWM with ICR1=TOP.... and your _great_ DLL warned me with a message something like: "you can't use ICR1 because it's only read unless you set as TOP ;)"

Thank you for this great library!

The fixed code then is:

[code]
#include <avr/io.h>

int main (void)
{

DDRB |= (1 << PB1);  // set PB1(OC1A) as output
OCR1A =399;  // d.c.=10% (Ton=.1ms)
TCCR1A |= (1 << WGM11);  // non inv. - fast PWM (ICR1=TOP) WGM11=1

TCCR1B |= (1 << WGM13) | (1 << WGM12); // no presc. - fast PWM (ICR1=TOP) WGM13:2=1

/* Now we can set ICR1=TOP */
ICR1 = 3999;  // Ts=1ms @ fc=4MHz

TCCR1A |= (1 << COM1A1);

TCCR1B |= (1 << CS10);


  while(1);


}
[/code]

Here it is the screenshot of VMLAB under Debian and how now all works fine:

[URL=http://img529.imageshack.us/i/vmlabat1mega68b.png/][IMG]http://img529.imageshack.us/img529/5910/vmlabat1mega68b.th.png[/IMG][/URL]

Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]






Back to top
 
 
  IP Logged
ThVortex
Global Moderator
*****
Offline



Posts: 160
Austin, TX, USA
Gender: male
Re: ATmega168 Peripheral Models
Reply #14 - 08/19/10 at 18:07:03
 
Great. I'm glad you got it working. Thank you for figuring out the case sensitive file names. I probably renamed the .ini file at some point without even thinking. I'll add a note about it on my website, and I'll change the name in my zip files back to "ATmega" since that is the capitalization used in the datasheets.
Back to top
 
 
WWW   IP Logged
Pages: 1 2 
Send Topic Print