Hallo,
sorry für den etwas nichtssagenden Titel, aber etwas Zielführenderes ist mir leider nicht eingefallen.
Zu meinem Problem: Das folgende Programm soll die Impulslänge einer Fernsteuerung messen, das tut es auch. Falls kein Impuls kommt, soll eine Fehlermeldung ausgegeben werden; und da liegt der Fehler: Die LED an Port D.1 zeigt durch Blinken auch brav das fehlende Signal an, aber die Ausgabe aufs LC-Display (Zeile 134-142) klappt nicht. Dieser Zweig des Programms wird nicht aufgerufen, obwohl ich wie gesagt dafür keine Ursache finden kann. Erhöhen des Zählers bPulseError per incr sollte nach einiger Zeit doch die per Konstante eingestellte Schwelle ErrorTolerance erreichen.
Alles anzeigen
sorry für den etwas nichtssagenden Titel, aber etwas Zielführenderes ist mir leider nicht eingefallen.
Zu meinem Problem: Das folgende Programm soll die Impulslänge einer Fernsteuerung messen, das tut es auch. Falls kein Impuls kommt, soll eine Fehlermeldung ausgegeben werden; und da liegt der Fehler: Die LED an Port D.1 zeigt durch Blinken auch brav das fehlende Signal an, aber die Ausgabe aufs LC-Display (Zeile 134-142) klappt nicht. Dieser Zweig des Programms wird nicht aufgerufen, obwohl ich wie gesagt dafür keine Ursache finden kann. Erhöhen des Zählers bPulseError per incr sollte nach einiger Zeit doch die per Konstante eingestellte Schwelle ErrorTolerance erreichen.
Quellcode
- '----- Settings ----------------------------------------------------------------
- $regfile = "m16DEF.Dat"
- $crystal = 1000000 'Frequency 1 MHz
- $hwstack = 48
- $swstack = 20
- $framesize = 32
- '----- Settings for Pollin Evaluation Board -----
- ' Port selected as given by addon board to use jumpers instead of cables to ports
- Lcd_db4 alias Porta.4
- Lcd_db5 alias Porta.5
- Lcd_db6 alias Porta.6
- Lcd_db7 alias Porta.7
- Lcd_e alias Portb.0
- Lcd_rs alias Portb.2
- config Portb.1 = output 'R/W of LCD to be connected to GND
- reset Portb.1 'PortB.1 set to GND
- ' 76543210
- Ddrd = &B00000010 'PinD0, 2-7 input, D1 output
- ' 76543210
- Portd = &B11111101 'PullUp PinD0, 2-7 active
- '----- Constants ---------------------------------------------------------------
- const ReadRepeat = 5 'necessary pulse readings before program continues
- const ErrorTolerance = 10 'number of errors before showing error condition
- '----- Variables ---------------------------------------------------------------
- dim wPulse as word 'stores current reading of RC signal
- dim wPulseMin as word : dim wPulseMax as word
- dim wPulseMeas as word : dim wPulseWidth as word
- dim bCount as byte 'loop counter
- dim bPulseError as byte 'error counter
- dim bPulseRead as byte 'indicate pulse readings
- FeedBack alias PortD.1 'feedback about signal errors
- SignalRead alias bPulseRead.0 'handles signal readings
- RC_In alias pind.2 'INT0 to read RC signal
- '----- Initialization ----------------------------------------------------------
- config lcd = 16x2 'LCD used in 4-bit-mode
- config Lcdpin = Pin , Db4 = Lcd_db4 , Db5 = Lcd_db5 , Db6 = Lcd_db6 , Db7 = Lcd_db7 , E = Lcd_e , Rs = Lcd_rs
- initlcd
- cls
- config timer0 = timer , prescale = 8
- config int0 = change
- on int0 GetPulse
- config timer1 = timer, prescale = 8 'timer overflow each 0,5 s
- on timer1 MisPulse
- wPulse = 0 : wPulseMeas = 0
- wPulseMax = 0 : wPulseMin = 65535 : wPulseWidth = 0
- Timer0 = 0 : timer1 = 0
- bPulseError = 0
- '===== Program =================================================================
- enable Timer0
- enable int0
- enable interrupts
- '----- Part 1 - Measures minimum pulse length ----------------------------------
- upperline : lcd "RC SigMeas 8bit"
- lowerline : lcd "Mes. Low "
- for bCount = 9 to 0 step -1
- locate 2 , 10 : lcd bCount
- waitms 300
- next bCount
- wPulseMin = wPulseMeas
- lowerline : lcd "MinPulse " ; wPulseMin ; spc(5)
- wait 2
- '----- Part 2 - Measures maximum pulse length ----------------------------------
- lowerline : locate 2 , 1 : lcd "Mes.High " ; spc(5)
- for bCount = 9 to 0 Step -1
- locate 2 , 10 : lcd bCount
- Waitms 300
- Next bCount
- wPulseMax = wPulseMeas
- lowerline : Lcd "MaxPulse " ; wPulseMax ; spc(5)
- Wait 2
- '----- Part 3 - Calculates pulse width and shows result at LCD -----------------
- if wPulseMin > wPulseMax then
- wPulseWidth = wPulseMin - wPulseMax
- else
- wPulseWidth = wPulseMax - wPulseMin
- end if
- lowerline : lcd "Pulse width " ; wPulseWidth
- wait 3
- '----- Part 4 - Summarizes results ---------------------------------------------
- upperline : home
- lcd "L" : lcd wPulseMin ; " H" ; wPulseMax
- lcd " W" ; wPulseWidth ; spc(8)
- '----- Part 5 - Main: Measures current pulse length and shows results at LCD ---
- lowerline : locate 2 , 1 : lcd "P-Length" ; spc(8)
- enable timer1 : start timer1
- Do
- SignalRead = 0 : wPulse = 0 : bCount = 0 'reset variables & counter
- do
- if SignalRead = 1 then
- wPulse = wPulse + wPulseMeas 'sum of pulse readings
- SignalRead = 0
- incr bCount
- end if
- Loop until bCount = ReadRepeat
- wPulse = wPulse / ReadRepeat 'average of pulse readings
- locate 2 , 10 'shows current pulse length
- lcd wPulse ; spc(8)
- If bPulseError > ErrorTolerance Then
- Stop Timer1
- locate 2, 10 : lcd "Error"
- waitms 500
- timer1 = 0
- start timer1
- bPulseError = 0 'reset counter
- Feedback = 0
- end if
- Loop
- End 'end program
- '===== End of program ==========================================================
- '----- Interrupts --------------------------------------------------------------
- GetPulse:
- if RC_In = 1 then 'start Timer0 if positive signal on input
- start Timer0
- Else 'stop Timer0 if no positive signal
- stop Timer0
- wPulseMeas = timer0
- Timer0 = 0
- SignalRead = 1
- Timer1 = 0
- end if
- return
- MisPulse:
- incr bPulseError
- toggle Feedback
- timer1 = 0
- return
Beste Grüße
Jürgen
Jürgen