Werbung
Sollte das Print nicht in der Schleife sein? Wie sind Pwm3b und I definiert? Das erinnert mich irgendwie an solche Probleme:
Disable Interrupts
Pwm3b = I
Enable Interrupts
Wird I oder Pwm3b in einer ISR verwendet/geändert?
Wird I richtig ausgegeben?
Print "PWM: " ; Pwm3b ; " I: " ; I
[Edit]
Ach, das war wohl nichts, Pwm3b ist ja das Ocr3b-Register, oder?
Geändert von radbruch (31.08.2011 um 13:33 Uhr)
![]()
Atmel’s products are not intended, authorized, or warranted for use
as components in applications intended to support or sustain life!
Hups, ja, sorry, das Print steht natürlich in der schleife.
Aber es geht wie gesagt um die ausgabe .. wieso wird Pwm3b auf einmal 0?
Ok, dann hier mal ein komplettes programm:
[edit]Code:$regfile = "m2560def.dat" $crystal = 16000000 $hwstack = 60 $swstack = 60 $framesize = 40 $baud = 9600 Dim I As Integer Config Timer3 = Pwm , Pwm = 10 , Compare B Pwm = Clear Down , Compare C Pwm = Clear Down , Prescale = 1024 Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Do For I = 0 To 1023 Pwm3b = I Print "I: " ; I Print "pwm3b :" ; Pwm3b Next I Waitms 1000 Loop
I wird korrekt ausgegeben, ja.
Und Pwm3b ist meines Wissens nach Ocr3b und hat dann übrigens den gleichen wert wie Pwm3b, gerade mal kurz getestet.
Geändert von Fallback (31.08.2011 um 13:54 Uhr)
Haste das mal ausprobiert:
Ich vermute, es klemmt beim Schreiben ins Pwm3b-Register. Vielleicht versuchst du es mal byteweise:Code:Disable Timer3 Pwm3b = I Enable Timer3 Print "I: " ; I; Print " pwm3b: " ; Pwm3b
Ocr3bh = I \ 256
Ocr3bl = I Mod 256
Erst High- dann Lowbyte
![]()
Atmel’s products are not intended, authorized, or warranted for use
as components in applications intended to support or sustain life!
Interessant, also bei Enable/Disable Timer3 tut sich nichts anderes.
Aber ich hab mal die Ocr3b high/low bytes einzeln gesetzt, wie du vorgeschlagen hast und dabei kommt dann sowas raus:
Wieso fängt Oc3b jetzt bei 768 an?Code:I: 0 Ocr3b: 768 ... I: 255 Ocr3b: 1023 I: 256 Ocr3b: 768
Obwohl, hmm, das hat wahrscheinlich was mit nem falschen setzen der high/low bytes zu tun .. oder?
Echt lustig. Im Datenblatt des Mega16 steht zum 16-Bit Zugriff auf das OCRXY-Register:
Das Auslesen würde dann etwa so aussehen:To do a 16-bit write, the High byte must be written before the Low byte. For a 16-bit read, the
Low byte must be read before the High byte.
Code:Dim Temp As Integer , X As Integer X = Ocr3bl 'lowbyte Temp = Ocr3bh * 256 'highbyte X = X + Temp
Geändert von radbruch (31.08.2011 um 15:22 Uhr)
![]()
Atmel’s products are not intended, authorized, or warranted for use
as components in applications intended to support or sustain life!
Lesezeichen