|
|
View previous topic :: View next topic |
Author |
Message |
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
16F88 input(), LDR and ultrasonic |
Posted: Fri Aug 08, 2008 7:54 pm |
|
|
input():
I'm trying to use input(..) command, thing is..I can use it, but when the pin I'm trying to read is disconnected, it reads random values. I think this is affecting my ADC too, I try to use read_adc() but it always read like 2.20V or so when the pin is disconnected, I can only get a fixed value when I use a POT on it. But when I try to use an audio source for example it always have that 2.20V messing with it.
In input() if I connect PIN_B0/we to GND it reads 0, VDD=1, but when the pin is disconnected it should read 0, and it reads like 01001110/we :P
Code: | #include <16F88.h>
#device adc=10
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, NOMCLR, NOLVP, NOPROTECT
#use delay(clock=4000000)
#include "flex_lcd.c"
void main()
{
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports(sAN0);
set_adc_channel( 0 ); // AN0
lcd_init();
while(1)
{
printf(lcd_putc, "\fINPUT: %i", input(PIN_B0));
delay_ms(100);
}
} |
ldr:
In a normal ADC I can read, well, at least notice differences with audio sources POTs etc, but I can't notice any difference with a LDR, does anyone know why? :/
I tried to use a transistor (BC548) but nothing, my ADC always shows the same voltage, there's no difference :/
ultrasonic:
I got from an old robot 2 pairs of ultrasonic receivers and transmitters, thing is, I know which are transmitter and receiver, VCC and GND pins, but I don't know which frequency they work with (37khz?, 40khz?), how can I "know" it, they don't have any kind of reference ?
Also, I use Proteus to check the frequency I'm producing, its not always 37000, or 40000 it doesn't have to be like that right ? It can be 37100 or whatever right ?
Also, anyone that has experience with ultrasonic "things" in the receiver I only have to use read_adc() make some calculations and I have the distance right ?
Does the transmitter have to be connected to an amplifier or something ?
Well thats all for now :P
Thank you all ;) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 09, 2008 4:48 pm |
|
|
Quote: | I can use it, but when the pin I'm trying to read is disconnected, it reads random values. |
That's completely normal. If you want to hold an unused input pin at
some logic level (high or low), then you must put a pull-up or a pull-down
resistor on the pin. Try it. For the 16F88, you can turn on the Port B
pull-ups with this CCS function:
Code: | port_b_pullups(TRUE); |
Put that line of code near the start of main(). Then run your program.
Pin B0 should now read as a logic "1" level.
If you have questions about your LDR and ultrasonic devices, then post
the manufacturer and part number of each device. |
|
|
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
|
Posted: Sat Aug 09, 2008 5:26 pm |
|
|
Thanks...
Well, can that pullup thing be configured only for some pins? Im using a LCD (PORTB)+ADC(PORTA) will that be affected if I use the pullup? (Sorry for asking instead of testing, but I cant test it right now).
As for the LDR/ultrasonic...They are not indetified with nothing, no number, no reference :/
EDIT:
Tested, theres no interference with the LCD, but why cant I use port_a_pullups? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 09, 2008 6:46 pm |
|
|
Download and read the data sheet for the 16F88.
http://ww1.microchip.com/downloads/en/DeviceDoc/30487c.pdf
Look in the section on I/O Ports. If the PIC has the option to
enable/disable internal pull-ups on a port, it will tell you in that section.
Read the sections on Port A and on Port B. |
|
|
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
|
Posted: Sat Aug 09, 2008 7:46 pm |
|
|
Ok, checked, only PORTB has pull-ups :/ this means I cant get a fixed ADC :/ ill try some other ways.. |
|
|
Guest
|
|
Posted: Sat Aug 09, 2008 7:54 pm |
|
|
PORTB has _internal_ pullup resistors, PORTA does not. That doesnt mean you can't put your own pull up resistors on PORTA. |
|
|
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
|
Posted: Sat Aug 09, 2008 9:05 pm |
|
|
Well I do it but it keeps the same :/.
Can you show me a schematic on how to connect a resistor so I can have a stable ADC?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 10, 2008 12:13 pm |
|
|
Here is a schematic of a 47K pull-down resistor on pin AN0:
Code: |
|-------|
| PIC |
| |
| |
ADC >--------|AN0 |
signal | | |
| | |
| |-------|
|
|
---/\/\/\/---|
47K |
|
-----
---
- |
|
|
|
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
|
Posted: Sun Aug 10, 2008 12:34 pm |
|
|
Thanks, I was connecting a 470k resistor :/ lol
It worked, thank you all ;) |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|