Bascom support für Xmega-A1-USB

Natalius

Neues Mitglied
19. Dez. 2009
9
0
0
Sprachen
Hallo Bascom user,

es gibt gute Neuigkeiten zu Weihnachten:

Hatte ein paar Tage das Vergnügen, als Beta-Tester tätig zu sein:
Mark Alberts hat mit der letzen Bascom-Revision (1.11.9.7) deutliche Fortschritte für die Unterstützung des Xmega128A1 erzielt. Gegenüber der Vorversion (Anfang Dezember), die faktisch nur USARTC0 unterstützte, werden jetzt alle 8 USARTs angesprochen (Com1..Com8), also auch Com7 wie für Dirk's Xmega-A1-USB board (my favorite!) erforderlich. ADCs und DACs sind bereits voll lauffähig, Eeprom R/W funzt, DMA-Unterstützung ist teilweise verwirklicht, Interrupt-Priorisierung ist da, interne und externe Taktgeber sind konfigurierbar, Event-Handling und 16-Bit Timer/Counter incl. PWM-Synthese muß noch "registernah" selbst gemacht werden.

Hier das originale Source-Snippet mit Anpassung für Xmega-A1-USB eingebaut:

'----------------------------------------------------------------
' (c) 1995-2009, MCS
' xm128A1.bas
' This sample demonstrates the Xmega128A1
'-----------------------------------------------------------------

$regfile = "xm128a1def.dat"
$crystal = 32000000
$hwstack = 64
$swstack = 40
$framesize = 40

'include the following lib and code, the routines will be replaced since they are a workaround
$lib "xmega.lib"
$external _xmegafix_clear
$external _xmegafix_rol_r1014

'$timeout = 8000000 TIMEOUT WILL WORK FOR ALL UARTS

'first enable the osc of your choice
Config Osc = Enabled , 32mhzosc = Enabled

'configure the systemclock
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

Dim N As String * 16 , B As Byte
Config Com7 = 38400 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Config Input7 = Cr , Echo = Crlf ' CR is used for input, we echo back CR and LF
Open "COM7:" For Binary As #7
' ^^^^ change from COM1-COM8
Config Portf = Output
'Config Portf.3 = Output ' TX pin must be output
Config Pinf.2 = Input
Config Portq = Output

Waitms 500

Print #7 , "Xmega revision:" ; Mcu_revid ' make sure it is 7 or higher !!! lower revs have many flaws

Config Eeprom = Mapped ' when using EEPROM , add this config command

'setup the DACA
Config Daca = Enabled , Io0 = Enabled , Channel = Single , Reference = Int1v , Interval = 64 , Refresh = 64
Daca = 4095 '1 V output on porta.2
'Start Daca ' to enabled it
'Stop Daca ' to diabled it

'setup the ADC-A converter
Config Adca = Single , Convmode = Unsigned , Resolution = 12bit , Dma = Off , Reference = Int1v , Event_mode = None , Prescaler = 32 , Ch0_gain = 1 , Ch0_inp = Single_ended , Mux0 = 0 'you can setup other channels as well

Dim Teller As Long
Dim Le As Eram Long ' eram var
Dim L As Long ' normal var
L = &H12345678
Le = L
L = 0
L = Le
Print #7 , Hex(l) 'test if it worked

Dim W As Word, Iby as Byte
Do
W = Getadc(adca , 0)
Print #7 , W
Waitms 500
Iby = Waitkey(#7)
Loop Until Iby = 27
'Achtung: Im ursprüglichen snippet steht noch Loop until Inkey(#1),
'da meckert bei mir allerdings der Compiler, werde ich noch rückmelden.

'configure the priority
'config priority=static|roundrobin,vector=application|boot,HI=enabled|disabled, LO=enabled|disabled,ME=enabled|disabled
Config Priority = Static , Vector = Application , Lo = Enabled

'test an interrupts
On Usartc0_rxc Rxc_isr
Enable Usartc0_rxc , Lo
Enable Interrupts


Dim Tel As Byte
Tel = 65
Do
Teller = 0
'Print #1 , "press ESC key"
'Do
' Tel = Inkey(#1)
' Print #1 , Tel
' Waitms 100
'Loop Until Tel = 27

Tel = Waitkey(#7)
Print #7 , Tel
Input #7 , "name?" , N
Print #7 , N
Print #7 , Teller
Loop


Rxc_isr:
Toggle Portq.3
Incr Teller
Return

-------------------------------
Was braucht man sonst noch:
Die Version 1.11.9.7 ist nur registierten Bascom-Usern zugänglich. Man braucht ein neues LIC-File, das bei www.mcselec.com unter Registration und Update im Main Menu zu finden ist. Danach kann mit dem vorhandenen AutoUpdate Wiz weitergemacht werden.
Es gibt unter Samples/Boot einen Bootloader für den Xmega, der hat bei mir vor ein paar Tagen auf dem Xmega-A1-USB board noch nicht mit dem in Bascom eingebauten Uploader (MCS Bootloader) glatt funktioniert. Werde ihn noch anpassen. Mit Dirk's Programmer geht es aber mindestens genau so schön.
Für das Bootloader-Flashen (oder Direktflashen) sollte man als HW mindestens den AVRISP mkII einsetzen (AVR-Praxis-Shop). Das Update der FW geht mit dem AVR Studio (ab Juliversion, inzwischen gibt es eine Dezemberversion). Da der AVRISP mkii ab Dezemberversion per Kommandozeile aufrufbar ist (auch für PDI) sollte ein Direkteinbau in Bascom gelingen. Wird vermutlich nicht lange dauern, bis diese Option zur Verfügung steht.

Frohe Weihnachten und einen guten Rutsch,

N.
 
Hallo Natalius,

danke für die guten Infos. Na, das läßt ja hoffen ....
Wenigstens geht es mit BASCOm weiter, selbst wenn manchmal der Eindruck entsteht, dass es darum etwas ruhiger geworden ist.

Hast Du selber heiße Drähte zu MCS. Mann könnte Dich ja dazu "missbrauchen" :D einige Änderungswünsche und Korrekturvorschläge bei MCS einzukippen. Ich hatte das in der Vergangenheit via Email direkt getan und bis heute auf keine Email eine Antwort erhalten.

Grüße,
Markus
 
Hallo Markus,

ich bin davon überzeugt, daß es jetzt sogar in grösseren Schritten weitergeht. Bascom ist im Moment vielleicht nicht ganz so populär wie andere Dinge (die mit Ard.. beginnen), aber warte mal ab, es kommt zurück. Mark Alberts steht mit seinem Namen hinter Bascom. So wie ich ihn verstehe will er EINEN Compiler für die gesamten AVRs, und nicht - was aus ökonomischen Gründen (kurzfristig angedacht) naheliegend wäre - ein Aufsplitten in X und pre-X.

Einen sog. heissen Draht zu MCS habe ich natürlich nicht. Wir haben uns über email in den letzten Wochen kennengelernt, ich hatte ein kleines Problem, und schwupps in 9.6 war es offiziell behoben. Der ursprüngliche Kontakt ging aber über ein Ticket bei der supportline - einen Monat früher. Sei also bitte nicht zu ungeduldig - MCS gehört ebenso wie die Rodenhausen brothers zu den sog. SMEs (EUish: Small and medium enterprises), mehr als 24 h Arbeit geht halt nicht und "free tickets" können daher nicht unendlich schnell bedient werden. Sorry, will nicht belehrend wirken, aber laß uns einfach in die Lage von SMEs versetzen - keiner will diesen Turbokapitalismus um die Gunst der "Amateure" (wie wir) - er existiert halt trotzdem. Ich frage mich z.B: Warum ist Ard... bei den Fans soooo erfolgreich?

Ich glaube, daß eine "wishlist" offenes Gehör finden wird. Habe selbst auch schon Wünsche geäussert, aber die Priorisierung muß bei Mark bleiben. Er muß schliesslich davon leben, während es für mich und für Dich "nur" ein Hobby ist.

Laß uns Weihnachten geniessen!

N.
 
BASCOM 1.11.9.8 und xm128A1def.dat-Erweiterung für PWM und Modellbau-Servos

Hallo Xmega-A1-USB & Bascom-Fans,

Bascom 1.11.9.8 ist seit 24.12. verfügbar. Was für einen Kickstart von Dirk's Xmega-Modul in der Modellbau- und Robotikszene noch fehlt ist high resolution pwm. Anbei deswegen ein kleines Xmas-Präsent von meiner Seite aus. Es ist etwas Tiparbeit an der xm128A1def.dat erforderlich, aber der Aufwand hält sich in Grenzen. Wie es geht steht im source snippet:

Nen guten Rutsch wünsche ich noch,

Natalius


'----------------------------------------------------------------
' (C) MCS 2009 & N.Kiedro
' Xmega2Servo.bas
' This snippet demonstrates PWM on the Xmega128A1
' Platform: Xmega A1 USB module from http://shop.avr-praxis.de
'
' USE port D to create six RC servo signals in 4000 steps/ms
' resolution via interrupt-free single slope PWM.
' Servo signals are pulses between 1 and 2 ms,
' corresponding to 4000 to 8000 here - center at 6000.
' In my own kixm128a1def.dat file I have done these extensions for
' all Timer/Counters which allows to control 20 servos (=24-4 because
' of USART F0 in use) via the Xmega-A1-USB module. Of course, jitter-free
' and with best achievable resolution @ 32 MHz.
'-----------------------------------------------------------------

$regfile = "kixm128a1def.dat"

'For BASCOM 1.11.9.8: This snippet needs an extended definition dat with the following
'changes:
''(1) Load xm128a1def.dat into the editor and save it under a different name, e.g. kixm128a1def.dat
''(2) Find the following definitions for TCD0, TCD1
'' _CNT
'' _PER
'' _CCA
'' _CCB
'' _CCC
'' _CCD
'' _PERBUF
'' _CCABUF
'' _CCBBUF
''
''(3) Replace the corresponding sections as follows:
'' TCD0_CNTL = 2336 ; Count
'' TCD0_CNTH = 2337 ; Count
'' TCD0_PERL = 2342 ; Period
'' TCD0_PERH = 2343 ; Period
'' TCD0_CCAL = 2344 ; Compare or Capture A
'' TCD0_CCAH = 2345 ; Compare or Capture A
'' TCD0_CCBL = 2346 ; Compare or Capture B
'' TCD0_CCBH = 2347 ; Compare or Capture B
'' TCD0_CCCL = 2348 ; Compare or Capture C
'' TCD0_CCCH = 2349 ; Compare or Capture C
'' TCD0_CCDL = 2350 ; Compare or Capture D
'' TCD0_CCDH = 2351 ; Compare or Capture D
'' TCD0_PERBUFL = 2358 ; Period Buffer
'' TCD0_PERBUFH = 2359 ; Period Buffer
'' TCD0_CCABUFL = 2360 ; Compare Or Capture A Buffer
'' TCD0_CCABUFH = 2361 ; Compare Or Capture A Buffer
'' TCD0_CCBBUFL = 2362 ; Compare Or Capture B Buffer
'' TCD0_CCBBUFH = 2363 ; Compare Or Capture B Buffer
'' TCD0_CCCBUFL = 2364 ; Compare Or Capture C Buffer
'' TCD0_CCCBUFH = 2365 ; Compare Or Capture C Buffer
'' TCD0_CCDBUFL = 2366 ; Compare Or Capture D Buffer
'' TCD0_CCDBUFH = 2367 ; Compare Or Capture D Buffer
''
'' TCD1_CNTL = 2400 ; Count
'' TCD1_CNTH = 2401 ; Count
'' TCD1_PERL = 2406 ; Period
'' TCD1_PERH = 2407 ; Period
'' TCD1_CCAL = 2408 ; Compare or Capture A
'' TCD1_CCAH = 2409 ; Compare or Capture A
'' TCD1_CCBL = 2410 ; Compare or Capture B
'' TCD1_CCBH = 2411 ; Compare or Capture B
'' TCD1_PERBUFL = 2422 ; Period Buffer
'' TCD1_PERBUFH = 2423 ; Period Buffer
'' TCD1_CCABUFL = 2424 ; Compare Or Capture A Buffer
'' TCD1_CCABUFH = 2425 ; Compare Or Capture A Buffer
'' TCD1_CCBBUFL = 2426 ; Compare Or Capture B Buffer
'' TCD1_CCBBUFH = 2427 ; Compare Or Capture B Buffer
''(4) Dont forget to save the changes


$crystal = 32000000
$hwstack = 512
$swstack = 256
$framesize = 256

'include the following lib and code, the routines will be replaced since they are a workaround
$lib "xmega.lib"
$external _xmegafix_clear
$external _xmegafix_rol_r1014

'$timeout = 8000000 TIMEOUT WILL WORK FOR ALL UARTS

'first enable the osc of your choice
Config Osc = Enabled , 32mhzosc = Enabled 'remarkably accurate given the fact that no xtal is employed
'Config Osc = Enabled , Extosc = Enabled , Range = 12mhz_16mhz , Startup = Xtal_16kclk (so far doesn't work)

'configure the systemclock
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

Dim N As String * 16 , B As Byte
Dim Tel As Byte , Channum As Byte , Jst As String * 1 , Chanval As Word , Chanpwm(6) As Word , Iby As Byte

Config Com7 = 38400 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Config Input7 = Cr , Echo = Crlf ' CR is used for input, we echo back CR and LF

Open "COM7:" For Binary As #7
' ^^^^ change from COM1-COM8

Config Portf = Output
Config Portf.3 = Output ' TX pin must be output
Config Portf.2 = Input
Config Portq = Output

'Waitms 500
Print #7 , "Press <CR> to start";

'pwm initialisation here
'RC cycle period should be ideally at 20ms, viz. 50 Hz.
'With fpwm = fosc/per/clkdiv = 32MHz/(2^16)/8 = 1MHz/2^14 = 61.0352 Hz we have a
'cycle period of 16.384 ms most servos should be able to live with.

' From http://www.atmel.com/dyn/resources/prod_documents/doc8045.pdf:
' 6.4 Using a Timer/Counter for PWM Generation
' Task: Configure TCC0 for pulse width modulation output with varying duty cycle on channel A.
' 1. Configure PC0 for output by setting bit 0 in PORTC.DIR.
' 2. Select the timer period by setting the PER[H:L] register.
' 3. Select a waveform generation mode by setting the WGMODE[2:0] bits in CTRLB
' 4. Enable Compare Channel A by setting the CCAEN bit in CTRLB.
' 5. Start the TC by selecting a clock source (CLKSEL[3:0] in CTRLA).
' 6. Calculate the desired compare value.
' 7. Write the new compare value to CCA[H:L].
' 8. Wait for the TC Overflow Flag to be set. (OVFIF in INTFLAGS).
' 9. Clear the TC Overflow flag.
' 10. Go to step 6.
'Using this sequence, the compare value will be updated once every PWM period.

'Modification: free running pwm - no interrupt, but ASAP update instead:
' 1. Configure PD0 and PD1 for output --> PORTD.DIR.
' 2. Select the timer period by setting the PER[H:L] register.
' 3. Select a waveform generation mode by setting the WGMODE[2:0] bits in CTRLB
' 4. Enable Compare Channel A-D by setting the CCAEN bits in CTRLB.
' 5. Start the TC by selecting a clock source (CLKSEL[3:0] in CTRLA).
' 6. Calculate the desired compare value.
' 7. Write the new compare value to CCxBUF[H:L].
' 8. Go to step 6

'ad 1.
Portd_dir = &HFF

'ad2.
Tcd0_perl = &HFF
Tcd0_perh = &HFF
Tcd1_perl = &HFF
Tcd1_perh = &HFF

'ad 3 & 4
Tcd0_ctrlb = &HF3 'define WGMODE 011 = single slope and set OCA-D active
Tcd1_ctrlb = &HC3

'ad 5
Tcd0_ctrla = &H04 'Divide Clock By 8 , Enable Timers (Bits 3..0 define clckdiv)
Tcd1_ctrla = &H04

'ad 6
For Iby = 1 To 6
Chanpwm(iby) = 6000
Next Iby

'ad 7
Gosub Update

'configure the priority
'config priority=static|roundrobin,vector=application|boot,HI=enabled|disabled, LO=enabled|disabled,ME=enabled|disabled
Config Priority = Static , Vector = Application , Lo = Enabled

'test an interrupts
On Usartf0_rxc Rxc_isr
Enable Usartf0_rxc , Lo
Enable Interrupts


Tel = 65
Do
Print #7 , "Channel(1-6)?";
Tel = Waitkey(#7)
Jst = Chr(tel)
Channum = Val(jst)
Print #7 , Channum
Input #7 , "value?" , N 'enter values between 4000 (1ms) and 8000 (2ms)
Chanval = Val(n)
Print #7 , N
Chanpwm(channum) = Chanval
'ad 7
Gosub Update
Loop




Rxc_isr:
Toggle Portq.3
'Incr Teller
Return



Update:

Tcd0_ccabufL = Low(chanpwm(1))
Tcd0_ccabufH = High(chanpwm(1))

Tcd0_ccbbufL = Low(chanpwm(2))
Tcd0_ccbbufH = High(chanpwm(2))

Tcd0_cccbufL = Low(chanpwm(3))
Tcd0_cccbufH = High(chanpwm(3))

Tcd0_ccdbufL = Low(chanpwm(4))
Tcd0_ccdbufH = High(chanpwm(4))

Tcd1_ccabufL = Low(chanpwm(5))
Tcd1_ccabufH = High(chanpwm(5))

Tcd1_ccbbufL = Low(chanpwm(6))
Tcd1_ccbbufH = High(chanpwm(6))

Return
 
Hallo Natalius,

Dankeschön für dein Bascom Xmas-Present :)

Wenn ihr für euren Modellbau ein Windowsprogramm für Parameterübergabe, Darstellung von Reglerwerten o.ä. benötigt, könnte ich euch die Programmersoftware hier erweitern, ich muss dann nur wieder ein bisschen mehr Zeit haben. :rolleyes:

Noch einen schönen Sonntag,
Dirk
 
Hallo Dirk,

vielen Dank für Dein Angebot! Hätte ich mit Bezug auf http://www.rcgroups.com/forums/showthread.php?t=1092829 vor einem halben Jahr davon gehört, hätte man das glatt als Gemeinschaftprojekt angehen können! Aber die Entwicklung hört ja nicht auf - für den Xmega ist der existierende AR7212-Programmer zu klein, bei mehr als 12 Kanälen bietet es sich z.B. an grid controls statt listviews einzusetzen usw.

Vielleicht ein paar Informationen für diejenigen, die hier mitlesen (eigentlich passt das hier nicht ganz rein). In dem Projekt, das Dirk anspricht, geht es um einen per PC/Laptop programmierbaren 12-Kanal-RC-"Empfänger", der von einer preiswerten 7-Kanal-Funke (Spektrum DX7, 2.4 GHz) so betrieben wird, als ob man einen 12-Kanal-Sender in der Hand hätte. Möglich wird das durch Verlagerung von "Senderintelligenz = Mixer- und Servoeinstellungen" in den Empfänger. Das Konzept ist inzwischen mit einem größeren Elektrosegler (4m-Klasse) "lufterprobt", d.h. kein einziger Stör oder Ausfall innerhalb von 29 Flügen (insgesamt ca. 15 Stunden in der Luft) während der letzten Saison. Der Empfänger hat darüberhinaus Basis-Drohnenfunktionalität (Flugstabilisierung, GPS-Autopilot, 2nd Link und Telemetrie), die allerdings nur in Notsituationen eingesetzt werden soll. Jeder Modellflieger kennt das: Auf einmal isser weg. Vielleicht durch die Sonne geflogen, man ist geblendet, oder man hat sich kurz zu seinem Kollegen umgedreht, der lauthals "Störung" schreit. Wenn das Modell durch gute Thermik weit oben ist, hat man auf einmal ein Problem. Ab 500 Meter Höhe ist auch ein 4-Meter-Segler nur noch ein mehr oder minder strukturierter Fleck, und ihr könnt euch vorstellen, in welche Panik der Pilot gerät, wenn das Ding im Bereich 5-25kg wiegt. Nicht auszumalen, wenn ein aus Kevlar und Kohlefaser gebautes Modell beim Absturz einen Menschen trifft.. Ergo: Sinnvoll eingesetzte Drohnenintelligenz hilft der Flugsicherheit im Modellflug.

Was dem Modellflug weniger hilft ist etwas, was ich als RC-Kanalgesetz bezeichnen möchte. Kurz: Zahl das Doppelte für den Sender, wenn Du zwei Kanäle mehr haben willst. Einstiegsanlage mit 6 Kanälen: etwa 200 Euro, 8 Kanäle: 400 Euro. 10 Kanäle: 800 Euro. 12 Kanäle: 1600 Euro - dafür dann im Magnesiumgehäuse als Schmuckstück vor dem Bauch. Muß das sein? Selbst wenn man sein Geld als Schmuck verbrennen will - man muß auf diesen Schmuck auch noch warten! Das war - ganz grob - die Ausgangssituation für das "Speck Drum AR7212-Projekt".

Gruß

Natalius
 
Hallo Natalius,

:offtopic:
da sprichst Du mir aber voll aus der Seele. Ich hab zZ. auch zwei Heli-projekte
am Ruhen, weil das Problem teuere Funke einem in der Krise doppelt
weh tut.

Zitat:

Was dem Modellflug weniger hilft ist etwas, was ich als RC-Kanalgesetz bezeichnen möchte. Kurz: Zahl das Doppelte für den Sender, wenn Du zwei Kanäle mehr haben willst. Einstiegsanlage mit 6 Kanälen: etwa 200 Euro, 8 Kanäle: 400 Euro. 10 Kanäle: 800 Euro. 12 Kanäle: 1600 Euro - dafür dann im Magnesiumgehäuse als Schmuckstück vor dem Bauch. Muß das sein? Selbst wenn man sein Geld als Schmuck verbrennen will - man muß auf diesen Schmuck auch noch warten!

Auch von mir nen guten Rutsch ins Neue...
PS.: das mit der Kanalerweiterung find ich hochinteressant....



Grüßle
Wolfgang
 
Bascom 1.11.9.9 verfügbar

Die letzte "kleine" Revision von Bascom ist nun verfügbar:

Bzgl. X-mega support kommt in 1.11.9.9 hinzu:
- Xmega SPI support added. SPI for xmega also supports dynamic channels. The variable has to start with bSPI in that case:
Open "SPI,Master,mode0,clk2,msb" For Binary As #bspivar ' use a dynamic channel
Print #bspivar , W
Input #bspivar , W
Instead of a CONFIG, OPEN is used. Notice that you have to open
- Xmega dynamic UART channel added. When using a variable that begins with bUART, you can use a dynamic channel:
For Buart_channel = 0 To 7 'when using a variable, notice that the index is 0 based !
Print #buart_channel , "UART :" ; Buart_channel
waitms 1000
Next
The channel does not to be opened in this case.

Die vollständige Liste von Änderungen ist auf MCSelec im Bereich Registration/LIC/Download History einsehbar.

Natalius

Meine Application Notes bei MCSelec:
AN #171: Programmable 12-channel receiver for Spektrum DX7 radios.
AN #174: Kixlines - Tetrasexagesimal number compression to speed up serial communication.
AN #176: Mini matrix algebra.
AN #177: Kixrazor - Bascomer's Electronic Flight Information for Sparkfun's 9DOF Razor.
 

Über uns

  • Makerconnect ist ein Forum, welches wir ausschließlich für einen Gedankenaustausch und als Diskussionsplattform für Interessierte bereitstellen, welche sich privat, durch das Studium oder beruflich mit Mikrocontroller- und Kleinstrechnersystemen beschäftigen wollen oder müssen ;-)
  • Dirk
  • Du bist noch kein Mitglied in unserer freundlichen Community? Werde Teil von uns und registriere dich in unserem Forum.
  •  Registriere dich

User Menu

 Kaffeezeit

  • Wir arbeiten hart daran sicherzustellen, dass unser Forum permanent online und schnell erreichbar ist, unsere Forensoftware auf dem aktuellsten Stand ist und der Server regelmäßig gewartet wird. Auch die Themen Datensicherheit und Datenschutz sind uns wichtig und hier sind wir auch ständig aktiv. Alles in allem, sorgen wir uns darum, dass alles Drumherum stimmt :-)

    Dir gefällt das Forum und unsere Arbeit und du möchtest uns unterstützen? Unterstütze uns durch deine Premium-Mitgliedschaft!
    Wir freuen uns auch über eine Spende für unsere Kaffeekasse :-)
    Vielen Dank! :ciao:


     Spende uns! (Paypal)