PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : ATtiny2313 mit PWM mode 14 klappt nicht in der Simulation



newbee08
23.09.2008, 10:09
AVR Studio 4.13.528
GUI Version 4, 13, 0, 528
AVR Simulator 1, 0, 2, 0
ATTINY2313 208

Möchte eine PWM in Mode 14 erzeugen und als Top IRC1=20000 nehmen.
Obwohl nun nach Datenblatt OCR1A ein 16bit Register ist, kann der Wert
0x05DC nicht geladen werden - es wir im Simulator 0x1DC draus. Was läuft falsch - der Simulator, das Datenblatt oder ich ?( :Haue

Ein newbee

#include "avr/io.h"
#include "avr/interrupt.h"

// Timer 1 overflow interrupt service routine
ISR (TIMER1_OVF_vect)
{
PORTB |= 0x08;
}

int main(void)
{

PORTB=0x08;
DDRB=0x08;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 31.250 kHz
// Mode: Fast PWM top=ICR1
// OC1A output: Changed Clear on OCR1A Set on Top; (Toggle)
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x82;
TCCR1B=0x1A;
ICR1=0x4E20;
TCNT1=0x00;
OCR1A=0x05DC;
OCR1B=0x03FF; // nicht benutzt

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x80;

// Global enable interrupts
sei();

while (1)
{
// Place your code here


};
}

fhs
23.09.2008, 10:51
Hi,

du hast ein (bekanntes) Problem im Simulator gefunden. Dazu steht im Helpfile des AVRStudio v 4.14: Shadow register support is missing in AVR Studio. As a consequence when operating PWM in fast- and phase correct mode, the OCR register should not be updated until TCNT is at TOP. Das steht auch hier (http://support.atmel.no/knowledgebase/avrstudiohelp/mergedProjects/AVRStudio4/Html/Knownissues.htm) (unter "Simulator").

Du kannst das Problem umgehen, indem Du die Compare-Regs initialisiert, bevor Du den Timer startest (das ist sowieso immer eine gute Idee, wenn es denn machbar ist!), also so:
<pre>OCR1A=0x05DC;
OCR1B=0x03FF; // nicht benutzt
TCCR1A=0x82;
TCCR1B=0x1A;
// usw. </pre>
Den Rest Deiner Initialisierung habe ich mir übrigens nicht angesehen.

Gruß

Fred