Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ATXMega 32 E5 - XCL Event System Counter/Timer Overflow/Unde

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
andrge

Bascom Member



Joined: 26 Oct 2011
Posts: 7
Location: Kaufbeuren

germany.gif
PostPosted: Wed Aug 18, 2021 1:15 pm    Post subject: ATXMega 32 E5 - XCL Event System Counter/Timer Overflow/Unde Reply with quote

Hello,

i have a little issue on getting my over/underflow handler working.

The goal of this project is to count the numbers of falling edges on the pin C4 and C5 on a somewhat close hardware-level using XCL.
From what i've found on research is that there are not that many examples out there for that topic especially not for the MCU i am using.

I've started on a small example from MCS for the xm128a1 with the relevant lines being

Code:

Config Event_system = Dummy , Mux0 = Porte.5 , Digflt0 = 8 'Eventchannel 0 = PINE.5, enable digital filtering Config Tcc0 = Normal , prescale = E0 , Event_source = E0 , Event_action = capture
On Tcc0_ovf Timerd0_int
Enable Tcc0_ovf , lo 'Enable overflow interrupt in LOW Priority
Tcc0_per = 5 'Interrupt when Count > 5

Do
'...
Loop

Timerd0_int:
Return
 


which turned out to this

Code:


$regfile = "xm32E5def.dat"

$crystal = 32000000
$hwstack = 65
$swstack = 65
$framesize = 65


'baud 19200
$programmer = 16                                                                                    'USBprog Programmer/ AVR ISP mkII (Atmel)

'(
... clock correction ...
')

'UARTD0, PIN 32, 33
'-----------------------------------------
Config Com1 = 19200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "com1:" For Binary As #1


'Open UARTS
Enable Interrupts

'Startausgabe
'-----------------------------------------
Print #1 , "-------------------------------------"
Print #1 , "              Welcome"
Print #1 , "-------------------------------------"


'Variablen
'------------------------------------------
Dim CounterSecondByte as Byte
Dim CounterTotal As Word

Config PortC.4 = Input
Config Xpin = PortC.4 , Outpull = Pullup , Sense = Falling                                          'enable Pullup and reaction on falling edge
Config Event_system = Dummy , Mux0 = PortC.4 , Digflt0 = 8                                          'Eventchannel 0 =  PINE.5, enable digital filtering

Config Tcc4 = Normal , Prescale = E0 , Event_source = E0 , EVENT_ACTION = RESTART , RESOLUTION = Byte       ' Normal = no waveform generation, Event Source = Event Channel 0

' set the direction to count up
TCC4_CTRLGSET.0 = 0

On Tcc4_ovf Timerc4_int
Enable Tcc4_ovf , Lo

' Interrupt @ 256 -> 0xFF
Tcc4_per = 255



'################MAINLOOP#######################################################
Do
    ' Interval
    Waitms 500

    ' CounterTotal = (CounterSecondByte << 8) | TCC4_CNT
    CounterTotal = CounterSecondByte
    Shift CounterTotal , Left , 8
    CounterTotal = CounterTotal Or TCC4_CNT

    ' Debug Ausgabe
    Print #1 , "TCC4_CNT = " ; CounterSecondByte ; " | " ; TCC4_CNT ; " = " ; CounterTotal ; " EXT " ; High(TCC4_CNT)
Loop
'################MAINLOOP#######################################################


Timerc4_int:
    ' increment high
    Incr CounterSecondByte
Return

 


However i am experiencing a strange issue. Once the over/underflow happened and the handler is being called it won't stop to interrupt and blocks the main loop.

Code:

TCC4_CTRLA 00001000
TCC4_CTRLB 01000000
TCC4_CTRLC 00000000
TCC4_CTRLD 10101000
TCC4_CTRLE 00000000
TCC4_CTRLF 00000000
INTCTRL 00000000 | 00000000
TCC4_CTRLGCLR 00000000
TCC4_CTRLGSET 00000000
TCC4_CTRLHCLR 00000000
TCC4_CTRLHSET 00000000
TCC4_INTFLAGS 00000000
TCC4_TEMP 00000000
 


I have tried to switch some promising bits in various registers attached to the timer but they weren't noticabely improving the situation.

(BASCOM-AVR version : 2.0.8.3 , Latest : 2.0.8.4 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1985

blank.gif
PostPosted: Wed Aug 18, 2021 8:05 pm    Post subject: Re: ATXMega 32 E5 - XCL Event System Counter/Timer Overflow/ Reply with quote

andrge wrote:
Once the over/underflow happened and the handler is being called it won't stop to interrupt and blocks the main loop.

The XMegas do not clear interrupt flags by executing the interrupt vector, instead they want flags cleared by user code, i.e in this case writing a 1 into INTFLAGS.OVFIF.

https://www.microchip.com/content/dam/mchp/documents/OTH/ProductDocuments/DataSheets/Atmel-42005-8-and-16-bit-AVR-Microcontrollers-XMEGA-E_Manual.pdf
Page 180.
Back to top
View user's profile
andrge

Bascom Member



Joined: 26 Oct 2011
Posts: 7
Location: Kaufbeuren

germany.gif
PostPosted: Thu Aug 19, 2021 3:49 pm    Post subject: Reply with quote

I thought i tried setting that bit already but it seems to work now. Thank you.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum