 


           
|
 |
Merijn Wijnen
RCL Neu-User


Dabei seit: 02.04.2002
Herkunft: Eindhoven, Niederlande
 |
|
|
09.04.2006 22:26 |
|
Gwydion 
RCL Power-User

Dabei seit: 18.09.2005
 |
|
|
10.04.2006 00:31 |
|
|
|
Hier die program Code, sie ist (glaube ich) ausreichend documentiert auf Englisch. Vielleicht kan jemand etwas damit.
Ich habe keine Probleme mehr festgestelt, gebe aber keine Garantie.
Die interrupt routine koennte noch etwas Kuerzer auf kosten der Uebersichtlichkeit des Programs.
Glitch detection ist noch nicht drin. Am einfachtsten zu implementieren ist das Detektieren ob ein Puls eine vernunftige zeit dauert (1-2 ms fuer Robbe / Graupner, 1.05-2.15 fuer MPX).
Gruesse,
Merijn
| code: |
'Testsoftware multichannel RC decoder'
'Merijn Wijnen, 12-4-2006'
'Processor: ATMega 8-16
'Bascom-Version: 1.11.8.1
'
'Hardware:
'Undecoded receiver signal at D.2 (INT0)
'Wintek 2 processor 4 line serial LCD
'LED at C.0
'LED at C.1
'*******************************************************
'Program description:
'The program is written for 8 MHz system clock
'Calibration us used: before running the program, look at the value of calibration byte 3
' (from the "lock and fusebits" tab) and write it into the OSCCAL register on line 124
'
'The receiver pulsetrain consists of 9 consecutive positive chanel pulses, plus one long synchronisation pulse
'The time between two rising or falling pulse flanges is equal to the high time of the pulse on the servo line
'So the time to be measured is the time between two rising or falling flanges
'Using 16 bit timer1, the time of a pulse is measured using a falling flange interrupt and reading and resetting timer1
'The sycronasation pulse is used to determen the number of the channels:
'If a pulse is detectet longer than 3000 ms it must be the sync pulse, so next pulse will be channel 1.
'The signal values including the sync pulse are stored in an intermediate array (channel())
'Fail safe is done using an overflow interrupt on timer 1.
'If timer 1 overflows (after 65 ms), the signal_up_flag is set to signal down, and the signal_valid flag to invalid.
'In this case the output values Ch_time() are either not updated or set to failsafe settings,
'depending on the value of the fail_safe_mode bit
'after startup the fauilsafe values are used for the output array ch_time until it is sure that valid data is present
'Data is valid if two consequitive sync pulses have been measured.
'
'******************************************************
'======================================================
'System settings
'======================================================
'Definition for Mega 8
$regfile "m8def.dat"
'System frequency (8Mhz)
$crystal = 8000000
' LCD-libraries for 2-processor-isplay
$lib "lcd4e2.lbx"
'======================================================
'Configurations
'======================================================
'I/O-Ports
Config Portc = Output
Config Portd = Input
'Size of display
Config Lcd = 20 * 4 'it is 4x27 really, but the compiler doesn't understand
'Interrup 0
Config Int0 = Falling 'timing of pulses on negative flank
'Configuration of timer 1 (16 bit)
Config Timer1 = Timer , Prescale = 8
'======================================================
'Declarations
'======================================================
Dim ___lcde As Byte 'for switching between upper and lower LCD half
Dim N_sync As Byte
Dim Rc_value As Word
Dim Channel(10) As Word '9 channels plus the synchonisation pulse
Dim N_ch As Word
Dim Ch_time(9) As Word
Dim Failsafe_value(9) As Word 'These will be used when no signal is available
Dim I As Integer 'Running parameter for loops
Dim Failsafemode As Bit
Dim Signal_up_flag As Bit
Dim Signal_valid_flag As Bit '
'======================================================
'Initialisations
'======================================================
'Interrupt-Service-Routines
On Timer1 Signal_down 'overflow of timer occurs when the signal is down
On Int0 Read_signal 'On int0 timing of the signal pulses
'Timer-release
Enable Timer1
'Release of interrupts
Enable Int0
Enable Interrupts
'Initialise ports
Portc = &B00000000 'Note: my hardware has non-inverted LED ports: 1 = on, 0 = off
'Initialise variables
Signal_up_flag = 1 'Signal available
Signal_valid_flag = 0 'Signal not valid
N_ch = 1
N_sync = 0 'Start at channel 1
'No sybcronisation pulse seen yet
'Failsafe settings
Failsafemode = 0 '0 for "keep old signals", 1 for the failsafe values below
Failsafe_value(1) = 1600 'Set failsafe value of channel 1 (roll)
Failsafe_value(2) = 1600 'Set failsafe value of channel 2 (pitch)
Failsafe_value(3) = 1600 'Set failsafe value of channel 3 (yaw)
Failsafe_value(4) = 1050 'Set failsafe value of channel 4 (power)
Failsafe_value(5) = 1600
Failsafe_value(6) = 1600
Failsafe_value(7) = 1600
Failsafe_value(8) = 1600
Failsafe_value(9) = 1600
'Initialise timer channel values
For I = 1 To 9
Ch_time(i) = Failsafe_value(i)
Next
'Calibration of the internal oscillator.
'Write here the hex value of calibration byte 3 from the locks and fuses tab
Osccal = &HAF 'Loading the calibration byte in the OSCCAL register
'======================================================
'Writing LCD headers
'======================================================
___lcde = 0 'Switch to upper two lines
Cls 'Clear lines
'First line
Locate 1 , 1
Lcd "**multichannel RC decoder**"
Cursor Off
'Switch to lower two lines
___lcde = 1
Cls 'Clear lines
Cursor Off
'======================================================
'Main program
'======================================================
Do
'Calculate timing values in micro sec, only if the signal is up (simple fail safe implementation)
'Otherwise leave old values or use faisafe values
'The ch_time() array would be used for further processing
'The channel() array is only used for measurement and may contain invalid data
If Signal_valid_flag = 1 Then
For I = 1 To 9
Ch_time(i) = Channel(i) / 1
Next
Else
If Failsafemode = 1 Then
For I = 1 To 9
Ch_time(i) = Failsafe_value(i)
Next
End If
End If
'Writing timing values to LCD display
___lcde = 0
Locate 2 , 1
Lcd Ch_time(1) ; " ch1"
Locate 2 , 11
Lcd Ch_time(2) ; " ch2"
Locate 2 , 20
Lcd Ch_time(3) ; " ch3"
___lcde = 1
Locate 1 , 1
Lcd Ch_time(4) ; " ch4"
Locate 1 , 11
Lcd Ch_time(5) ; " ch5"
Locate 1 , 20
Lcd Ch_time(6) ; " ch6"
Locate 2 , 1
Lcd Ch_time(7) ; " ch7"
Locate 2 , 11
Lcd Ch_time(8) ; " ch8"
Locate 2 , 20
Lcd Ch_time(9) ; " ch9"
Portc.0 = Signal_valid_flag 'Showing the signal valid flag on port C0
Portc.1 = Signal_up_flag 'Showing the signal up flag on port C1
'waitstate to get readable LCD values
Waitms 300
Loop
End
'******************************************************
'Interrupt Service Routines
'******************************************************
Read_signal:
Rc_value = Timer1 'First thing: store the timer value in an intermediate variable.
Timer1 = 0 'Then reset the timer
If Rc_value > 3000 Then 'If the puls is to long it is the synchronisation pulse,
N_ch = 10 'so set channel number to number of synchonisation pulse
If N_sync < 2 Then Incr N_sync 'The sync pulse counter is increased until it is 2
If N_sync = 2 Then Signal_valid_flag = 1 'If it is the second consequitive sync puls, then the signal is declared valid
End If
Channel(n_ch) = Rc_value 'Load the measured timer value into the array of measurement data
Incr N_ch 'next channel
If N_ch = 11 Then N_ch = 1 'Limit the number of channels to 10
Signal_up_flag = 1 'set the signal up flag
Return
Signal_down: 'if no signal is detected for 65 ms
Signal_up_flag = 0 'reset signal_up_flag
Signal_valid_flag = 0 'reset signal valid flag
N_sync = 0 'reset number of syncpulses passed
Return
|
|
|
|
12.04.2006 21:42 |
|
Helge 
RCL Neu-User

Dabei seit: 13.05.2007
 |
|
|
20.06.2007 09:22 |
|
|
|
 |
|
|
|
|