ADC mit DMA

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Ich versuche gerade den ADC auszulesen.

      Source Code

      1. Config Sysclock = 32mhz , Prescalea = 1 ', Prescalebc = 1_1
      2. Enable Interrupts
      3. Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled , Hi = Enabled
      4. Config Dma = Enabled , Doublebuf = Disabled , Cpm = Ch0rr123
      5. Config Adca = Single , Convmode = Unsigned , Resolution = 12bit , Dma = Ch012 , Reference = Int1v , Event_mode = None , Prescaler = 32 , _
      6. Ch0_gain = 1 , Ch1_gain = 1 , Ch0_inp = Single_ended , Mux0 = &B00011000 , Ch1_inp = Single_ended , Mux1 = &B00001000 , Ch2_inp = Single_ended , Mux2 = &B00010000 , Ch3_inp = Single_ended , Mux3 = &B00011000 'you can setup other channels as well
      7. Dim Dma_ready2 As Bit
      8. On Dma_ch1 Dma_ch2_int
      9. Dim Channel2_0(150) As Word
      10. Dim Channel2_0_ges As Word
      11. Dim Globword1 As Byte
      12. Config Dmach1 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Lo , Eil = Lo , Singleshot = Enabled , _
      13. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H10 , Btc = 50 , Repeat = 0 , Sadr = Varptr(adca_ch1_res) , Dadr = Varptr(channel2_0(1))
      14. Channel2_0(5) = 50
      15. do
      16. Waitms 50
      17. Dma_ch1_ctrla.7 = 1
      18. Waitms 50
      19. Channel2_0_ges = 0
      20. For Globword1 = 1 To 25
      21. Channel2_0_ges = Channel2_0_ges + Channel2_0(globword1)
      22. Next
      23. Lcdat 5 , 1 , Channel2_0_ges
      24. loop
      25. Dma_ch2_int: ' DMA Transaction complete
      26. If Dma_intflags.1 = 1 Then ' Channel 0 Transaction Interrupt Flag
      27. Set Dma_intflags.1 ' Clear the Channel 0 Transaction Complete flag
      28. Set Dma_ready2
      29. End If
      30. Return
      Display All
      Ich bekomme aber als channel2_0ges immer den wert 50 also wird der dma überhaupt nicht ausgeführt.
      hat jemand ne idee was da falsch ist?
    • Da kannste lange warten. Was nirgendwo steht ist, dass config dma in die schleife gehört. Hatte ich schon im alten verlorenen forum mitgeteilt.
      Ich liebe auch keine Interrupts. Deswegen warte ich lieber auf das Ende der Transaktion.
      Nachher wenn der Kaffee verdaut ist, poste ich mal wie ich es mache, aber vielleicht hilft dies ja schon.
    • Ohne das config DMA_ch0 in der Loop läuft's nur einmal. Hat mich viel Zeit gekostet ....
      Habe auch mal versucht, herauszufinden, welches register da gesetzt werden müsste, anstelle, hab's aber nicht gefunden. Außerdem geht das config genügend schnell.

      Source Code

      1. Config Priority = Static , Vector = Application , Lo = Enabled
      2. Config Dma = Enabled , Doublebuf = Disabled , Cpm = Ch01rr23
      3. Config Adca = Free , Convmode = Signed , Resolution = 12bit , Dma = Ch01 , _
      4. Reference = Int1v , Prescaler = 32 , Sweep = Ch0 , Event_mode = None , Event_channel = Ch0123 , _
      5. Ch0_gain = 1 , Ch0_inp = Diffwgain , Mux0 = &H33
      6. Enable Interrupts
      7. Start Adca
      8. Start Adcb
      9. Do
      10. Portf.7 = 0 'LED
      11. Null = 0
      12. I = Memcopy(null , Summenarray1(1) , Sample1_countx2 , 2) 'sample_countx2,2)
      13. I = Memcopy(null , Summenarray0(1) , Sample_countx2 , 2)
      14. For I2 = 1 To 64
      15. Bitwait Aca_status.0 , Set 'AC0 IntFlag
      16. Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Hi , Eil = Lo , Singleshot = Enabled , _
      17. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H10 , Btc = Sample_countx2 , Repeat = 1 , Sadr = Varptr(adca_ch0_res) , Dadr = Varptr(samples(1))
      18. Set Adca_ctrla.0 'enable adc
      19. Aca_status.0 = 1 'Clear AC0 IntFlag
      20. Porte.3 = 1 'Gate out
      21. Bitwait Dma_intflags.0 , Set 'Channel 0 Transaction Interrupt Flag
      22. Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag
      23. Reset Adca_ctrla.0
      24. Set Adca_ctrla.1 'flush
      25. Reset Adca_ctrla.0 'disable adc
      26. Porte.3 = 0
      27. Portf.7 = 1
      28. Adca_refctrl = &B0_001_0000
      29. Next I2
      30. Loop
      Display All
    • Danke, bei Channel 0 geht das, aber bei channel 1 und 2 bekomme ich bei allen Variablen 0

      Source Code

      1. $regfile = "xm128a4udef.dat"
      2. $crystal = 32000000 '32MHz
      3. $hwstack = 64
      4. $swstack = 40
      5. $framesize = 40
      6. $lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
      7. Config Osc = Enabled , 32mhzosc = Enabled
      8. Config Sysclock = 32mhz '--> 32MHz
      9. 'Serial Interface to PC
      10. Config Com2 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
      11. Open "COM2:" For Binary As #1
      12. Config Priority = Static , Vector = Application , Lo = Enabled
      13. Config Dma = Enabled , Doublebuf = Disabled , Cpm = Ch01rr23
      14. 'Config Adca = Free , Convmode = Signed , Resolution = 12bit , Dma = Ch01 , _
      15. 'Reference = Int1v , Prescaler = 32 , Sweep = Ch0 , Event_mode = None , Event_channel = Ch0123 , _
      16. 'Ch0_gain = 1 , Ch0_inp = Diffwgain , Mux0 = &H33
      17. Config Adca = Free , Convmode = Unsigned , Resolution = 12bit , Dma = Ch012 , Reference = Int1v , Event_mode = None , Prescaler = 32 , _
      18. Ch0_gain = 1 , Ch1_gain = 1 , Ch0_inp = Single_ended , Mux0 = &B00011000 , Ch1_inp = Single_ended , Mux1 = &B00001000 , Ch2_inp = Single_ended , Mux2 = &B00010000 , Ch3_inp = Single_ended , Mux3 = &B00011000 'you can setup other channels as well
      19. Enable Interrupts
      20. Dim Samples(100) As Word
      21. Dim Samples2(100) As Word
      22. Dim I2 As Word
      23. Dim Globword1 As Word
      24. Dim Channel2_0_ges As Dword
      25. Dim Channel1_0_ges As Dword
      26. Start Adca
      27. Print #1 , "anfang"
      28. Do
      29. 'Bitwait Aca_status.0 , Set 'AC0 IntFlag
      30. Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Hi , Eil = Lo , Singleshot = Enabled , _
      31. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H10 , Btc = 50 , Repeat = 1 , Sadr = Varptr(adca_ch0_res) , Dadr = Varptr(samples(1))
      32. Set Adca_ctrla.0 'enable adc
      33. Aca_status.0 = 1 'Clear AC0 IntFlag
      34. Bitwait Dma_intflags.0 , Set 'Channel 0 Transaction Interrupt Flag
      35. Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag
      36. Reset Adca_ctrla.0
      37. Set Adca_ctrla.1 'flush
      38. 'Reset Adca_ctrla.0 'disable adc
      39. Adca_refctrl = &B0_001_0000
      40. Waitms 100
      41. Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Hi , Eil = Lo , Singleshot = Enabled , _
      42. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H14 , Btc = 50 , Repeat = 1 , Sadr = Varptr(adca_ch1_res) , Dadr = Varptr(samples2(1))
      43. Set Adca_ctrla.0 'enable adc
      44. Aca_status.0 = 1 'Clear AC0 IntFlag
      45. Bitwait Dma_intflags.0 , Set 'Channel 0 Transaction Interrupt Flag
      46. Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag
      47. Reset Adca_ctrla.0
      48. Set Adca_ctrla.1 'flush
      49. 'Reset Adca_ctrla.0 'disable adc
      50. Adca_refctrl = &B0_001_0000
      51. Waitms 100
      52. Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Hi , Eil = Lo , Singleshot = Enabled , _
      53. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H14 , Btc = 50 , Repeat = 1 , Sadr = Varptr(adca_ch2_res) , Dadr = Varptr(samples2(1))
      54. Set Adca_ctrla.0 'enable adc
      55. Aca_status.0 = 1 'Clear AC0 IntFlag
      56. Bitwait Dma_intflags.0 , Set 'Channel 0 Transaction Interrupt Flag
      57. Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag
      58. Reset Adca_ctrla.0
      59. Set Adca_ctrla.1 'flush
      60. 'Reset Adca_ctrla.0 'disable adc
      61. Adca_refctrl = &B0_001_0000
      62. Channel1_0_ges = 0
      63. For Globword1 = 1 To 25
      64. Channel1_0_ges = Channel1_0_ges + Samples(globword1)
      65. Next
      66. Channel2_0_ges = 0
      67. For Globword1 = 1 To 25
      68. Channel2_0_ges = Channel2_0_ges + Samples2(globword1)
      69. Next
      70. Print #1 , Channel1_0_ges ; " " ; Channel2_0_ges ; " " ; Samples2(2) ; " " ; Samples2(3) ; " " ; Samples(4)
      71. Waitms 200
      72. Loop
      Display All
    • tscha, aber ich wette (um was) daran liegts. Man muss dann entweder einen ICE oder dragon Debugger zu rate ziehen (nur so konnte ich bascom und xmega Vereinen) und das Dat file studieren.
      Vielleicht hilft aber auch der kostenlose Studio7 simulator.
      Wenn die Dat files für eine der Peripherien gut waren, war man vielleicht zufrieden. Das generelle problem zieht sich schon Jahre hin.
    • mist!!!!!
      aber danke. leider sind meine programmierkentnisse nicht so weit vortgeschritten um so ein fehler zu finden. im schlimmsten fall neme ich nen 2. prozessor, und übertrage dann die daten mit uart und dma auf den hauptprozessor.
      dass hätte sogar den vorteil, dass ich das ssd1306 display auch ohne zeitverzögerung betreiben kann, da das ja auch nicht über dma geht

      The post was edited 1 time, last by tobiw ().

    • nee, das ist aber gar nicht schön, obwohl du mit 921600 übertragen könnteSt.
      Das "billigste" ist, du guckst dir mal im code-explorer-fenster die RegisterNamen an und schaust in das Datenblatt zum Prozessor, ob wenigstens die entsprechenden Register vorkommen.
      Nebenbei, hat der a4 entsprechend viele dma-kanäle wie du denkst?
    • ohne dma geht es

      Source Code

      1. Getjoistik:
      2. Globdword1 = 0
      3. Globdword2 = 0
      4. Globdword3 = 0
      5. For Schleifen = 0 To 100 '255
      6. Joistik_yanalog = Getadc(adca , 1)
      7. Globdword2 = Globdword2 + Joistik_yanalog
      8. Next
      9. Globdword2 = Globdword2 / 50 '256
      10. Joistik_yanalog = Globdword2
      11. For Schleifen = 0 To 100
      12. Joistik_zanalog = Getadc(adca , 2)
      13. Globdword3 = Globdword3 + Joistik_zanalog
      14. Next
      15. Globdword3 = Globdword3 / 50
      16. Joistik_zanalog = Globdword3
      17. For Schleifen = 0 To 100
      18. Joistik_xanalog = Getadc(adca , 3)
      19. Globdword1 = Globdword1 + Joistik_xanalog
      20. Next
      21. Globdword1 = Globdword1 / 50
      22. Joistik_xanalog = Globdword1
      Display All
    • achso adc einstellung:

      Source Code

      1. Config Adca = Single , Convmode = Unsigned , Resolution = 12bit , Dma = Off , Reference = Int1v , Event_mode = None , Prescaler = 32 , _
      2. Ch0_gain = 1 , Ch1_gain = 1 , Ch0_inp = Single_ended , Mux0 = &B00011000 , Ch1_inp = Single_ended , Mux1 = &B00001000 , Ch2_inp = Single_ended , Mux2 = &B00010000 , Ch3_inp = Single_ended , Mux3 = &B00011000 'you can setup other channels as well
    • Das heißt noch nicht, dass Deine Muxen (z.B.Mux2 = &B00010000) richtig waren.
      Probier mal mit Mux parameter.
      W = Getadc(adca , 0 , Mux)
      In der riesigen Tabelle für config adcx herumsuchen, um den passenden Mux zu finden.
      Hilfe sagt:"MUX
      An optional numeric variable or constant that specifies the MUX value thus which input pin is used for the measurement. The MUX number is coded with negative and positive input pin info. The positive pins are have an offset of 8. So PIN0 in single ended mode would need a value of 8."
    • Ist nicht die feine art, aber so geht es
      zeile 45 57 einfach vorher die mux auf die pins umschalten

      Source Code

      1. '$regfile = "xm128a1udef.dat"
      2. $regfile = "xm128a1def.dat"
      3. $crystal = 32000000 '32MHz
      4. $hwstack = 64
      5. $swstack = 40
      6. $framesize = 40
      7. $lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
      8. Config Osc = Enabled , 32mhzosc = Enabled
      9. Config Sysclock = 32mhz '--> 32MHz
      10. 'Serial Interface to PC
      11. Config Com2 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
      12. Open "COM2:" For Binary As #1
      13. Config Priority = Static , Vector = Application , Lo = Enabled
      14. Config Dma = Enabled , Doublebuf = Disabled , Cpm = Ch01rr23
      15. 'Config Adca = Free , Convmode = Signed , Resolution = 12bit , Dma = Ch01 , _
      16. 'Reference = Int1v , Prescaler = 32 , Sweep = Ch0 , Event_mode = None , Event_channel = Ch0123 , _
      17. 'Ch0_gain = 1 , Ch0_inp = Diffwgain , Mux0 = &H33
      18. Config Adca = Free , Convmode = Unsigned , Resolution = 12bit , Dma = Ch012 , Reference = Int1v , Event_mode = None , Prescaler = 32 , _
      19. Ch0_gain = 1 , Ch1_gain = 1 , Ch0_inp = Single_ended , Mux0 = &B00011000 , Ch1_inp = Single_ended , Mux1 = &B00001000 , Ch2_inp = Single_ended , Mux2 = &B00010000 , Ch3_inp = Single_ended , Mux3 = &B00011000 'you can setup other channels as well
      20. Enable Interrupts
      21. Dim Samples(100) As Word
      22. Dim Samples2(100) As Word
      23. Dim Samples3(100) As Word
      24. Dim I2 As Word
      25. Dim Globword1 As Word
      26. Dim Channel2_0_ges As Dword
      27. Dim Channel1_0_ges As Dword
      28. Start Adca
      29. Print #1 , "anfang"
      30. Do
      31. Adca_ch0_muxctrl = &B00011000
      32. 'Bitwait Aca_status.0 , Set 'AC0 IntFlag
      33. Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Hi , Eil = Lo , Singleshot = Enabled , _
      34. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H10 , Btc = 50 , Repeat = 1 , Sadr = Varptr(adca_ch0_res) , Dadr = Varptr(samples(1))
      35. Set Adca_ctrla.0 'enable adc
      36. Aca_status.0 = 1 'Clear AC0 IntFlag
      37. Bitwait Dma_intflags.0 , Set 'Channel 0 Transaction Interrupt Flag
      38. Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag
      39. Reset Adca_ctrla.0
      40. Set Adca_ctrla.1 'flush
      41. 'Reset Adca_ctrla.0 'disable adc
      42. Adca_ch0_muxctrl = &B00001000
      43. Adca_refctrl = &B0_001_0000
      44. Waitms 100
      45. Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Hi , Eil = Lo , Singleshot = Enabled , _
      46. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H10 , Btc = 50 , Repeat = 1 , Sadr = Varptr(adca_ch0_res) , Dadr = Varptr(samples2(1))
      47. Set Adca_ctrla.0 'enable adc
      48. Aca_status.0 = 1 'Clear AC0 IntFlag
      49. Bitwait Dma_intflags.0 , Set 'Channel 0 Transaction Interrupt Flag
      50. Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag
      51. Reset Adca_ctrla.0
      52. Set Adca_ctrla.1 'flush
      53. 'Reset Adca_ctrla.0 'disable adc
      54. Adca_refctrl = &B0_001_0000
      55. Adca_ch0_muxctrl = &B00010000
      56. Waitms 100
      57. Config Dmach0 = Enabled , Burstlen = 2 , Chanrpt = Enabled , Tci = Hi , Eil = Lo , Singleshot = Enabled , _
      58. Sar = Burst , Sam = Inc , Dar = None , Dam = Inc , Trigger = &H14 , Btc = 50 , Repeat = 1 , Sadr = Varptr(adca_ch0_res) , Dadr = Varptr(samples3(1))
      59. Set Adca_ctrla.0 'enable adc
      60. Aca_status.0 = 1 'Clear AC0 IntFlag
      61. Bitwait Dma_intflags.0 , Set 'Channel 0 Transaction Interrupt Flag
      62. Set Dma_intflags.0 'Clear the Channel 0 Transaction Complete flag
      63. Reset Adca_ctrla.0
      64. Set Adca_ctrla.1 'flush
      65. 'Reset Adca_ctrla.0 'disable adc
      66. Adca_refctrl = &B0_001_0000
      67. Channel1_0_ges = 0
      68. For Globword1 = 1 To 25
      69. Channel1_0_ges = Channel1_0_ges + Samples(globword1)
      70. Next
      71. Channel2_0_ges = 0
      72. For Globword1 = 1 To 25
      73. Channel2_0_ges = Channel2_0_ges + Samples2(globword1)
      74. Next
      75. Print #1 , Channel1_0_ges ; " " ; Channel2_0_ges ; " " ; Samples2(2) ; " " ; Samples2(3) ; " " ; Samples(4)
      76. Waitms 200
      77. Loop
      Display All