|
|
View previous topic :: View next topic |
Author |
Message |
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
Input pin 16F18324 |
Posted: Thu Jan 09, 2020 4:35 am |
|
|
Does anyone know if the input pin A0 is changed from 16F1824 to 16F18324? This pin is used for input, but also for RS232 output, so should be switched from input to output during the program if RS232 signal is on.
The code for the 16F1824 was like this (simplified):
Code: |
#use rs232(baud=9600, FORCE_SW, xmit=PIN_A0)
setup_adc_ports(sAN2|sAN16|sAN18|VSS_VDD);
void main()
{
if (INPUT(PIN_A0) == 1)
output_low (PIN_C4);
else
output_high(PIN_C4);
while(1);
}
|
And is not working anymore with the 16F18324, if I change it to ADC it is working ok:
Code: |
#use rs232(baud=9600, FORCE_SW, xmit=PIN_A0)
setup_adc_ports(sAN0|sAN2|sAN16|sAN18|VSS_VDD);
int mode = 0;
void main()
{
delay_ms(10);
set_adc_channel(0);
delay_us(20);
MODE = read_adc();
if (MODE > 170)
output_low (PIN_C4);
else
output_high (PIN_C4);
while(1);
}
|
So it seems Microchip or CCS has changed something in the input of the PIN_A0. For now it is working ok, but I'm curious why the input read function is not working with only TTL levels. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Thu Jan 09, 2020 5:31 am |
|
|
While I don't use that PIC, I downloadedthe datasheet as I had a hunch.
That PIC has Peripheral Pin Select (PPS) ! You need to 'setup' or 'configure' the PPS section of the PIC BEFORE you using the I/O pins.
There's a 'sticky' above that shows you how to do it...
Jay |
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Thu Jan 09, 2020 5:53 am |
|
|
Hi Jay,
Thanks for your reaction, it could be part of the solution, but because it should be an regular input I don't think pin_select will do the job, only DAC, PWM, SPI and Interrupts are mentioned in the 16F18324.h file, I can't see an function to set the input as standard I/O pin.
Code: |
// #pin_select function=pin
// Valid Pins:
// PIN_A0,PIN_A1,PIN_A2,PIN_A3,PIN_A4,PIN_A5,PIN_C0,PIN_C1,PIN_C2,PIN_C3,
// PIN_C4,PIN_C5
// Input Functions:
// INT0,T0CK,T1CK,T1G,CCP1,CCP2,CCP3,CCP4,CWG1IN,CWG2IN,MDCIN1,MDCIN2,MDMIN,
// SCK1IN,SCL1IN,SDI1,SDA1IN,SS1IN,U1RX,U1CKIN,CLCIN0,CLCIN1,CLCIN2,CLCIN3,
// T3CK,T3G,T5CK,T5G,T0CKI,T1CKI,CCP1IN,CCP2IN,CCP3IN,CCP4IN,T3CKI,T5CKI,RX1
// Output Functions:
// NULL,PWM5OUT,PWM6OUT,CLC1OUT,CLC2OUT,CLC3OUT,CLC4OUT,CWG1OUTA,CWG1OUTB,
// CWG1OUTC,CWG1OUTD,CCP1OUT,CCP2OUT,CCP3OUT,CCP4OUT,CWG2OUTA,CWG2OUTB,
// CWG2OUTC,CWG3OUTD,U1TX,U1DT,C1OUT,C2OUT,SCK1OUT,SCL1OUT,SDO1,SDA1OUT,T0OUT,
// NCO1OUT,CLKROUT,DSMOUT,PWM5,PWM6,TX1,DT1,SCK1,SCL1,SDA1,NCO1
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Thu Jan 09, 2020 7:05 am |
|
|
hmmmm still thinking about this....
I'm wondering if you have to disable the 'USE RS232()' feature to allow the PIC to use that pin as a digital I/O pin ?
This was discussed here months( years ?) ago. Having to 'share' a pin to do both output RS232 AND INPUT a signal does have challenges. You need to isolate the 'output RS232' from the reading of the 'input'.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Thu Jan 09, 2020 8:47 am |
|
|
Comments:
'your 'setup_adc' line is doing nothing. This needs to be inside code.....
'definition' lines can (must) exist outside the code, but program lines need to
actually be in the program to work.
Now in fact what you need, is to get rid of the 'adc_channel' line, and instead
have:
setup_adc_ports(NO_ANALOGS);
You should then find your program works.
What is happening, is the 16F18324, wakes up with all these pins configured
as 'analog', which then won't work for digital I/O. Adding the
'set_adc_channel', overrides this selection 'accidentally', and starts it
working. However better to override correctly.
As Jay says, to use the pin for serial, you need to use PPS to set this
up before the #USE RS232. Otherwise the code will only generate a
'software' UART on the pins. |
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Thu Jan 09, 2020 9:23 am |
|
|
We have chosen for the software based UART, therefore the Forse_SW in the #use RS232, but if all is working we could decide to use the hardware based UART again.
So is this setup_adc_ports(sAN0,sAN2,...); still required for these new types uC or just use setup_adc_ports(NO_ANALOGS); and use 'set_adc_channel(X);' for each ADC readout.
It's strange that the sAN0 is working as ADC input while in my program this sAN0 is not mentioned in the setup_adc_ports.
But you are right my program is working if I use NO ANALOGS instead of the other declaration. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Thu Jan 09, 2020 9:26 am |
|
|
That simply sets all the pins to digital I/O.
The 'set_adc_channel' function as a 'side effect' loads the register that
configures the adc ports. It loads it with a default value which is what
starts the code working with this. |
|
|
|
|
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
|