Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20606

BASCOM-AVR : xmega ADC-DMA problem : NEWTOPIC

$
0
0
The code was written according to the samples of Bascom 2.0.7.7 for Xmega based on a sample AD_Free_run_1_channel_8-bit_mode + one DMA Channel.bas. But this code works only once (J=1). What I need to do for the Sub Get_adc() restarting ? [code:1:0d280530c4]$regfile = "xm128a4udef.dat" $crystal = 32000000 '32MHz $hwstack = 64 $swstack = 40 $framesize = 40 Config Osc = Enabled , 32mhzosc = Enabled , Plldiv2 = Enabled Config Sysclock = 32mhz '--> 32MHz Config Com5 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 Open "COM5:" For Binary As #1 'Config Eeprom = Mapped 'when using EEPROM , add this config command '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Const Sample_count = 1500 'Number of 12-Bit Samples (Measurement Values) '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Dim Channel_0(sample_count) As Integer 'Measurement Array for Channel 0 Dim Dma_ready As Bit Dim Dma_channel_0_error As Bit Dim X As Word , J As Byte Declare Sub Get_adc() ' DMA Interrupt On Dma_ch0 Dma_ch0_int 'Interrupt will be enabled with Tci = XX in Config DMAX Config Dma = Enabled , Doublebuf = Disabled , Cpm = Ch01rr23 ' enable DMA, Double Buffer disabled Config Priority = Static , Vector = Application , Lo = Enabled ' DMA Channel 0 is used here Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Lo , Eil = Lo , Singleshot = Enabled , _ Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H10 , Btc = 3000 , Repeat = 1 , Sadr = Varptr(adca_ch0_res) , Dadr = Varptr(channel_0(1)) ' We use DMA Channel 0 ' Burstlen = 2 (We use here 12-Bit Mode so we need 2Bytes from Source Address = ADC A) ' Channelrepeat is enabled ' BTC = 2000 (must be 2X of Sample_count because of 2 Bytes per Measurement Value) ' TCI = Lo --> Low Level Transaction Complete Interrupt is enabled ' EIL = Lo --> Low Level Error Interrupt is enabled ' Sar = Source Address reloaded after each burst ' Sam = incremented (Low Byte and High Byte of Measurement Value) ' Dar = No Destination address reload ' Dam = inc (Destination Address (the Array) will be incremented by one) ' Trigger (Trigger base value for ADC A = &H10 + Trigger offset = &H00 for Channel 0 --> &H10 ) 'Configure ADC of Port A in FREE running mode Config Adca = Free , Convmode = Signed , Resolution = 12bit , Dma = Ch01 , _ Reference = Int1v , Event_mode = None , Prescaler = 16 , Sweep = Ch0 , _ Ch0_gain = 2 , Ch0_inp = Diffwgain , Mux0 = &B00000000 Enable Interrupts For J = 1 To 5 Call Get_adc() For X = 1 To Sample_count Print #1 , Channel_0(x) ; " "; Next X Print #1, Print #1 , "J=" ; J Reset Dma_ready Set Adca_ctrlb.3 Set Adca_ctrla.0 Next J End 'end program '************************************************* Sub Get_adc() '************************************************* Do Loop Until Dma_ready = 1 'Disable Channel 0 Interrupt on comversion complete Adca_ch0_intctrl = &B0000_00_00 'OFF Int on Conversion complete (CH 0) 'Disable Free Running mode Reset Adca_ctrlb.3 'Disable ADC A Reset Adca_ctrla.0 End Sub '----------------------[Interrupt Service Routines]----------------------------- ' Dma_ch0_int is for DMA Channel ERROR Interrupt A N D for TRANSACTION COMPLETE Interrupt ' Which Interrupt fired must be checked in Interrupt Service Routine Dma_ch0_int: If Dma_intflags.0 = 1 Then 'Channel 0 Transaction Interrupt Flag Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag Set Dma_ready End If If Dma_intflags.4 = 1 Then 'Channel 0 ERROR Flag Set Dma_intflags.4 'Clear the flag Set Dma_channel_0_error 'Channel 0 Error End If Return[/code:1:0d280530c4] Help me please. [b:0d280530c4][color=red:0d280530c4](BASCOM-AVR version : 2.0.7.7 )[/b:0d280530c4][/color:0d280530c4]

Viewing all articles
Browse latest Browse all 20606

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>