View previous topic :: View next topic |
Author |
Message |
mcmsat
Joined: 25 May 2018 Posts: 51 Location: Nigeria
|
PIC16F1827 Voltage Level Indicator |
Posted: Fri May 25, 2018 4:19 am |
|
|
Hello all!
I am new in Microcontroller code writing. I have tested this code and it is working as proposed but a great counts of error is noticed while the circuit is simulating.
The error is:
[PIC16 ADC] PC=0x001C. PORTA<0> is not configured as an analog input. [U2]
[PIC16 ADC] PC=0x001C. PORTA<1> is not configured as an analog input. [U2]
[PIC16 ADC] PC=0x001C. PORTA<2> is not configured as an analog input. [U2]
[PIC16 ADC] PC=0x001C. PORTA<3> is not configured as an analog input. [U2]
[PIC16 ADC] PC=0x001C. PORTA<4> is not configured as an analog input. [U2]
The error repeats like this up to 10,177 Times?
Though all the functions of the circuit are working but I am not comfortable with these errors! I understand the error but please can someone tell me how to configure PORT A as input?
My CCS C code is:
Code: |
//Voltage Level Indicator
#include <16f1827.h>
#device adc=10
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO,PUT,NOPROTECT,BROWNOUT,NOMCLR,NOCPD
long ad;
float ANALOG;
void GetADC(int channel)
{
set_adc_channel(channel); // Set A/D channel
delay_us(20); // Delay acquisition time
ad = read_adc(); // Read A/D channel into ad variable
ANALOG = (float)ad * (5.0/1024); // Convert 10-bit reading
}
void init() // Hardware initialization
{
setup_adc(ADC_CLOCK_DIV_8); // A/D clock/8 @4MHz,Tad=2uS
}
void main()
{
init(); // Configure peripherals/hardware
while(1) // Continuous loop
{
GetADC(0);
if (ANALOG <= 0.40)
{
output_low(PIN_B0);
}
if (ANALOG >= 0.47)
output_high(PIN_B0);
GetADC(1);
if (ANALOG <= 0.77)
{
output_low(PIN_B1);
}
if (ANALOG >= 0.84)
output_high(PIN_B1);
GetADC(2);
if (ANALOG <= 1.06)
{
output_low(PIN_B2);
}
if (ANALOG >= 1.13)
output_high(PIN_B2);
GetADC(3);
if (ANALOG <= 1.72)
{
output_low(PIN_B3);
}
if (ANALOG >= 1.80)
output_high(PIN_B3);
GetADC(4);
if (ANALOG <= 2.17)
{
output_low(PIN_B4);
}
if (ANALOG >= 2.24)
output_high(PIN_B4);
}
} |
_________________ All is well even in the well! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Fri May 25, 2018 5:51 am |
|
|
You are not setting the input multiplexer to make the pins available as analog inputs....
Code: |
void init() // Hardware initialization
{
setup_adc(ADC_CLOCK_DIV_8); // A/D clock/8 @4MHz,Tad=2uS
setup_adc_ports(sAN1 | sAN2 | sAN3 | sAN4);
}
|
On the PIC, you have to connect the pins you intend to use as analog to the analog multiplexer, and then select from these. You are doing the selection, without first connecting them..... |
|
|
mcmsat
Joined: 25 May 2018 Posts: 51 Location: Nigeria
|
|
Posted: Fri May 25, 2018 6:21 am |
|
|
Thanks. I will modify the code. I hope this will solve this error. _________________ All is well even in the well! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Fri May 25, 2018 6:23 am |
|
|
Actually you need sAN0 as well. I was posting with part of the code visible and thought you only selected channels 1 to 4... |
|
|
mcmsat
Joined: 25 May 2018 Posts: 51 Location: Nigeria
|
|
Posted: Fri May 25, 2018 6:49 am |
|
|
@ Ttelmah, I thanked you for your help.
I did that you told me the rest of the errors disappeared remaining
"PORTA..."
I included sAN0 at the beginning it failed to build then I added it to the end and it is solved completely.
You people are making the World a better place for all. I love that.
void init() // Hardware initialization
{
setup_adc(ADC_CLOCK_DIV_8); // A/D clock/8 @4MHz,Tad=2uS
setup_adc_ports(sAN1 | sAN2 | sAN3 | sAN4);
}
I added sAN0 at the end of the line
Code: |
void init() // Hardware initialization
{
setup_adc(ADC_CLOCK_DIV_8); // A/D clock/8 @4MHz,Tad=2uS
setup_adc_ports(sAN1 | sAN2 | sAN3 | sAN4 | sAN0);
} |
Thanks so much. _________________ All is well even in the well! |
|
|
|