Alright, now that I'm home, I'll post the code. Its bare bones Timer1 code:
#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:
; ************************************************************
; 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.