Quantcast
Channel: MCS Electronics Forum
Viewing all 20587 articles
Browse latest View live

BASCOM-AVR : UTF-8 to ASCII in a string : REPLY

$
0
0
if you want the clean ASCII, you only need to check the MS bit. If it is 1, skip, if it is 0, it is plain ASCII and keep it. then make a simple loop : [code:1:314b5671c2]z="" 'clear return string for j=1 to len(s) b=asc(s,J) 'get byte if b.7=0 then 'normal ASCII z=z+chr(b) 'add to return string end if next [/code:1:314b5671c2] now z contains the plain ascii code.

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
Thanks guys. The typo for microseconds was indeed a mistake, but it was not my only oversight. Mark was correct about needing to add config statements. The documentation has it in an easy to find place. This worked as a minimum version, blinking once per second: $regfile = "xm32A4Udef.dat" $crystal = 2000000 $hwstack = 64 $swstack = 40 $framesize = 40 Config Sysclock = 2MHZ Config Porte.1 = Output Do toggle porte.1 Waitms 500 Loop End ... It just won't run without Config Sysclock. Including a Config Osc statement before the Config Sysclock statement can be used to stop the other oscillators, and it would save a bit of current, like this: Config Osc = Enabled , 32mhzosc = DISABLED , EXTOSC = DISABLED I have not yet measured to see how much current this would save. I am really impressed with the Mattairtech breakout board. It is a very handy product.

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
Wow, something else is going on, then. For the Xmega32E5 the following Blink an LED program works just fine. It omits the Config SysClock statement entirely. All Xmegas start up running on the 2 MHz Internal RC Osc. So, in theory, if one doesn't need to change the clock source or frequency, one shouldn't need to use the Config Osc or the Config SysClock commands. They set a number of internal registers, but the default power on register settings should be fine. I find it interesting that the two different Xmegas respond differently in this regard. JC [code:1:ee9d5d280c] 'File: X32E5 Test Clock V2.bas 'Xmega32E5 Program 'Bascom Jay Carter Feb 2017 'This project is to Flash an LED and to see if the Config SysClock statement 'is needed in the program or not. 'The Xmegas all start up at 2 MHz, so if one doesn't need to change the clock 'does one still need the statement? --> NO, at least not for the Xmega32E5. 'Hardware: 'Currently set up for my "Blue" Xmega32E5 PCB. 'PortD.1 = LED1 Red LED 'This program runs fine, it does flash the LED without using the Bascom 'Config SysClock or Config Osc instructions. '------------------------------------------------------------------------------- $regfile = "xm32E5def.dat" 'Micro in use $crystal = 2000000 'Micro's Clock: 2 MHz $hwstack = 64 'Hardware stack $swstack = 64 'Software stack $framesize = 64 'Frame space 'Config I/O Pin for LED for Output Mode: 'LED is on PortD.1 High = On Portd_pin1ctrl = &B00000000 'PortD.1 Control Totem Pole Output Portd_dir.1 = 1 'PortD.1 = Output Main: Do Toggle Portd.1 Flash The Led Waitms 250 Loop [/code:1:ee9d5d280c]

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
[quote:8db2380303]I find it interesting that the two different Xmegas respond differently in this regard. [/quote:8db2380303] Within XMEGA there are different series. Most have small differences. E series can not be compared to the others. You can not compare them. Only within a series. Part of the config code is to wait for the oscillator stable bit(s). without it, it seems that the xmega will not run or become in some odd state.

BASCOM-AVR : clock cycles per instruction? : REPLY

$
0
0
Hi JP I will put a code snippet for Sine-generation under "share your working AVR code" in a moment. Take care Per

Share your working BASCOM-AVR code here : Generate Triangle and Sine wave from double intergration : NEWTOPIC

$
0
0
If you want to generate a sinewave, a very simple way is to doubleintegrate a constant. Integration is the same as accumulation in the digital domain so all you need is to DIM two variables acting as accumulators. The first integration generates a triangle wave and the second a sine. The sine phase will lag the triangle by 90 degrees. In the case below, 256 loops are needed for one sine period, but you can experiment with other lengths depending of how finegrained curve you want (Forget about the figures in the Picture. They belong to Another application. I just wanted to illustrate the principle) /Per ------------------------------------------------------------------------------------------------------------------------------------------ Dim Ramp_direction As Integer Dim Ramp_value As Integer Dim Sine_value As Long Dim Triangle_value as long do Ramp_value = Ramp_value + Ramp_direction Sine_value = Sine_value + Ramp_value Select Case Ramp_value '256 accumulations per period Case 127 : Ramp_direction = -1 Sine_value = 0 'Slope down Case -127 : Ramp_direction = 1 Sine_value = 0 'Slope up End Select Triangle_value = Ramp_value * 64 'Make Triangle ampliude equal to Sine waitus 39 'Frequency wiil be approx 1kHz (256*39us = 1ms) loop

Share your working BASCOM-AVR code here : Generate Triangle and Sine wave from double intergration : REPLY

$
0
0
Gode formatting got mangled. Attaching file instead. /Per

BASCOM-AVR : UTF-8 to ASCII in a string : REPLY

$
0
0
Hi, The "normal ASCII" did not work for me on lcd [quote:cfc6438908]was : THOR GÖRANS - FREDAG I KÖPENHAMN got : THOR GRANS - FREDAG I KPENHAMN[/quote:cfc6438908] but you'r code was simple, so i change it and now it runs fine for me [quote:cfc6438908]THOR GÖRANS - FREDAG I KÖPENHAMN THOR GÖRANS - FREDAG I KÖPENHAMN[/quote:cfc6438908] [code:1:cfc6438908]Dim S As String * 60 Dim Z As String * 60 Dim J As Byte , B As Byte , A As Byte ' THOR GÖRANS - FREDAG I KÖPENHAMN <****> Chr(195) + Chr(150) = hex C3 96 Ö S = "THOR G" + Chr(195) + Chr(150) + "RANS - FREDAG I K" + Chr(195) + Chr(150) + "PENHAMN" Do Print S ' Thor Gã–rans - Fredag I Kã–penhamn Z = "" 'clear return string For J = 1 To Len(s) B = Asc(s , J) 'get byte If B >= 194 And B <= 195 Then 'utf-8 ASCII J = J + 1 'incr j for next char A = Asc(s , J) 'get next char Shift B , Left , 6 ' shift it left by 6 B = B Mod &HFF A = A Mod &HFF B = B Or A 'or utf-8 with next char Z = Z + Chr(b) 'add to return string Else Z = Z + Chr(b) 'add to return string End If Next S = Z 'Thor Görans - Fredag I Köpenhamn Loop[/code:1:cfc6438908]

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
I like being able to choose oscillators, and manage power usage. Hey, I just noticed something weird. When I try switching the ATXMEGA32A4U over to run with the external crystal 16 MHz oscillator, it doesn't work. I tried this: $regfile = "xm32A4Udef.dat" $crystal = 16000000 $hwstack = 64 $swstack = 40 $framesize = 40 Config Osc = DISABLED , 32mhzosc = DISABLED , EXTOSC = ENABLED Config Sysclock = EXTERNAL , Prescalea = 1 , Prescalebc = 1_1 Config Porte.1 = Output Do toggle porte.1 Waitms 500 Loop End ... I suppose I should break out my scope, and see whether the little crystal is actually ticking.

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
When I compiled and programmed the BASCOM-AVR code that I believe should have enabled the external oscillator, the oscilloscope showed no activity on the crystal. The code must not be activating the crystal oscillator properly. Again, I know how to enable an external oscillator using C, so I tried that. When running the C program, with the crystal oscillator enabled, the oscilloscope showed a healthy 16 MHz waveform on the crystal terminals. When I burned in a BASCOM-AVR code version, there was nothing. The BASCOM-AVR examples for the xmega use the internal 32MHz oscillator, so I don't see what I am missing by reading the examples. The statements to activate the external oscillator seem to be fairly simple in the documentation. Has anyone had experience using BASCOM-AVR to enable an external oscillator for this chip? Is it supported?

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
you might want to try the 2080 version (download the full setup). or when using 2078 : enable the internal osc: Config Osc = ENABLED , 32mhzosc = DISABLED , EXTOSC = ENABLED if i remember correct, there was a problem in 2078 when the internal osc was not enabled.

BASCOM-AVR : UTF-8 to ASCII in a string : REPLY

$
0
0
aha, i see. you want to have the other chars. well you could do a lookup and replace them. and when not in the table, use a ?

Share your working BASCOM-AVR code here : Library for Nokia1616 display : REPLY

BASCOM-AVR : UTF-8 to ASCII in a string : REPLY

$
0
0
hi, The Nextion HMI lcd i have added ISO 8859-15 so all chars are working with this code

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
Here are a few more Xmega Clock setup routines. Some use the Bascom instructions, some just directly set the internal registers. Clock Option 5 demonstrates reading the Clock status bit, the others just insert a short delay for the clock to stabilize, and assume it is ready... Several of these were written for the original X128A, (no longer available), and have more recently been used on the Xmega E5 series. They may be helpful to you. If I recall correctly, also, some (all?) Xmega's have a upper limit on the frequency of an external Xtal. For some of them 16 MHz is out of spec! The issue is that the internal oscillator circuitry is optimized for a lower frequency Xtal, e.g. 4 MHz, and one is expected to use the PLL to get the higher operating frequency clocks. Interesting that I noted that Clock Option 7 failed at 48 MHz. I've run the XmegaE5 at 48 MHz for several, (non-commercial), projects where I needed a faster clock. I didn't take the time to track down why that particular setup didn't work. JC [code:1:b197e15ea8] Clockopt1: 'Set up the Xmega clock. 'Run on Internal 32 MHz Osc at 32 MHz Works. 'Xmega runs at 2MHz on power up. 'Leave 2 MHz Osc enabled, and enable the Int 32MHz Clock Config Osc = Enabled , 32mhzosc = Enabled 'Wait a bit to allow clocks to start up and stabilize. 'Note: Haven't yet switched to 32MHz, are at 2MHz, so Waitms 1 = 16 mSec Waitms 4 'Wait 64mSec 'Next configure the systemclock: Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 Waitms 100 'Startup Stabilization Delay Return Clockopt2: 'Set up the Xmega clock. Works 'Run on Internal 2 MHz Osc at 2 MHz. Works. 'Xmega runs at 2MHz on power up. 'Leave 2 MHz Osc enabled Config Osc = Enabled 'Wait a bit to allow clocks to start up and stabilize. 'Note: Haven't yet switched to 32MHz, are at 2MHz, so Waitms 1 = 16 mSec Waitms 4 'Wait 64mSec 'Next configure the systemclock: Config Sysclock = 2mhz , Prescalea = 1 , Prescalebc = 1_1 Waitms 100 'Startup Stabilization Delay Return Clockopt3: 'Set up the Xmega clock. Works. 'Run on Internal 2 MHz Osc at 0.5 MHz. Works. 'Xmega runs at 2MHz on power up. 'Leave 2 MHz Osc enabled Config Osc = Enabled 'Wait a bit to allow clocks to start up and stabilize. 'Note: Haven't yet switched to 32MHz, are at 2MHz, so Waitms 1 = 16 mSec Waitms 4 'Wait 64mSec 'Next configure the systemclock: Config Sysclock = 2mhz , Prescalea = 4 , Prescalebc = 1_1 Waitms 100 'Startup Stabilization Delay Return Clockopt4: 'Set up the Xmega clock. Works. 'Run on Internal 2 MHz Osc, at 32 MHz, via the PLL. 'This MANUALLY turns on the Xmega PLL. 'I don't have a reference for how to do this, this is my attempt... It Works! 'Xmega runs at 2MHz on power up. Osc_ctrl = 15 'All Osc ON, PLL Off Clk_psctrl = 0 'No PreScaler in use Osc_xoscctrl = 195 '12-16MHz, 256 Clks Osc_pllctrl = 16 'PLL: Int 2 MHz Osc x 16 Waitms 1 Osc_ctrl = 31 'PLL ON, All Osc Sources On Waitms 1 Cpu_ccp = 216 'Config Change Protection Clk_ctrl = 4 'Use PLL as Clock Source Return Clockopt5: 'Set up the Xmega Clock. Works. 'Run at 32 MHz from the Internal 32 MHz Osc, set by my code. 'Xmega runs on Int 2MHz Osc on Startup. 'This turns on the Int 32 MHz Osc, awaits it being ready, and switches to it. 'Don't forget the Configuration Change Register Protection Trigger before 'changing the uC's Clock Source. 'First turn ON the 32 MHz Int Osc: 'Then wait until the Int 32 MHz Osc is ready to be used. Osc_ctrl = 2 'Int 32 MHz Osc ON Rvbit = 0 'Clear flag While Rvbit = 0 'Read the Int 32 MHz Osc Status Regdata = Osc_status 'Status of all Int Osc Sources Rvbit = Regdata.1 'Int 32 MHz Osc Status, 1 = Ready Wend Cpu_ccp = 216 'Config Change Protection Clk_ctrl = 1 'Use Int 32 MHz Osc Return Clockopt6: 'Set up the Xmega clock. Works. 'Run on External Xtal, (16 MHz), at 32 MHz, via the PLL x2. 'This MANUALLY turns on the Xmega PLL. 'Xmega runs at 2MHz on power up. Osc_xoscctrl = 203 'Ext Osc: 12-16MHz, 16 K Clks Osc_ctrl = 9 'PLL Off, Ext Xtal On, Int 2M OSC On Clk_psctrl = 0 'No PreScaler in use Osc_pllctrl = 194 'PLL: Ext Xtal 16 MHz, Multi x2 Waitms 1 Osc_ctrl = 31 'PLL ON, All Osc Sources On Waitms 1 Cpu_ccp = 216 'Config Change Protection Clk_ctrl = 4 'Use PLL as Clock Source Return Clockopt7: '>>>>>> Fails <<<<<<< 'Try Overclocking for Logic Analyzer sampling. 48 MHz !!! 'Set up the Xmega clock. 'Run on External Xtal, (16 MHz), at 32 MHz, via the PLL 3. 'This MANUALLY turns on the Xmega PLL. 'Xmega runs at 2MHz on power up. Osc_xoscctrl = 203 'Ext Osc: 12-16MHz, 16 K Clks Osc_ctrl = 9 'PLL Off, Ext Xtal On, Int 2M OSC On Clk_psctrl = 0 'No PreScaler in use Osc_pllctrl = 195 'PLL: Ext Xtal 16 MHz, Multi x3 Waitms 2 Osc_ctrl = 31 'PLL ON, All Osc Sources On Waitms 2 Cpu_ccp = 216 'Config Change Protection Clk_ctrl = 4 'Use PLL as Clock Source Return Clockopt8: '>>>>>> WORKS <<<<<<< 50 MHz Xmega !!!!! 'But must switch FROM a mode which does NOT have the PLL active at the time. 'Can't change the PLL when it is in use. 'Try Overclocking for Logic Analyzer Sampling. 'Xmega Max Spec is 32 MHz. 'Incrementally Incr PLL using 2 MHz Int Osc. 'PLL = x16 = 32 MHz = Baseline, in spec. 'Set up the Xmega clock. 'Run on Internal 2 MHz Osc, at 32 MHz, via the PLL. 'This MANUALLY turns on the Xmega PLL. 'Xmega runs at 2MHz on power up. Osc_ctrl = 15 'All Osc ON, PLL Off Clk_psctrl = 0 'No PreScaler in use Osc_xoscctrl = 195 '12-16MHz, 256 Clks Osc_pllctrl = 25 'PLL: Int 2 MHz Osc x 25 !!! Waitms 2 Osc_ctrl = 31 'PLL ON, All Osc Sources On Waitms 2 Cpu_ccp = 216 'Config Change Protection Clk_ctrl = 4 'Use PLL as Clock Source Return [/code:1:b197e15ea8]

Share your working BASCOM-AVR code here : Generate Triangle and Sine wave from double intergration : REPLY

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
Yikes. I did not specify a range or a startup time for the external oscillator. I will go back and try that next. When in doubt, read the docs.

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
Success. As far as I can see, this gives us a working 32 MHz clock that is precisely controlled by a 16 MHz external crystal: [code:1:55a74403a4]$regfile = "xm32A4Udef.dat" $crystal = 32000000 $hwstack = 64 $swstack = 40 $framesize = 40 Config OSC = Disabled, _ EXTOSC = Enabled, _ PLLOSC = Enabled, _ RANGE = 12MHZ_16MHZ, _ STARTUP = XTAL_16KCLK, _ PLLSOURCE = Extclock, _ PLLMUL = 2 Config Sysclock = Pll Config Porte.1 = Output Do toggle porte.1 Waitms 500 Loop End [/code:1:55a74403a4] ... It was a difficult PLL to swallow, but it was better than drinking the Kool-Aid. ~Bill

BASCOM-AVR : ATXMEGA does not blink : REPLY

$
0
0
So, the external crystal can drive the PLL, and the PLL can drive the processor. I wonder whether it would be possible to run the chip directly from the external crystal without using the PLL. Has anyone made this work with an XMEGA? If I read the chip's data sheet(s) deeply enough, a better insight could come, so I will try that, but I am hoping someone has already investigated it. Here's a related thought: An external 16 MHz crystal provides exact timing, but it consumes a great deal more current to provide that accuracy. In battery powered applications, I could attach a lower frequency crystal at 32 KHz. Use that crystal to get a calibration factor for the internal oscillator. Then, stop the 32 KHz oscillator, and use the calibrated RC oscillator at 2 MHz, which should be a fast enough system clock for most applications. Monitor temperature. If it changes, go fetch an updated calibration factor. This could provide a good combination of speed, accuracy, and low power consumption. ~Bill

Share your working BASCOM-AVR code here : Generate Triangle and Sine wave from double intergration : REPLY

$
0
0
Thanks for sharing Per. Indeed nice and simple :D
Viewing all 20587 articles
Browse latest View live


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