View previous topic :: View next topic |
Author |
Message |
blackdragon
Joined: 24 May 2010 Posts: 10
|
pic18f4550 and mpx4250, getting pressure |
Posted: Thu May 27, 2010 2:29 pm |
|
|
Hi folks,
Now, I'm trying pressure sensor read in the ISIS, so I found some information about pressure logic such as digital/analog converter etc.
So, I've just used read_adc() functions and a few settings as below;
:::: settings ::::
Code: |
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
set_adc_channel(0);
|
::::: read sensor value :::
Code: |
pressure = read_adc();
|
However sensor value and pressure value haven't match. Also, I read sensor's datasheet and I found transfer function as below:
Nominal Transfer Value: Vout = VS x (0.00369 x P + 0.04)
± (Pressure Error x Temp. Factor x 0.00369 x VS)
VS = 5.1 ± 0.25 Vdc
After all, may I making something wrong/missing, how can I read exactly seeing in sensor value ?
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 27, 2010 3:01 pm |
|
|
Post your test program. (Complete). |
|
|
blackdragon
Joined: 24 May 2010 Posts: 10
|
|
Posted: Fri May 28, 2010 12:17 pm |
|
|
PCM programmer wrote: | Post your test program. (Complete). |
my source as below;
Code: |
#include <18F4550.h>
#FUSES NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NOMCLR
#use delay(clock=4000000)
#define use_portb_lcd True
#include <lcd.c>
void main(void)
{
float temperature;
int16 value;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
lcd_init();
while(TRUE)
{
value = read_adc();
printf(lcd_putc,"\fPressure:%lu", value);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 28, 2010 12:44 pm |
|
|
I was expecting to see some math equations in the code.
But here are some comments:
1. The compiler is using 8-bit mode for the A/D converter. The numbers
returned by read_adc() will be from 0 to 255 in 8-bit mode. If you want
to use 10-bit mode, with the result from 0 to 1023, then you need to
add the line shown in bold below:
Quote: |
#include <18F4550.h>
#device adc=10
#fuses ...
|
2. You don't have an oscillator setting in the #fuses statement, but
maybe Proteus doesn't care. But if it did care, you could use INTRC_IO.
3. The oscillator clock of ADC_CLOCK_INTERNAL is not the best.
For a 4 MHz oscillator, the correct value is ADC_CLOCK_DIV_4, but
maybe Proteus doesn't care. |
|
|
blackdragon
Joined: 24 May 2010 Posts: 10
|
|
Posted: Fri May 28, 2010 2:03 pm |
|
|
PCM programmer wrote: | I was expecting to see some math equations in the code.
|
Actually I'm not sure about math equations but I'll investigate for more clarification.
Thanks for another comments..
cheers |
|
|
|