Hallo Programmierfreunde,
ich habe eine Frage zu der PWM-Signalerzeugung des Raspberry Pi Pico mittels MMBASIC.
---------------------------------------------------------------------------------------------------------------------------------
Vorgeschichte (kann man überspringen wenn einen das nicht interessiert !)
Ziel ist es einen Verbrennungsluftmotor eine Gasheizung, entsprechend dem Spannungswert der von der Brennerelektrode geliefert wird, zu steuern.Anfangs habe ich versucht das mit den Standardbefehlen zu realisieren habe dann aber festgestellt das die Schrittweite 0-100 Prozent zu grob ist. Der benötigte Aussteuergrad (experimentell ermittelt) bewegt sich zwischen ca. 18 und 35% was dann nur noch 17 Schritte Spielraum für den Aussteuergrad ergibt. Die Einstellschritte sind dann zu grob für das Optimale Luft/Gas Gemisch wie ich dann feststellen musste. Es stellt sich kein stabiler Brennerzustand ein. Die Motordrehzahl pendelte dann ständig auf und ab.
Ich brauche aber noch ein zweites PWM-Signal für den Raumluftmotor und da habe ich das Problem.
---------------------------------------------------------------------------------------------------------------------------------
Programm und Problem:
Ich habe ein kleines Testprogramm (MMBASIC_Pi_Pico_PWM_Test_05.7z) geschrieben worin ich die Controlregister des RP2040 benutze um die entsprechenden Rahmenparameter mittels dem POKE Befehl von MMBASIC direkt einzustellen. Damit lässt sich das Problem gut nachvollziehen.
'------------------------------------------------------------------
'load variables with initial values
'------------------------------------------------------------------
SetPin gp0,pwm0a
SetPin gp1,pwm0b
PWM 0,100000,pwm_0a,pwm_0b
'------------------------------------------------------------------
Poke word &h40050010,6500 'Set CH0_Top, ca. 20,4kHz
Poke word &h40050000,1 'CH0_CSR Bit 0 -> EN = 1
'Enable PWM Channel CH0
Poke word &h40050024,6500 'Set CH1_Top, ca. 20,4kHz
Poke word &h40050014,1 'CH1_CSR Bit 0 -> EN = 1
'Enable PWM Channel CH1
Poke word &h40014004,4 'Set GPIO0_CTRL = 4 FUNCSEL PWM
Poke word &h4001400c,4 'Set GPIO1_CTRL = 4 FUNCSEL PWM
Das Problem ist nun das wenn ich in das PWM-Register CH1_CC (Channel 1 Counter Compare Value = adress &h40050020) einen neuen Wert schreibe ändert sich nichts am Austeurgrad von CH1 und beide PWM-Signale bleiben aber aktiv.
Ändert man die FUNCSEL (Function Select) Einstellungen kann man beide Signale entsprechen aktivieren oder deaktivieren.
Schreibe ich einen neuen Wert in das PWM-Register CH0_CC (Channel 0 Counter Compare Value = adress &h4005000C) ändert sich entsprechend des veränderten Einstellwertes der Austeuergrad von CH0 aber gleichzeitig verschwindet das PWM-Signal von CH1.
Warum verschwindet das PWM-Signal von dem zweiten Kanal wenn ich einen neuen Wert für den ersten Kanal in das CH0_CC schreibe?
Was ist da oder was mache ich falsch?
Gruss
Snygghus
###################################################################################################################################
Testprogramm Tasten:
PWM0A
1 Austeuergrad vergrossern (CH0_CC + 1)
q Austeuergrad verkleinern (CH0_CC - 1)
a Funktionseinstellung GPIO Pin vergroessern (GPIO0_CTRL + 1, FUNCSEL)
a Funktionseinstellung GPIO Pin verkleinern (GPIO0_CTRL - 1), FUNCSEL)
PWM0B
2 Austeuergrad vergrossern (CH1_CC + 1)
w Austeuergrad verkleinern (CH1_CC - 1)
s Funktionseinstellung GPIO Pin vergroessern (GPIO1_CTRL + 1, FUNCSEL)
x Funktionseinstellung GPIO Pin verkleinern (GPIO1_CTRL - 1), FUNCSEL)
OPTION EXPLICIT
' OPTION DEFAULT NONE
'------------------------------------------------------------------
'declare variables
'------------------------------------------------------------------
dim as integer pwm_0a = 20
dim as integer pwm_0b = 25
dim as integer PWM_Frequency
dim as integer CH0_CC
dim as integer CH1_CC
dim as integer GPIO0_CTRL
dim as integer GPIO1_CTRL
dim as string InKey
'------------------------------------------------------------------
'load variables with initial values
'------------------------------------------------------------------
SetPin gp0,pwm0a
SetPin gp1,pwm0b
PWM 0,100000,pwm_0a,pwm_0b
'------------------------------------------------------------------
Poke word &h40050010,6500 'Set CH0_Top, ca. 20,4kHz
Poke word &h40050000,1 'CH0_CSR Bit 0 -> EN = 1
'Enable PWM Channel CH0
Poke word &h40050024,6500 'Set CH1_Top
Poke word &h40050014,1 'CH1_CSR Bit 0 -> EN = 1
'Enable PWM Channel CH1
Poke word &h40014004,4 'Set GPIO0_CTRL = 4
Poke word &h4001400c,4 'Set GPIO1_CTRL = 4
'------------------------------------------------------------------
do
InKey = inkey$
if InKey <> "" then
'------------------------------------------------------------------
'CH0
'------------------------------------------------------------------
if InKey = "1" then
CH0_CC = CH0_CC + 1
if CH0_CC > 2000 then CH0_CC = 2000
print "CH0_CC = ";CH0_CC
Poke word &h4005000c,CH0_CC 'Set CH0_CC
end if
if InKey = "q" then
CH0_CC = CH0_CC - 1
if CH0_CC < 0 then CH0_CC = 0
print "CH0_CC = ";CH0_CC
Poke word &h4005000c,CH0_CC 'Set CH0_CC
end if
'-----------------------
if InKey = "a" then
GPIO0_CTRL = GPIO0_CTRL + 1
'if CH1_CC > 2000 then CH1_CC = 2000
print "GPIO0_CTRL = ";GPIO0_CTRL
Poke word &h40014004,GPIO0_CTRL 'Set GPIO0_CTRL
end if
if InKey = "z" then
GPIO0_CTRL = GPIO0_CTRL - 1
'if CH1_CC > 2000 then CH1_CC = 2000
print "GPIO0_CTRL = ";GPIO0_CTRL
Poke word &h40014004,GPIO0_CTRL 'Set GPIO0_CTRL
end if
'------------------------------------------------------------------
'CH1
'------------------------------------------------------------------
if InKey = "2" then
CH1_CC = CH1_CC + 1
if CH1_CC > 2000 then CH1_CC = 2000
print "CH1_CC = ";CH1_CC
Poke word &h40050020,CH1_CC 'Set CH1_CC
end if
if InKey = "w" then
CH1_CC = CH1_CC - 1
if CH1_CC < 0 then CH1_CC = 0
print "CH1_CC = ";CH1_CC
Poke word &h40050020,CH1_CC 'Set CH1_CC
end if
'-----------------------
if InKey = "s" then
GPIO1_CTRL = GPIO1_CTRL + 1
'if CH1_CC > 2000 then CH1_CC = 2000
print "GPIO1_CTRL = ";GPIO1_CTRL
Poke word &h4001400c,GPIO1_CTRL 'Set GPIO1_CTRL
end if
if InKey = "x" then
GPIO1_CTRL = GPIO1_CTRL - 1
'if CH1_CC > 2000 then CH1_CC = 2000
print "GPIO1_CTRL = ";GPIO1_CTRL
Poke word &h4001400c,GPIO1_CTRL 'Set GPIO1_CTRL
end if
'-----------------------
end if
'------------------------------------------------------------------
pause 50
loop
Display More