Author Topic: VMLab issues...or is it me?  (Read 3846 times)

0 Members and 1 Guest are viewing this topic.

Offline krichTopic starter

  • Robot Overlord
  • ****
  • Posts: 165
  • Helpful? 0
VMLab issues...or is it me?
« on: May 19, 2008, 11:12:35 AM »
Well, I happened upon this really cool software called VMLab.  I guess it's been around for a while, so its really nothing new, but it's new to me.   ;D

Anyway, I decided to learn timers on atMega168-20PU over the weekend in preparation for the arrival of my new ultrasonic transducers.  Long story short, I don't think the VMLab simulator properly emulates the timers on a atMega168 because I was not getting what I was expecting.  I'm 99% certain I've set up the software correctly.  Right off I could tell something was wrong because the timer registers in the simulator don't match up with the datasheet.  I can load the code onto a "real" mega16 and it seems to work fine.  It's free software, so I can't really complain.  I'm just really bummed because it had huge potential for me.

So, my question for those who may be more familiar with VMLab is...

Is it still being developed/updated?  The website seems to be reasonably current, but the forums have been under maintenance since I became aware of VMLab.  Is there something obvious that I'm doing wrong that would clear all this up?  I've checked and double checked that the MICRO definition is for a atMega168.  Can't imagine I need to set anything else to make the timer registers match the datasheet.

Anyway, thanks in advance for any guidance you guys might have.

Regards,

Ken.



Offline Steel_monkey

  • Full Member
  • ***
  • Posts: 85
  • Helpful? 0
Re: VMLab issues...or is it me?
« Reply #1 on: May 19, 2008, 03:01:40 PM »
Well, it is not very easy to heal at great distance, but I will try  ;D (add achematic, code project if possible, it will really help those who want to help you). Try to separate your task into small subtastks and simulate them separately. Also check clock setup- perhaps that is an issue. I also found a trouble with VMlab timers, but I think it is just my stupidness.   

Offline krichTopic starter

  • Robot Overlord
  • ****
  • Posts: 165
  • Helpful? 0
Re: VMLab issues...or is it me?
« Reply #2 on: May 19, 2008, 05:32:07 PM »
Alright, now that I'm home, I'll post the code.  Its bare bones Timer1 code:

Code: [Select]
#define F_CPU 8000000
#include <avr\io.h>

int main(void) {

    DDRB |= _BV(PORTB1)|_BV(PORTB2);
PORTB |= _BV(PORTB1) | _BV(PORTB2);

// Waveform setting
TCCR1B |= _BV(WGM13);
TCCR1B |= _BV(WGM12);
TCCR1A |= _BV(WGM11);
//TCCR1A |= _BV(WGM10);

// Compare Action
TCCR1A |= _BV(COM1A1);
TCCR1A |= _BV(COM1A0);
TCCR1B |= _BV(COM1B1);
TCCR1B |= _BV(COM1B0);

// Prescale setting
//TCCR1B |= _BV(CS12);
//TCCR1B |= _BV(CS11);
TCCR1B |= _BV(CS10);

    ICR1=200;
//OCR1A=100;
//OCR1B=100;

// Main loop
for (;;) {}

}

and here's the project file:

Code: [Select]
; ************************************************************
; PROJECT:
; AUTHOR:
; ************************************************************

; Micro + software running
; ------------------------------------------------------------
.MICRO "ATmega168" "CKDIV8=1"
.TOOLCHAIN "GCC"
.GCCPATH   "C:\WinAVR-20080512"
.GCCMAKE   AUTO
.TARGET    "project.hex"
.SOURCE    "project.c"

.TRACE              ; Activate micro trace

; Following lines are optional; if not included
; exactly these values are taken by default
; ------------------------------------------------------------
.POWER VDD=5 VSS=0  ; Power nodes
.CLOCK 8meg         ; Micro clock
.STORE 250m         ; Trace (micro+signals) storage time

; Micro nodes: RESET, AREF, PB0-PB7, PC0-PC6, PD0-PD7, ACO, TIM1OVF, ADC6, ADC7
; Define here the hardware around the micro
; ------------------------------------------------------------
 .PLOT V(PB1)
 .PLOT V(PB2)

R1  PB1 D1_node 380
D1  VDD D1_node
R2  PB2 D2_node 380
D2  VDD D2_node

This gets me a 40kHz frequency in Fast PWM mode on a real live mega168, but a flat high line on the VMLab scope.

I've attached a screen shot of the simulator in progress.  Notice the flat lines on PB1 and PB2?  Also, I really wanted to use Timer0 for this, but take a look at Timer0's registers on the screen.  Only a TCCRn register, when the datasheet has TCCRnA and TCCRnB for Timer0.  Strange.
« Last Edit: May 19, 2008, 05:33:30 PM by krich »

Offline Steel_monkey

  • Full Member
  • ***
  • Posts: 85
  • Helpful? 0
Re: VMLab issues...or is it me?
« Reply #3 on: May 20, 2008, 06:05:57 AM »
I have tried this - and it looks like a bug. If MAX register is changed to OCR1 ( remove comment from //TCCR1A |= _BV(WGM10); ) and OCR1 is set to 200, everything works fine. Perhaps there are hidden features with fast PWM, but I am not sure.

 


Get Your Ad Here

data_list