Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Pitot and 3-axis Gravity transmition to a base station

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
hgrueneis

Bascom Member



Joined: 04 Apr 2009
Posts: 902
Location: A-4786 Brunnenthal

austria.gif
PostPosted: Mon Jan 17, 2022 4:09 pm    Post subject: Pitot and 3-axis Gravity transmition to a base station Reply with quote

For any one interested, I also have a Board that I would consider giving away for a minimal charge , or free.
Here is the code:
'FILE FOR PITOT TRANSMITTER SYSTEM
'COPYRIGHT © 2008-2022 HUBERT GRUENEIS
'Use only for Hobby, not Commercial use permitted!.
'SYSTEM TRANSMITS SPEED AND GRAVITY TO BASE MCU VIA UART AND WIRELESS MODULE IN TRANSPARENT MODE
'TRANSMITTER WIRELESS RS232,XBEE-PRO 2.4 GHZ. FCC ID:OUR-XBEEPRO
'57600 BAUD , WIRELESS SPEED
'Board Power is 3.3V! to be compatible to ATXMEGA.
'Gravity chip used is MMA7261QT
'Receiver was paired with transmitter. Any other wireless will work.
'******************************************************************************
$regfile = "m168def.dat" ' specify the used micro
$crystal = 14745600 ' used crystal frequency
$baud = 57600 ' baudrate for tx
$hwstack = 128
$swstack = 128
$framesize = 128
'*******************CONFIGURATION**********************************************
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Adc = Single , Prescaler = Auto , Reference = Avcc 'USE VCC REFERENCE INTERNALLY
'*******************SIMULATE YES/NO********************************************
'$sim
'*******************SET VARIABLES**************************************
Dim Vx As Word 'X-GRAVITY AD-VALUE
Dim Vy As Word 'Y-GRAVITY AD-VALUE
Dim Vz As Word 'Z-GRAVITY AD-VALUE OFFSET
Dim Offx As Word 'X-GRAVITY AD-VALUE OFFSET
Dim Offy As Word 'Y-GRAVITY AD-VALUE OFFSET
Dim Offz As Word
Dim X As Single 'X-GRAVITY
Dim Y As Single 'Y-GRAVITY
Dim Z As Single 'Z-GRAVITY
Dim Oldpdm As Word 'OLD DIFF. PRESSURE FOR AVERAGE
Dim Pdcalc As Word
Dim Pd As Single 'PRESSURE DIFFERENTIAL
Dim Pa As Single 'PRESSURE ABSOLUTE
Dim Ad As Single 'AIR DENSITY
Dim H As Word 'ADC VALUE FOR TEMPERATURE
Dim Co As Word 'CORRECTION VALUE FOR DIFF. PRESSURE
Dim N As Single 'TEMPERATURE IN DEG CELSIUS
Dim C As Single 'DISPLAY VALUE FOR TEMPERATURE IN DEG CELSIUS
Dim K As Single 'CONSTANT FOR KELVIN 273=0 DEG CELSIUS
Dim Vs As Single 'VELOCITY IS V2
Dim Mps As Single 'METERS PER SECOND
Dim Pam As Word 'ADC VALUE FOR PRESSURE ABSOLUTE
Dim Pdm As Word 'PRESSURE DIFFERENTIAL MEASURED
Dim Altitudeft As Single 'ACTUAL ALTITUDE IN FEET
Dim Altdat As Single 'ALTITUDE DATA CALCULATION
Dim Kmh As Single
Dim Mph As Single
Dim Inhg As Single
Dim Sendstrg As String * 16 'start with 0 kmh
Start Adc 'START ADC
Waitms 20 'WAIT FOR POWER TO SETTLE
Vx = Getadc(6) 'AND DO A DUMMY CONVERSION, CHANNEL DOES NOT MATTER
'Because of change in MCS.LIB to one sampling of ADC instaead of two samplings
Gosub Offsetadc 'DUMMY AND OFFSET READ FOR ADC (first read problem)
'
'*********+++++++++++++********** S T A R T M A I N P R O G R A M **********++++++++*****************************
Do
Gosub Calcspeed 'GET DATA and calculate
Gosub Senddat 'UNMARK FOR SIMULATION WITHOUT INTERRUPT FROM MAIN MCU
Loop
End 'IN CASE OF PROBLEM END IT HERE !!!! NO RESET WITHOUT POWER OUT
'************++++++++++++********** E N D M A I N P R O G R A M *************************************************
'------------------------START OF SUBROUTINES------------------------------------------
'************
Offsetadc:
Vx = Getadc(6) 'ADC OF X_GRAVITY
Vy = Getadc(7) 'ADC OF Y-GRAVITY
Vz = Getadc(0) 'ADC OF Z-GRAVITY
Offx = Vx
Offy = Vy
Offz = Vz
H = Getadc(1) 'ADC OF TEMP SNSOR
Oldpdm = Getadc(2) 'INITIAL AVERAGE VALUE FOR DIFF. PRESSURE READING
Pdm = Getadc(2) 'ADC OF DIFFERENTIAL PRESSURE
Pam = Getadc(3) 'ADC OF ABSOLUTE PRESSURE
Co = Pdm
Return
'******************************************************************************************************************
Calcspeed:
H = Getadc(1) 'temperature sensor read
N = H \ 3.1
N = N - 50
C = N
K = N + 273
Pam = Getadc(3) 'READ ABSOLUTE PRESSURE
Pam = Pam + 102 'OFFSET ADDED FOR DIFFERENCE TO 15 KPA
Pa = Pam * 1.0966
Inhg = Pa \ 10 'RESULT IS HPA
Inhg = 0.2953 * Inhg 'RESULT IS INHG
Ad = 2.87 * K
Ad = Pa \ Ad
Pdm = Getadc(2) 'READ DIFFERENTIAL PRESSURE
Pdm = Pdm + Oldpdm
Pdm = Pdm \ 2
Oldpdm = Pdm 'USE AS NEW OLDPDM AVERAGE
If Pdm > Co Then Pdcalc = Pdm - Co 'GET OFFSET DEDUCTED
If Pdm < Co Then Pdcalc = 0
Pdm = Pdm - Pdcalc
Pd = Pdcalc \ 102.3 '204.6 FOR 5VOLT OPERATION
Pd = Pd * 1.31
Pd = Pd * 1000 'IN N/m SQUARE
Vs = Pd \ Ad
Mps = Sqr(vs) 'SQUARE ROOT
Kmh = Mps * 3.6 'Meters Per Second Into Kmh
Mph = Kmh \ 1.6
Altdat = 1013 - Pa 'SUBTRACT ACTUAL ABSOLUTE PRESSURE FROM SEALEVEL (1013 hPA)
Altitudeft = Altdat * 30
Vx = Getadc(6) 'ADC OF X_GRAVITY
Vy = Getadc(7) 'ADC OF Y-GRAVITY
Vz = Getadc(0) 'ADC OF Z-GRAVITY
X = Vx - Offx
Y = Vy - Offy
Z = Vz - Offz 'DO NOT FORGET TO ADD ONE G TO Z-GRAVITY
Z = Z \ 37.2
Z = Z + 1
X = X \ 37.2 '37.2 BITS PER G
Y = Y \ 37.2
Return
'*************************
Senddat:
Sendstrg = Str(mph)
Print "S";
Printbin Sendstrg
Print " "
Waitms 5
Sendstrg = Str(x)
Print "C" ;
Printbin Sendstrg
Print " "
Waitms 5
Sendstrg = Str(y)
Print "D" ;
Printbin Sendstrg
Print " "
Waitms 5
Sendstrg = Str(z)
Print "E" ;
Printbin Sendstrg
Print " "
'
'**************************************************
'Print "S" ; "M=" ; Fusing(mph , "#.&") ; " " 'AIRSPEED STRING TO RECEIVER ,TRAILING SPACES MAKE SURE THAT RECEIVER GETS ALL DATA
'Waitms 1
'Print "B" ; "A=" ; Fusing(altitudeft , "#.&") ; " "
'Waitms 1
'If X >= 0 Then Print "C" ; "X+" ; Fusing(x , "#.&") ; " " Else Print "C" ; "X" ; Fusing(x , "#.&") ; " "
'Waitms 1
'If Y >= 0 Then Print "D" ; "Y+" ; Fusing(y , "#.&") ; " " Else Print "D" ; "Y" ; Fusing(y , "#.&") ; " "
'Waitms 1
'If Z >= 0 Then Print "E" ; "Z+" ; Fusing(z , "#.&") ; " " Else Print "E" ; "Z" ; Fusing(z , "#.&") ; " "
'GRAVITY STRING TO RECEIVER
Waitms 284 'wait is for the receiver display to have enough time to recover 'SEND APPROX. EVERY 300 MILLISECONDS
Return
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum