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

Share your working BASCOM-AVR code here : Moving average for INTEGER and SINGLE data streams : REPLY

$
0
0
thanks for sharing Per. Very useful.

Share your working BASCOM-AVR code here : Matrix math routines : REPLY

$
0
0
hi Per, Thanks for sharing your matrix code. I know you put a lot of time in it.

BASCOM-AVR Old versions : " dxDockErrorPane " problem. : REPLY

$
0
0
کرک معتبر برای فایلتون پیدا کنین

BASCOM-AVR Old versions : " dxDockErrorPane " problem. : REPLY

$
0
0
Many thanks for this funny answers jp :lol:

Share your working BASCOM-AVR code here : Moving average for INTEGER and SINGLE data streams : REPLY

$
0
0
Hi again Meister Having read your post about "Boxcar integrators" I understand your interest for fast avearging . ;) It is kind of an exotic instrument, but once yo need it, well .. then you cannot escape the math. Did you succeed in building your boxcar integrator in the end? Your project was a good example of why we sometimes need small and simple but very fast math routines and averaging is really used everywhere. [b:c6340faaf2]I would really encourage our friends here in this forum who are good att assembly to port my RUNAVG routine into assembly code. It could run considerably faster if we shaved off unnecessary basic calls.[/b:c6340faaf2] It is probably a very simple task for those who are familiar with AVR assembly. I could probably fix it myself, but have tried to stay out of this area. A blacksmith should stay a blacksmith. Not pretending to be a juweler. :) /Per

BASCOM-8051 : sw SPI - how to read MCP3004 : REPLY

$
0
0
Nobody :cry: Does Shiftout and Shiftin in Bascom supports multiple variables to be accessed? Something like in Basic Stamp SHIFTOUT MOSI, SCLK, MSBFIRST, [var18,var28,var38].. :idea:

Share your working BASCOM-AVR code here : BME280 sensor : NEWTOPIC

$
0
0
BME280 is a combined digital humidity, pressure and temperature sensor. Attached library for I2C mode, but it can be easy adapted for SPI. [URL=http://radikal.ru/fp/3caa6015df234ee682fab7adb349b79c][img:390701309c]http://s013.radikal.ru/i324/1512/ed/902ebf51118ft.jpg[/img:390701309c][/URL][URL=http://radikal.ru/fp/de82e8cd7be34b048720b7dc4a838c12][img:390701309c]http://s006.radikal.ru/i214/1512/63/1002f4dd5b03t.jpg[/img:390701309c][/URL]

Share your working BASCOM-AVR code here : Moving average for INTEGER and SINGLE data streams : REPLY

$
0
0
Per, yes, the boxcar integrator works. But rather than making use of tricks to speed up the program, it is based on using the Xmega with its Event and DMA capabilities and its high clock frequency (it runs at 48MHz) - oh yes, but there is a trick: MWS in the German forum wrote a function that sums one array onto another one, element for element [url]http://bascom-forum.de/showthread.php?3322-Beispiel-custom-mem-byte-copy-in-Assembler[/url] If you would have to do the summation for some thousands of elements by a for loop you would be lost.. Useful also in this respect are some array functions provided by Galahat (Summing a partial array): [url]http://bascom-forum.de/showthread.php?5596-Summe-eines-Array-Teils-bilden/page2[/url] Also, it would be nice if Mark could pretty up the Max and Min functions by adding a parameter for the number of elements to search through. Galahat provided assembler code earlier: [url]http://bascom-forum.de/showthread.php?5250-Zweierkomplement&highlight=Get_min_sint_16[/url] These are a collection of array functions potentially useful to somebody, and maybe someone could put 'em into a library (I never did so). Best regards, Meister

Share your working BASCOM-AVR code here : Use of the MCS I2C Slave Library : REPLY

$
0
0
Alan, why do you initiate a write cycle, if you are not going to write anything? like this: ' I2cstart I2cwbyte &H40 I2cstop ' Also, you do not need the case statement if you read high and low, the byte count would take care of that. If an array is used with the byte count, then you can consecutively read as many bytes as predetermined in one session. Best regards Hubert

BASCOM-AVR Old versions : " dxDockErrorPane " problem. : REPLY

$
0
0
that was in persian language duval JP :P :P

BASCOM-AVR : SIM800L GPRS GSM Module : REPLY

$
0
0
Hello toto aliexpress http://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20151215162225&SearchText=SIM800L+GPRS

Share your working BASCOM-AVR code here : BME280 sensor : REPLY

$
0
0
Mrshilov, Thanks for the Lib. Is very nice have all this sensors in one unique module. Paulo

Share your working BASCOM-AVR code here : Moving average for INTEGER and SINGLE data streams : REPLY

$
0
0
Thank-you Per for posting the code for calculating Moving Averages for Singles. The example below shows a 3-point Moving Average over 20 data points. Several observations: 1. It seems as if the algorithm does not reach the anticipated data average of 1.5 - even though it was intended to calculate a 3-point MA. 2. It seems as if the algorithm calculates the 'actual' MA for the Nth value and it is only available at the N+1 position; ie the MA that includes the current value is not available until the next calculation. Would very much like to receive your feedback. E [code:1:7bac965bcb]$regfile = "m1280def.dat" 'Type of AVR-processor $crystal = 16.000e6 'Use "_XTAL" to read this value from program $hwstack = 128 $swstack = 128 $framesize = 128 $baud = 9600 $sim Dim Sum As Single ' Sum Dim Runavg_sing As Single ' Average Dim X As Single Dim Factor As Byte Dim I As Byte Factor = 3 Restore Sampledata For I = 1 To 20 Read X 'Function Runavg_sing(byval Newval As Single , Sum As Single , Byval Factor As Byte ) As Single 'Running Average for any SINGLE variable 'X is the new value to add to the statistics (preserved) 'SUM is an accumulator 'FACTOR is the averaging factor. 'RUNAVG_SING is a return variable (the arithmehic mean of all values in Accum, divided by FACTOR) 'Moving average Runavg_sing = Sum Shift Runavg_sing , Right , Factor , Signed 'compute data average from accumulated values Sum = Sum - Runavg_sing 'subtract the old average Sum = Sum + X 'add the new value Print I ; " " ; Fusing(x , "###.##") ; " " ; Fusing(runavg_sing , "####.####") Next End Sampledata: Data 2! , 1! , 2! , 1! , 2! , 1! , 2! , 1! , 2! , 1! , 2! , 1! , 2! , 1! , 2! , 1! , 2! , 1! , 2! , 1! [/code:1:7bac965bcb] [quote:7bac965bcb]1 2.00 0.0000 2 1.00 0.2500 3 2.00 0.3438 4 1.00 0.5508 5 2.00 0.6069 6 1.00 0.7811 7 2.00 0.8084 8 1.00 0.9574 9 2.00 0.9627 10 1.00 1.0924 11 2.00 1.0808 12 1.00 1.1957 13 2.00 1.1713 14 1.00 1.2748 15 2.00 1.2405 16 1.00 1.3354 17 2.00 1.2935 18 1.00 1.3818 19 2.00 1.3341 20 1.00 1.4173[/quote:7bac965bcb]

BASCOM-AVR : ADC Measurement : NEWTOPIC

$
0
0
Hi, This is my first post here so please be gentle guys.. :wink: I found a simple microcontroller based solar charger here: http://blog.amateurworld.in/archives/36 The software is written with BASCOM-AVR, I can understand most of the code (with the help of comments) but having trouble with the ADC portion.. CODE BELOW: [code:1:fa387868f4]'MICRO-CONTROLLER BASED SOLAR CHARGE CONTROLLER 'USED CHIP: ATMEGA8L WITH INTERNAL RC OSCILLATOR '*************************************************************** ' INITIAL SETTINGS '*************************************************************** $regfile = "m8def.dat" 'REGISTER FILE FOR ATMEGA8 $crystal = 1000000 'OSCILLATOR FRQUENCY=1MHZ $swstack = 40 'SOFT STACK SIZE $hwstack = 32 'HARDWARE STACK SIZE $framesize = 32 'FRAME SIZE '*************************************************************** ' DEFINE INPUT/OUTPUT PORTS '************************************************************** Config Portd.2 = Output Config Portd.3 = Output Config Portb.1 = Output Config Portb.2 = Output Config Portb.3 = Output '************************************************************** ' DEFINE ALIAS FOR GOOD READEBILITY '************************************************************** Charging Alias Portd.3 _load Alias Portd.2 Ch_led Alias Portb.3 Bat_h_led Alias Portb.1 Bat_l_led Alias Portb.2 '*************************************************************** ' SETUP ADC MODULE '*************************************************************** Config Adc = Single , Prescaler = Auto , Reference = Avcc '_2.56_nocap Start Adc '*************************************************************** ' VARIABLE DECLARATIONS '*************************************************************** Dim W As Word , W_single As Single Dim Sol_v As Single , B_high As Single Dim Bat_v As Single , B_low As Single Dim Gp1 As Byte , Gp2 As Byte '*************************************************************** ' MAIN PROGRAM LOOP '*************************************************************** Main: Gosub Check_adc If Bat_v < B_high And Sol_v > Bat_v Then Charging = 1 'CHARGING ON Ch_led = 0 'CHARGING LED ON Bat_h_led = 1 'BAT HIGH LED OFF _load = 0 'LOAD OFF End If If Bat_v >= B_high Then Charging = 0 'CHARGING STOPS Ch_led = 1 'CHARGING LED OFF Bat_h_led = 0 'BAT HIGH LED ON Bat_l_led = 1 'BAT LOW LED OFF Else Bat_h_led = 1 'BAT HIGH LED OFF End If If Sol_v < Bat_v Then Charging = 0 'CHARGING STOPS Ch_led = 1 'CHARGING LED OFF _load = 1 'LOAD ON End If If Bat_v <= B_low Then _load = 0 'LOAD OFF Bat_l_led = 0 'BAT LOW LED ON Else Bat_l_led = 1 'BAT LOW LED OFF End If Goto Main '*************************************************************** ' ADC MEASUREMENT SUB RUTINE '*************************************************************** Check_adc: For Gp1 = 2 To 5 W_single = 0 For Gp2 = 1 To 200 W = Getadc(gp1) W_single = W_single + W Next Gp2 If W_single <> 0 Then W_single = W_single / 200 Else W_single = 0 End If Select Case Gp1 Case 2 : Sol_v = W_single Case 3 : B_high = W_single Case 4 : B_low = W_single Case 5 : Bat_v = W_single Case Else End Select Next Gp1 Return '**************************************************************** End 'end program [/code:1:fa387868f4] Can somebody help me with the ADC portion.. TIA [b:fa387868f4][color=red:fa387868f4](BASCOM-AVR version : 2.0.7.8 )[/b:fa387868f4][/color:fa387868f4]

BASCOM-AVR : ADC Measurement : REPLY

$
0
0
Hallo, OK I'll try and help you a bit:- [code:1:66a0598c6d]Check_adc: For Gp1 = 2 To 5 'Loop through Gp1 (2-5) This is the ADC number we'll read later W_single = 0 'Setup an accumulator For Gp2 = 1 To 200 'Read the ADC 200 times in this loop W = Getadc(gp1) 'Actually read the ADC Value W_single = W_single + W 'Add to the accumulator Next Gp2 ' If W_single <> 0 Then 'If the total of all ADC values read for this ADC is > 0 then W_single = W_single / 200 'Divide by 200 (The number of times we read the ADC). This will give us an average Else W_single = 0 End If Select Case Gp1 'Where should the average value for the ADC just read be stored? Case 2 : Sol_v = W_single 'Save value from ADC 2 to Sol_v Case 3 : B_high = W_single 'Save value from ADC 3 to B_High Case 4 : B_low = W_single 'Save value from ADC 4 to B_low Case 5 : Bat_v = W_single 'Save value from ADC 5 to Bat_v Case Else End Select Next Gp1 Return [/code:1:66a0598c6d] Not the most beautiful code I've seen, but if it works why not. Regards Ian Dobson

BASCOM-AVR : ADC Measurement : REPLY

$
0
0
Thank you so much Ian! It's clear to me now. I tried compiling the code and simulating it in Proteus but it's not working.. I wonder if how will I know the correct fusebit to use if I'll breadboard this circuit? Thanks again..

BASCOM-AVR : ADC Measurement : REPLY

$
0
0
You should only need to set the correct crystal (Internal 1MHz RC). Just to see if your CPU is running at the correct frequency, just toggle a pin every 1 second, attach an LED to the pin and see if it flashes at the correct frequency. [code:1:e3ebb1bdc7]do toggle PORTD.3 WAIT 1 loop[/code:1:e3ebb1bdc7] Regards Ian Dobson

BASCOM-AVR Old versions : ADC Measurement : REPLY

$
0
0
Hi, It flashes every second as expected.. :P

BASCOM-AVR Old versions : ADC Measurement : REPLY

$
0
0
Hello, You can run the code in the Bascom simulator, I've just run it here and it seems to work. Try running on real Hardware. Regards Ian Dobson

BASCOM-AVR : SIM800L GPRS GSM Module : REPLY

Viewing all 20563 articles
Browse latest View live


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