Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
You can leave them floating and I did put the wrong setting for ADCON1 set it 0 I should of seen that You don't want tad at 0 that doesn't give any time to charge and take a reading
Yep if do that first you wouldn't be here asking for help. I been using a chip that you set the register to "1" on every pin and posted it wrong
What I was meaning is it's better to use binary for your setting so you can see what bits are set
And you can set tad to fast so if your having problems lower it.
And never think you can't do somthing wrong nine times out of ten you did and most of them is with how you hooked up your hardware.
Well I have tried everything suggested, (changing TAD, osc speed etc) and also new PIC's . Still can't get the inputs to stop sinking my input voltage though.
Can you guys look at the code again, and tell me your thoughts, is it possibly that I am doing the ADCON 0 result, TRISA and ADCON 1 settings in the wrong order?
to reiterate, I have input voltages of 0-5v on AN 0 to AN8
here is "main.c" code
#include "main.h"
#pragma config OSC = IRCIO67
#pragma config WDT = OFF
//enables the PGM/PGC/PGD pins
#pragma config LVP = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config PBADEN = OFF
WORD ADCread(BYTE source)
{
WORD result = 0;
ADCON0 = source << 2;
ADCON0 = ADCON0 | 0x03; //enable A/D convert
while((ADCON0&0x02)!= 0x00);
result = ADRESH;
result = result<<8;
result = result | ADRESL;
ADCON0 = 0;
return result;
}
void ADCinit()
{
//enable most a/d pins and make the voltage reference based on the power pins to the PIC
ADCON1=0x06;
//right justified results
//use a sampling rate of oscilator/32
//us 2 T_ad
ADCON2=0b10101010;
}
void main (void)
{
int read_vals = 0;
int lit = 1;
WORD result;
initMCU();
initMCU_OLED();
oledinit();
ADCinit();
LED = 0;
draw = 1;
AD7QUADRATIC_C)+AD7LOWERVAL;
//v_5 is going to be SWR, but it was forward voltage
v_9 = (v_6 + v_7)/(v_6 - v_7);
result = ADCread(8);
v_8 = result/1024.0;
v_8 = (AD8UPPERVAL-AD8LOWERVAL) * (v_8*v_8*AD8QUADRATIC_A + v_8*AD8QUADRATIC_B +
Looking at the data sheetfor the PIC18F4682, on page 131, it says:
10.1 PORTA, TRISA and LATA Registers
PORTA is an 8-bit wide, bidirectional port. The
corresponding data direction register is TRISA. Setting
a TRISA bit (= 1) will make the corresponding PORTA
pin an input (i.e., put the corresponding output driver in
a high-impedance mode). Clearing a TRISA bit (= 0)
will make the corresponding PORTA pin an output (i.e.,
put the contents of the output latch on the selected pin).
Reading the PORTA register reads the status of the
pins, whereas writing to it, will write to the port latch.
The Data Latch register (LATA) is also memory
mapped. Read-modify-write operations on the LATA
register read and write the latched output value for
PORTA.
Looking at examples for simpler PICs there is a specific PORT command = 0 to set the port to an input.
Does the datasheet imply that you only have to set a TRISA to 1 to automatically set the PORTA bit to 0 and the same for the LATA register?
As I said, my inputs still seem to 'look' like outputs (i.e. sink the input voltage to zero) so something is wrong in my configuring of the AD inputs, but I can't work out what it is!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.