I just tested Darrel's oversampling, using the MPX4115a and a PIC12F675 that I quickly soldered up, and it works very well. I just used the two capacitors on the power side of the MPX4115a, like the data sheet shows, but with no filter capacitor on the output. Even at 16 bit resolution, the A/D output values only varied by +/- 1 digit. It varied more when I breathed though! 16 bit is really sensitive!
My vote is for oversampling, parts count is at 6, running the board from the power of the PicKit2.
Pic12f675
3 capacitors
mpx4115a
20 mhz resonator
http://www.scalerobotics.com
Hi, Scalerobotics
Could you tell us what it shows for some close to another calibrated pressures ( water column i.e.) I'm really curious about this "oversampling method" application ...
And moreover after having carefully read the relevant AN 1152 from Microchip ...
Alain
" Surely overpaid Engineer ... ( lol ) , but Graduate Engineer ... "
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
@Acetronics
VERY good infos in AN thanks for sharing!
@ Scalerobotics
You have done excellent job That was exactly I was thinking to do trying oversampling on 12f pics! so you did the job for me THANKS!
So the conclusion is that we can use 12f675 ir 12f683 as I want to just measure an alt difference of 200m
I did some calculation and I have attaches 2 XL one is the previous 10,12,14bit calculation and bolded out the 200m measurements just to see what is going on and the second one is use pic 10bit ADC but with Dual AMP LMC662 (Acetronics suggestion) to give a narrow-window measurements and the resolution improved to about 4m .
Also attached a fast schematic of my thoughts (not checked , improvements are welcome!)
Final conclusion I take the amp route or MPX connected directly to pic (with oversampling). I think as I will only want to measure 200m difference. the pcb must/and can be kept simple (low weight) and low part count.
(dual amp trick: first subtracts 2.5V from MPX vout and the result is multiplied by 3 , so we have a range just from
0-2300meters but better resolution for 10bit pic adc -see AZAltitude10bit_DUALAMP.xls)
Scalerobotics about oversampling on 12f do you think you can 'go with' just the internal 8Mhz rc oscilator or it will not do the trick?!
Last edited by bitmaniac; - 4th June 2009 at 12:03.
bitmaniac, Check your J1 and J2 power wiring....
Dave Purola,
N8NTA
You can go with the internal, but at least on the 12F675 you have 4mhz internal, so your conversions are a little slower. See the TAD vs device operating frequencies part of your schematic. 1.6 us if fastest. Looks like 4mhz would be 2.0 us. So as long as you are not using 16 bit, you probably won't notice the difference in speed, and you will save one more part in your part count.
http://www.scalerobotics.com
@scalerobotics
I have import your code to Proteus Sim and playing around with your code.
It seems to work ok (I have to use meters instead of feets here).
My MPX4115A arrived yesterday (4pieces) so it is time to make the real thing and figure out how it works. I am going to use my schematic ommiting the opamp and hope oversampling method works (12f683,internal 8Mhz,MPX,3caps -> total part count 5!)
For the moment I put everythimg in SIM (i used 12f683 with internal 8Mhz) and here what I found:
According to simulation at 50.400kPa I read 17646 feet ALT (lower limit) and
at 99.900kPa I read 5 feet ALT (upper limit) that is with this code we measure aprox. 49,500Kpa difference. (two screenshots attached)
Note: We must also use calibration data and/or Level0 default presure
(Please note that in the sim I can only vary sensor kPa in .100 increaments)
Last edited by bitmaniac; - 5th June 2009 at 09:22.
Sounds good. If you beat me to it, try it with and without C3. I am guessing it may work better without it. If not without, it may work best with a much smaller capacitor. That defies most filtering logic, but I think oversampling likes a little bit of noise. I can't find my 470pf, but I know they are around here somewhere.....
Last edited by ScaleRobotics; - 5th June 2009 at 09:36.
http://www.scalerobotics.com
At my location and 14 bits, I get an output of 13255. This calculates to a pressure of 1004.86 mBar, and an altitude of 229.85 feet. I don't have a barometer here, so I can't really give you a side by side comparison on the figures. On the internet, it said a nearby weather barometer read 1014.42. But I think this is more a function of the accuracy of the MPX4115a, and to a bigger extent (since I don't have a calibrated barometer side by side) my altitude. The altitude from my calculations seem very close. I think I am between 250 and 285 feet altitude.
Oversampling is really just a form of averaging. So it can't skew your results. At worst, you could have no noise in your A/D conversion, which would give you a 10 bit result with lots of useless bits to the right. Once I find a 470pf capacitor around here, I plan to test results again. I think this will filter the result a bit too much, and take away some of the needed noise. Here, white noise is our friend.
On a side note, at 16 bits, when you watch the results at first power up, you can really see the effects of the MPX4115a and maybe the PIC12F675 warming up. For about two minutes the values really move!
Last edited by ScaleRobotics; - 4th June 2009 at 18:36.
http://www.scalerobotics.com
Here's a little code to calculate altitude from 0 to about 17,000 feet. I could not quite fit the full 85 value lookup2 table without getting some errors, so it is more of a 74 value lookup table. I may try a 74 value lookup table that covers the range to 36,000 feet later. Also will not work for Death Valley where the altitude goes to negative.
It is a pretty short program. I am using about 900 words of the PIC12F675 though, so not much space left over. Have not tested it too much, so if anyone finds issues, let me know.
Code:DEFINE OSC 20 INCLUDE "DT_Analog.pbp" ; DT's 16-bit Analog Module DEFINE ADC_BITS 10 '10 BIT A/D CONVERSION RESULT DEFINE ADC_CLOCK 2 ' DEFINE ADC_SAMPLEUS 5 'SET SAMPLE TIME IN MICROSECONDS CMCON = 7 'TURN COMPARATORS OFF TRISIO = %000100 'Set GSIO 0 INPUTS, others to OUTPUT ANSEL = %00100100 ' ADCON0.7 = 1 'Right Justify for 10-bit ADCON0 = %10001001 ADbits = 14 ; set to 14-bit resolution DEFINE DEBUG_REG GPIO DEFINE DEBUG_BIT 0 DEFINE DEBUGIN_BIT 1 DEFINE DEBUG_BAUD 2400 DEFINE DEBUG_MODE 0 ALTresult var word 'lookup table output tempALT var word 'base altitude of lookup from table ADtemp var byte 'lookup table input ALTdifference var word 'difference of two nearby altitudes finalALT var word 'final calculated altitude in feet ;--------------------------------------------------------------------------- Main: ADchan = 2 ; Do only AN2 channel GOSUB GetADC ; Get A/D value ADtemp = (ADvalue/100) - 60 ' get to table acceptable value for lookup gosub lookmeup tempALT = ALTresult 'save first result for use in math ADtemp = ADtemp - 1 'run another lookup for nearby altitude for diff calc gosub lookmeup ALTdifference = ALTresult - tempALT 'get difference in nearby alt finalALT = tempalt - (((ADvalue//100)* ALTdifference)/100) 'use difference to calculate slope & adjust altitude accordingly debug "Alt= ",DEC finalALT," A/D= ",DEC ADvalue," " pause 1000 GOTO Main: End lookmeup: lookup2 ADtemp,[_ 17646,17327,17011,16699,16389,16083,15780,15480,15183,14888,14597,14308,14022,_ 13739,13458,13179,12903,12630,12359,12090,11823,11559,11297,11037,10779,10524,_ 10270,10018,9769,9521,9275,9031,8789,8549,8310,8074,7838,7605,7373,7143,6915,_ 6688,6463,6239,6017,5796,5577,5359,5143,4928,4715,4502,4292,4082,3874,3667,_ 3462,3257,3054,2852,2652,2452,2254,2057,1861,1666,1472,1280,1088,898,708,520,_ 332,146],ALTresult return
Last edited by ScaleRobotics; - 5th June 2009 at 00:33.
http://www.scalerobotics.com
I don't see the problem with dividing by 1024?
The process is quantising a variable. Say our variable voltage lies in the range 0 to 10 Volts and we have one bit to use for the digital result of the quantising (2 to the power of 1 = 2, so we have two levels to play with):
A. The result 0 means that the voltage was in the range 0 to 5 Volts (not that it was zero).
B. The result 1 means the voltage was in the range 5 to 10 volts (not that it was 10 volts)
So each level is 10/2 volts wide. Not 10/1 volt wide.
The bit of cake after carving it up into portions has a slice 0 - it is not any smaller than any other slice.
This is not jibberish created by highly paid engineers it is simple maths.
I wonder how many devices you have launched on the world that are happily 'over' measuring analog quantities by assuming that each slice is bigger than it actualy is?
Kind regards to you all
Bill Legge
Hi,
The problem is very simple : the servo signal frame length is too long ( or too short ??? ) and the ESC do not recognise it as a valid frame ...
The solution is not so simple : the total time of the frame must be 30 or 35 ms as a MAXIMUM and , say 17-18 ms as a minimum.
That's why servo works and not the ESC ...
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Sure there is a timing (delay) problem.
You gave a more sophisticating explanation.
You gave me an idea.May be we I will hook the oscilloscope to see the exact pulse..
Hi Alexandros
I had committed that from what you wrote ...
...Code:'**************************************************************************** ' (c)2009 Alexandros Zahariadis (E.A.TH.) Greece * ' Electric Glider electronic switch to be used in F3J-GR competitions. ' The device will cut-off motor if 200m ALT reached or 30seconds passed ' whichever comes first! ' There is also a status led option which idicates if you have reached 200m ' or not (may be because of luck of power!) ' steady led -> 200m ALT reached , blinking led -> 30 secs passed. ' NOTE: after a lot of experiments and because of code execution speed ' I use direct ADC raw sample values without converting them to meters first! ' :: thanks to Acetronics (Alain) and picbasic forum for codding ideas :: '**************************************************************************** '@ DEVICE FCMEN_OFF '@ DEVICE IESO_OFF '@ DEVICE BOD_ON '@ DEVICE CPD_OFF '@ DEVICE PROTECT_OFF '@ DEVICE MCLR_OFF '@ DEVICE PWRT_OFF '@ DEVICE WDT_OFF '@ DEVICE INTRC_OSC @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _BOD_ON INCLUDE "modedefs.bas" clear DEFINE OSC 4 define PULSIN_MAX 250 ;DEFINE DEBUG_REG GPIO ;DEFINE DEBUG_BIT 2 ;DEFINE DEBUG_BAUD 9600 ;DEFINE DEBUG_MODE 1 OSCCON = $60 ' $60:4 Mhz $70:8 Mhz int. CMCON0 = 7 'TURN COMPARATORS OFF TRISIO = %00001010 'Set GPIO1 and GPIO3 0 INPUTS, others to OUTPUT ANSEL = %00000100 'Set AN2 , Fosc/32 ADCON0 = %00000000 'AN2 select & Right Justify for 10-bit ;--------------------------------------------------------------------------- THROTTLE VAR GPIO.0 'Outputs to throttle servo RADIO VAR GPIO.1 'Input from receiver LED var GPIO.2 'status indicator ADC_DATA var GPIO.3 ' adc serial data ADC_SCLK var GPIO.5 ' adc serial clock ADC_CS var GPIO.4 ' adc chip select ;--------------------------------------------------------------------------- advalue var word ' value read from adc groundALT var word difalt var word P VAR WORD ' This stores the PULSIN value x var byte ' general var y var byte ' general var SEC_COUNT VAR BYTE ' seconds counter O_FLOWS VAR BYTE ' holds the number of timer1 overflows BRAKE_PULSE var word ' servo pulse to STOP (brake on) THR servo BRAKE_PULSE = 100 '-= vars for averaging routine =- AvgCount CON 6 ' = Number of samples to average FAspread CON 1000 ' = Fast Average threshold +/- Value VAR WORD '-= end of vars for averaging routine =- '****************************************************************************** ' TIMER1 Cycle MUST be longer than a R/C frame duration to be sure not to miss any ticks. ' 50 ms is a good value for timing precision. ' PL = 15543 @ 4Mhz ( reload = 7 cycle ) '****************************************************************************** T1LO CON $49 'timer1 preload values T1HI CON $C3 '$C349 -> -15543 low throttle INTCON = 0 ' disable interrupts T1CON = %00010000 ' 1:2 prescale (1uS per tick), timer1 off (max 1:8!) ' 11 = 1:8 ,10 = 1:4, 01 = 1:2, 00 = 1:1 Prescale Value TMR1H = T1HI ' 65,536-15536 = 50.000 TMR1L = T1LO ' 50.000 ticks * 1uS =50.000usec.=100msec ' 1 second= 100*10 ' every 10 timer1 overflows = 1 second 1uS= '--------------------------------------------------------------------------- pause 3000 for x=1 to 4 high led pause 200 low led pause 100 next x '****************************************************************************** CAL_BP: ' CALIBRATING Brake_Pulse ( P ) '****************************************************************************** Pause 50 LOW led P = 0 For x = 1 TO 16 PulsIn radio,1,P IF ( P < 80 ) OR ( P > 220 ) Then Led = 1 GoTo CAL_BP EndIF IF P = $00 Then prems IF ( P < (Brake_Pulse -1)) OR ( P > (Brake_Pulse +1)) THEN Led = 1 GoTo CAL_BP ENDIF prems: Brake_Pulse = P Next x LOW Throttle ''****************************************************************************** 'calibrate: 'check for valid signal ' 'For x = 1 TO 2 ' ' PulsIn radio,1,P ' pauseus 10 ' IF ( P < 80 ) OR ( P > 200 ) Then calibrate ' next x ' 'for x=1 to 3 ' PulsIn radio,1,P ' brake_pulse = P 'next x ' 'low led ' 'low throttle '***************************************************************************** precheck: 'leave some seconds to do a motor test 'then motor brake is ON for some seconds for y=1 to 3 for x=1 to 255 PULSIN RADIO,1,P IF ( P < 80 ) OR ( P > 220 ) Then Led = 1 GoTo Precheck EndIF Led = 0 LOW Throttle pULSOUT THROTTLE, p next x next y for x=1 to 160 LOW Throttle PULSOUT THROTTLE, brake_pulse pause 18 next x low THROTTLE GOSUB GetAdc 'Get ground ALT groundalt=value '****************************************************************************** armcheck: ' Now, we can launch the beast ... PULSIN RADIO,1,P IF ( P < 80 ) OR ( P > 220 ) Then Led = 1 ' Show Problem !!! LOW Throttle GoTo Armcheck ENDIF Led = 0 low throttle PULSOUT THROTTLE, p if difalt < 2 OR difalt > 10000 then Armcheck 'Arm if>=5mALT (in adc samples) reached!! '****************************************************************************** '****************************************************************************** start: ' We are flying , now ... preset timer1 SEC_COUNT=28 ' load for 30 to 0 seconds countdown O_FLOWS=0 ' clear overflow count PIR1.0=0 ' clear timer1 overflow flag T1CON.0=1 ' start timer1 low throttle ' to be sure ... '****************************************************************************** main: gosub GetADC PULSIN RADIO,1,P pauseUS 10 pULSOUT THROTTLE, p ' Note: Timer1 overflows every 0.050 seconds IF PIR1.0 THEN ' if timer1 overflow then O_FLOWS = O_FLOWS + 1 ' inc oveflow counter IF O_FLOWS = 20 THEN ' if 1 second elapsed SEC_COUNT = SEC_COUNT - 1 ' decrement seconds count O_FLOWS=0 ' reset overflow counter ENDIF PIR1.0=0 ' clear timer1 overflow flag T1CON.0 = 0 ' stop timer1 TMR1H = T1HI ' Reload values TMR1L = T1LO T1CON.0=1 ' re-start timer1 ENDIF if difalt>=89 and difalt<10000 then KILL_MOTOR_ALT 'Check if 100mALT '(in adc samples) reached!! if sec_count<=0 then KILL_MOTOR_TMR goto main ' SUBROUTINES '****************************************************************************** '****************************************************************************** GetADC: 'Read MAX187 12bit ADC value low ADC_CS PAUSEUS 10 shiftin ADC_DATA,ADC_SCLK,msbpost,[advalue\12] high ADC_CS Average:' -=-=-=-=-=-= Average 6 X Analog values -=-=-=-=-=-=-=-=-=-= IF Value = advalue Then NoChange IF ABS (Value - advalue) > FAspread OR Value < AvgCount Then FastAvg IF ABS (Value - advalue) < AvgCount Then RealClose advalue = advalue - (advalue/AvgCount) advalue = advalue + (Value/AvgCount) GoTo AVGok FastAvg: advalue = Value GoTo AVGok RealClose:'If averaging more than 8 samples,change to (AvgCount/4) advalue = advalue - (advalue/(AvgCount/2)) advalue = advalue + (Value/(AvgCount/2)) AVGok: Value = advalue ' Put Average back into Value NoChange:' -=-=-=-=-=-= End of Averageing -=-=-=-=-=-=-=-=-=-= difalt=value-groundalt return END '****************************************************************************** KILL_MOTOR_ALT: low throttle high led LOOP1: PULSOUT throttle, brake_pulse ; Kill motor - adjust this value. 4Mhz ->> 10uSec pause 18 goto LOOP1 END '****************************************************************************** KILL_MOTOR_TMR: x = 0 LOOP2: low throttle PULSOUT throttle, brake_pulse ; Kill motor - adjust this value. 4Mhz ->> 10uSec IF X = 0 THEN led = led ^ 1 x = ( x+1 ) // 18 ' Counter for led Blinking @ 1.5 Hz pause 18 goto LOOP2 END '****************************************************************************** '******************************************************************************
But did not try it ...
have fun
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Hey Bitmaniac,
You could try using a 20ms interrupt, and start your pulsout on interrupt. That would make things more consistent, and probably keep your motor controller happy.
Hey Bitmaniac,
I was thinking this use of interrupts would probably keep things happy as far as motor controllers. It may need some more work though, and I still have to test it on a motor control.
http://www.picbasic.co.uk/forum/show...3834#post83834
Walter
Bookmarks