Werbung
Hi leute,
ich setze mit Bascom einen PWM wert, ganz normal.
Das kuriose ist nun, dass bei den werten 256, 512 und 768 immer 256 abgezogen werden. Also 256 ist dann 0, 512 ist 256 und 768 ist 512.Code:Config Timer3 = Pwm , Pwm = 10 , Compare B Pwm = Clear Down , Compare C Pwm = Clear Down , Prescale = 1024 Pwm3b = 255 Waitms 1000 Pwm3b = 512 Print "PWM: " ; Pwm3b Waitms 1000
Alle anderen werte werden richtig eingestellt.
Wie kann das sein und womit hat das zu tun?
Das ganze ist nicht wirklich kritisch, aber es wäre mal interessant zu wissen, woran das liegt.
Vielen dank für eure antworten, grüße,
Fallback
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!
Hmm, also ich hab jetzt einfach nur "Print OC3RB" gemacht und mich um low und high nicht gekümmert. Hab noch deine methode gerade probiert, gleiches ergebnis.
Gibt's daraus jetzt irgendwelche erkenntnisse woran das liegen könnte?
Is das noch irgendjemandem aufgefallen? Is das vielleicht ein bug von Bascom im zusammenhang mit mega2560 und timer3?
Lesezeichen