Hi,
[code:1:7f1fb66ba9]$regfile = "xm128a1def.dat"
$crystal = 32000000 '32MHz
$hwstack = 128
$swstack = 128
$framesize = 128
$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014[/code:1:7f1fb66ba9]
In most of my app I do the ISR on precise time slice, like this: (there is also some settings to handle COM5 & 7)
[code:1:7f1fb66ba9]'********************** TIMER CONFIG ****************************************
Config Tcd0 = Normal , Prescale = 64
Tcd0_per = 2550 'perioda 20ms; 2550*256=652800 ciklov
'*********************************************************************************
'***************** UART7 portF interrupt **********************************************************
On Usartf0_rxc Rx_int7
Enable Usartf0_rxc , Lo
'**************************************************************************************************
'***************** UART5 portE interrupt **********************************************************
On Usarte0_rxc Rx_int5
Enable Usarte0_rxc , Lo
'**************************************************************************************************
'***** ENABLE TIMER INT.***************************************************************************
On Tcd0_cca Compared0_int
Enable Tcd0_cca , Lo
Enable Interrupts
'**************************************************************************************************
[/code:1:7f1fb66ba9]
ISR:
[code:1:7f1fb66ba9]'************************* TIME SLICE 0 ******************************
Compared0_int:
Tcd0_intflags.0 = 1
'some simple I/O handling:
' TX tipka zadaj ******************************
If Faza = 0 Then
If Tpx = 1 Then
Incr Tpx_timer1
If Tpx_timer1 > 200 Then
'Faza = 10
Faza = 2
Tpx_timer1 = 0
Beep = 7
End If
Else
Tpx_timer1 = 0
End If
End If
Call Serial_check7
Call Serial_check5
'*****************************************************************
'***** TEMP measurement and output handling **********
'*************************************************************
'stevec za preverjanje temperature - vklop/izklop kompresorja
If Enable_komptimer1 = 1 Then
If Komp_timer1 > 0 Then
Decr Komp_timer1
End If
End If
'*************************************************************
Incr Meritev_interval
If Meritev_interval > 60 Then
'Meritev_interval = 0
Toggle Led1
Incr Temp_index
Ww(temp_index) = Getadc(adca , 0 , 8)
If Temp_index = 10 Then
W = 0
For Temp_index = 1 To 10
W = W + Ww(temp_index)
Next
Temp_index = 0
Meritev_interval = 0
T_result = W
T_result = T_result / 10
T_result = T_result * K
T_y = T_result - N
'y je tu prava vrednost uporabi to za termostat/regulacijo
'Print #5 , Y
Temp_senzor = T_y
If Cooling = 0 Then
Temp_result = Temp_set + Temp_histereza
If Temp_senzor > Temp_result Then
If Komp_timer1 = 0 Then
Set Kompresor
Set Cooling
End If
End If
Else
Temp_result = Temp_set - Temp_histereza
If Temp_senzor < Temp_result Then
Reset Kompresor
Reset Cooling
Komp_timer1 = 18000
End If
End If
End If
End If
'********************************************************
Return
'****************** E N D TIME SLICE 0 *******************[/code:1:7f1fb66ba9]
In the main loop I only call some operations, including read/write from ISP FRAM, print to COM2 and COM5, read/write from internal EEPROM etc...
Sometimes I'm confused about usage of Gosub's or Sub's (Call)....
If any further hint... Thanks!
BR
Andrej
↧