View previous topic :: View next topic |
Author |
Message |
kazama
Joined: 01 Sep 2009 Posts: 10 Location: Malaysia
|
ADC Interrupt |
Posted: Sun Nov 15, 2009 5:46 am |
|
|
Hello, i have a question. i am doing obstacle robot project that use 3 sensor. I found that if 1 sensor sense the obstacle, the other sensors voltage value is not stable (both sensor will have a same value, even i try put the obstacle at the 2nd sensor). I think i should use interrupt. Am i right? and how to do it? i never try the ADC interrupt. I will post the sensor code if needed.
thanks |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Nov 15, 2009 12:18 pm |
|
|
It doesn't sound like interrupts or not is your problem...
Keep in mind, there's a small delay time between sampling one channel and another. (read the datasheet for the PIC in the ADC section carefully)
Tacq is your min required time based on input source impedance (and operating temp).
Are you analog sensors buffered with an op-amp?
You'll want to post your code (a short example) with your PIC and compiler version.
A diagram of your setup would be helpful too. (not a block if discrete parts are involved..)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
kazama
Joined: 01 Sep 2009 Posts: 10 Location: Malaysia
|
|
Posted: Sun Nov 15, 2009 5:57 pm |
|
|
Here are my code for the sensors
Code: | void adc(void)
{
while(true)
{
set_adc_channel(0);
delay_us(5);
val1=read_adc();
while (TXIF == 0);
TXREG = printf("Front=%LX ", val1);
delay_ms(500);
set_adc_channel(1);
delay_us(5);
val2=read_adc();
while (TXIF == 0);
TXREG = printf("Left=%LX ", val2);
delay_ms(500);
set_adc_channel(2);
delay_us(5);
val3=read_adc();
while (TXIF == 0);
TXREG = printf("Right=%LX ", val3);
delay_ms(500);
}
} |
Also i upload some results from the hyperterminal. This is the sensor value when a sensor found an obstacle
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Nov 15, 2009 6:04 pm |
|
|
Can you post the whole code please?
Also, how is the sensor hooked to the PIC? What is the source impedance of the sensor? are you using buffer op-amps?
And, you post a screen shot of what the sensor shows while in front of a wall, but what is it SUPPOSED to show? (if what it's showing isn't correct/expected)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 15, 2009 6:10 pm |
|
|
Quote: | TXREG = printf("Front=%LX ", val1); |
Download the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look at the section on printf, on page 199 (page 211 in the Acrobat reader).
What is returned by the printf() function, according to the manual ?
Answer:
Quote: |
printf( )
Syntax: printf (string)
Parameters: String is a constant string or an array of characters null terminated.
Returns: undefined
|
Quote: | while (TXIF == 0); |
Make a little test program for printf() in CCS, and compile it.
What does printf() do, whenever it sends a character to the UART ?
Answer:
Quote: |
......... #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
0020: BTFSS PIR1.TXIF
0022: BRA 0020
0024: MOVWF TXREG
0026: GOTO 0052 (RETURN)
|
Test program:
Code: |
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//======================================
void main(void)
{
printf("Hello World");
while(1);
} |
|
|
|
|