|
|
View previous topic :: View next topic |
Author |
Message |
PrinceNai
Joined: 31 Oct 2016 Posts: 471 Location: Montenegro
|
MPLAB SIM error |
Posted: Fri Jun 17, 2022 9:57 am |
|
|
Hi all,
I've been toying with MPLAB SIM in MPLAB 8.92 using the code for Olympic averaging of A/D signal with 18f46k22. No matter which analog input I choose, I get this warning:
ADC-W0012: Selected channel 0 is an invalid channel. What is MPLAB trying to tell with this? Which channel would be valid?
I hardly ever use a simulator and imaginary stimulus, this is from curiosity only. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 17, 2022 10:30 am |
|
|
Post a short test program that compiles.
Post your compiler version.
Post details on how you are doing the stimulus.
Confirm that you have 18F46K22 selected in MPLAB's Configure menu. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 471 Location: Montenegro
|
|
Posted: Fri Jun 17, 2022 10:43 am |
|
|
main:
Code: |
#include <main.h>
int16 MyADC = 0;
#INT_TIMER0
void TIMER0_isr(void)
{
}
// *********************************************
// olympic++ adc de-noising routine for 10 or 12 bit ADC values
// NOTE: you must have selected the desired ADC channel before calling
// reads 16x , sorts and tosses low4 && high 4 readings
// then averages the middle 8
unsigned int16 adchlx(void){ // read 16 - sort, keep middle 8 average
unsigned int8 i; unsigned int16 accum=0;
unsigned int16 s, b[16]; int1 didswap=1;
for ( i = 0 ; i < 16; i++ ) {
b[i]= read_adc(); // ADC set for 10 or 12 bits
delay_us(8);
} // end of for loop for multi sample
while(didswap){ // bubble sort
didswap=0;
for (i=0; i<15; i++){ // i 0-15
if(b[(i)]>b[(i+1)]){ // if low element greater than next -do swap
s=b[i]; // hold upper
b[i]=b[(1+i)];
b[(1+i)]=s;
didswap=1;
} // ~if
} // ~for
} // ~while
// now sort and keep middle 8 values
for (i=4; i<12; i++){ accum +=b[i]; }
return(accum>>3);
}
// *********************************************
void main()
{
setup_adc(ADC_CLOCK_INTERNAL); //
setup_adc_ports(sAN0);
set_adc_channel(0); //read from channel 0
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(TRUE)
{
MyADC = adchlx();
delay_cycles(1);
delay_ms(500);
}
}
|
h:
Code: |
#include <18F46K22.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#device ICD=TRUE
#use delay(internal=32000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,errors)
|
Device in MPLAB is ok, but I saw yellow circle regarding the ability to simulate this chip. As for the stimulus I tried two variants, simply setting AN0 to "high" and also some file I found on the net.
The code breaks here: b[i]= read_adc(); // ADC set for 10 or 12 bits
Code: |
NOT CCS!!!!
# process to continuously inject 0 to 5 V on AN0 in 0.1 V increments every 1 ms
process InjectADCPin is
begin
loop
AN0 <= 0 mv;
loop
wait for 1 ms;
AN0 <= AN0 + 100 mv;
if AN0 > 5000 mv then
exit loop;
end if;
end loop;
end loop;
|
The code compiles without any warning, version 5.104. MPLAB SIM throws that back. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 17, 2022 11:37 am |
|
|
I made a very small test program and got the same ADC-W0012 error.
Then I changed the PIC to 18F4620 and it didn't show that error.
So it's the yellow dot on MPLAB SIM. There isn't full support for 18F46K22.
As a work-around, I suggest you substitute a constant for the stimulus file.
ie., don't use stimulus. Example:
Quote: | #include <18F46K22.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#device ICD=TRUE
#use delay(internal=32000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,errors)
int16 MyADC = 0;
#define ADC_VALUE 1023 // *** FOR TESTING ***
|
and
Quote: |
unsigned int16 adchlx(void){ // read 16 - sort, keep middle 8 average
unsigned int8 i; unsigned int16 accum=0;
unsigned int16 s, b[16]; int1 didswap=1;
for ( i = 0 ; i < 16; i++ ) {
b[i]= ADC_VALUE; // *** FOR TESTING ***
delay_us(8);
} // end of for loop for multi sample
while(didswap){ // bubble sort
didswap=0;
for (i=0; i<15; i++){ // i 0-15
if(b[(i)]>b[(i+1)]){ // if low element greater than next -do swap
s=b[i]; // hold upper
b[i]=b[(1+i)];
b[(1+i)]=s;
didswap=1;
} // ~if
} // ~for
} // ~while
// now sort and keep middle 8 values
for (i=4; i<12; i++){ accum +=b[i]; }
return(accum>>3);
} |
|
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 471 Location: Montenegro
|
|
Posted: Fri Jun 17, 2022 2:29 pm |
|
|
Thanks a lot for the answers.
Regards,
Samo |
|
|
|
|
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
|