|
|
View previous topic :: View next topic |
Author |
Message |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
Problem with 18F45K22 input RA0 |
Posted: Fri Jun 03, 2016 11:27 pm |
|
|
Hello,
I am try configure RA0 as input, but not work... when I put 5V in this pin, the pic stop. Why? but the other inputs (RA1-RA6) if work normal
Code: | #use standard_io(A)
#use standard_io(B)
#use standard_io(C)
#use standard_io(D)
#use standard_io(E)
MAIN
set_tris_a(0b11111111); // RA0-RA5 (input 6,5,4,3,2,1), (RA6,RA7 OSCAL)
set_tris_b(0b11111111); // RB0-RB1 (RING,DTR), RB2-RB7 (input 12,11,10,9,8,7)
set_tris_c(0b10111110); // RC0-RC1 (TX, RX DEBUG),RC2-RC3 (Piloto, RST_SOFT), RC3-RC4 (free), RC6-RC7 (TX, RX UART1)
set_tris_d(0b10000000); // RD0-RD5(out 1,2,3,4,5,6),RD6-RD7 (TX, RX UART2)
set_tris_e(0b00000000); // RE0 (free), RE1-RE2 (out 7,8), RE3 (MCLR)
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1 (0x6FA);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_ccp3(CCP_OFF);
setup_ccp4(CCP_OFF);
setup_ccp5(CCP_OFF);
setup_dac(DAC_OFF);
setup_adc(ADC_OFF | NO_ANALOGS);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_wdt(WDT_OFF); |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19543
|
|
Posted: Sat Jun 04, 2016 1:51 am |
|
|
When posting about a problem, you must reduce to a minimum program, that demonstrates the problem, and post a _complete_ program that we can test. Bits without context are pointless.
Now there are several things slightly 'wrong', but nothing that is likely to cause the problem in what you show.
Generally is using standard_io, you don't have to set the TRIS. However, if you do, you should get it right. Things like RE3, cannot be programmed as an output (input only pin). Then you say that 'RA1-RA6' work normally, but this is impossible. RA6, is an _output only_ pin. If you apply 5v to this, then you risk destroying the gate. If you look at the 'overhead' diagrams of the package pins (Pin Diagrams), you will see that most I/O pins have 'dual headed' arrows, showing they can be input or output, while some have arrows only inwards (input only), and others have arrows only outward (output only). RE3, and RA7 are input only and RA6 is output only.
Then a comment. _every_ pin on the chip should be driven. Unused pins should either be set as 'output', or have an external resistor to drive them. You have several pins where you have them set as input, and the comment 'free'. Rethink, if these are not driven to a supply rail externally. Leaving pins 'floating', wastes power on the PIC, and also increases massively the risk of the code failing due to external EMI.
Then:
setup_adc(ADC_OFF | NO_ANALOGS);
is _not_ a legal setting.
You must only use setting values for the command they are for. NO_ANALOGS is _not_ a setting for the setup_adc command. Fortunately, NO_ANALOGS is coded as '0', so it won't cause a problem, but it is wrong.
So post a small complete program.
I've just tried:
Code: |
#include <18F45K22.h>
#device ADC=10
#fuses NOWDT, INTRC_IO, NOPLLEN, NOFCMEN, NOIESO, PUT
#fuses BROWNOUT, BORV29, STVREN, NOLVP, NODEBUG, NOCPB
#fuses NOCPD, NOXINST, NOPBADEN, NOPROTECT
#fuses CCP2C1, CCP3B5, TIMER3C0, CCP2D2
//safe set of fuses for internal oscillator and peripherals set to default
#use delay(internal=16MHz)
#use RS232 (UART1, BAUD=9600, ERRORS, PARITY=N, BITS=8)
//default RS232 for debugging
void main()
{
int1 old_input;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1 (0x6FA);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_ccp3(CCP_OFF);
setup_ccp4(CCP_OFF);
setup_ccp5(CCP_OFF);
setup_dac(DAC_OFF);
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
old_input=input(PIN_A0);
while(TRUE)
{
if (input(PIN_A0)!=old_input)
{
//input pin has changed
old_input=input(PIN_A0);
printf ("Pin is %d\n\r", old_input);
delay_ms(10);
}
} //loop sending to the RS232 when pin changes.
}
|
and it merrily runs, and sends 'Pin is 1', when RA0 goes high and then 'Pin is 0', when it goes low. |
|
|
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Sat Jun 04, 2016 3:19 pm |
|
|
Ttelmah wrote: | When posting about a problem, you must reduce to a minimum program, that demonstrates the problem, and post a _complete_ program that we can test. Bits without context are pointless.
..... |
thank you, but still no work...I write your code in the pic and work sometimes... the most times, the pic stop... :/ its how if was short circuit..
but I have not more... just this.
if I put divisor voltage if work, for example I put this
RA0--------¬
+5V---1k---|---1k---- GND
this code with the pic 18f25k22 if work...
:/ what happened?
I try this:
Code: | #include <18F45K22.h>
#device ADC=10
#fuses NOWDT, INTRC_IO, NOPLLEN, NOFCMEN, NOIESO, PUT
#fuses BROWNOUT, BORV29, STVREN, NOLVP, NODEBUG, NOCPB
#fuses NOCPD, NOXINST, NOPBADEN, NOPROTECT
#fuses CCP2C1, CCP3B5, TIMER3C0, CCP2D2
//safe set of fuses for internal oscillator and peripherals set to default
#use delay(internal=16MHz)
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C0,rcv=PIN_C1,ERRORS,stream=debug) // Configuración debug (Software)
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS,stream=uart1) // Configuración UART1 (Hardware)
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_D6,rcv=PIN_D7,ERRORS,stream=uart2) // Configuración UART2 (Hardware)
/***************************************************************/
//default RS232 for debugging
void main()
{
int1 old_input;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1 (0x6FA);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_ccp3(CCP_OFF);
setup_ccp4(CCP_OFF);
setup_ccp5(CCP_OFF);
setup_dac(DAC_OFF);
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
old_input=input(PIN_A0);
while(TRUE)
{
fprintf(debug,"hola\n\r");
delay_ms(1000);
output_toggle(PIN_A0);delay_ms(200);
output_toggle(PIN_c2);delay_ms(200);
//! if (input(PIN_A0)!=old_input)
//! {
//! //input pin has changed
//! old_input=input(PIN_A0);
//! fprintf(debug,"Pin is %d\n\r", old_input);
//!
//! delay_ms(10);
//! }
} //loop sending to the RS232 when pin changes.
} | [/code]
and as out if work good.
here say that is IO page 17
http://ww1.microchip.com/downloads/en/DeviceDoc/41412F.pdf
This pic has tolerance to +5V?
EDIT
With this configuration if work perfect.
Code: |
I deleted some fuses and put the crystal to 12M
#include <18F45K22.h>
#Device PASS_STRINGS=IN_RAM //#ZERO_RAM
#define FASTER_BUT_MORE_ROM // Variables en memoria
#fuses HSM, NOWDT, BROWNOUT, PUT, NOPBADEN, NOHFOFST
#fuses NOPLLEN //HW PLL disabled, PLL enabled in software
#fuses MCLR //Master Clear pin enabled
#fuses PROTECT //Code protected from reads
#use delay(clock=12MHz,crystal=12MHz)
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C0,rcv=PIN_C1,ERRORS,stream=debug) // Configuración debug (Software)
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS,stream=uart1) // Configuración UART1 (Hardware)
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_D6,rcv=PIN_D7,ERRORS,stream=uart2) // Configuración UART2 (Hardware)
/***************************************************************/
//default RS232 for debugging
void main()
{
int1 old_input;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1 (0x6FA);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_ccp3(CCP_OFF);
setup_ccp4(CCP_OFF);
setup_ccp5(CCP_OFF);
setup_dac(DAC_OFF);
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
old_input=input(PIN_A0);
while(TRUE)
{
fprintf(debug,"hola\n\r");
delay_ms(1000);
// output_toggle(PIN_A0);delay_ms(200);
output_toggle(PIN_c2);delay_ms(200);
output_low(PIN_A0);
if (input(PIN_A0))
{fprintf(debug,"Pin alto\n\r");
}
else{fprintf(debug,"Pin bajo\n\r");}
} //loop sending to the RS232 when pin changes.
}
|
Why? I can not used high frecuency with 3.3v? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 04, 2016 7:41 pm |
|
|
You can't put +5v on an i/o pin of a 18F45K22 which is running at +3.3v.
From the PIC data sheet:
Quote: |
27.0 ELECTRICAL CHARACTERISTICS
Voltage on any pin with respect to VSS (except VDD, and MCLR) ..... -0.3V to (VDD + 0.3V)
|
It says the highest voltage allowed on an i/o pin is 3.6v in your case.
3.3v Vdd + 0.3v = 3.6v
If you load the PIC data sheet in Acrobat reader, and search for 'tolerant'
you only find one use of it, and it is not for 5v tolerant. It's very easy
to do this search. |
|
|
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Sat Jun 04, 2016 9:00 pm |
|
|
PCM programmer wrote: | You can't put +5v on an i/o pin of a 18F45K22 which is running at +3.3v.
From the PIC data sheet:
Quote: |
27.0 ELECTRICAL CHARACTERISTICS
Voltage on any pin with respect to VSS (except VDD, and MCLR) ..... -0.3V to (VDD + 0.3V)
|
It says the highest voltage allowed on an i/o pin is 3.6v in your case.
3.3v Vdd + 0.3v = 3.6v
If you load the PIC data sheet in Acrobat reader, and search for 'tolerant'
you only find one use of it, and it is not for 5v tolerant. It's very easy
to do this search. |
ohhh
Damn!! yes (VDD + 0.3V) so max 3.6V ohhhh :(
Well, is very important read the manual :(
Well, but RA1-RA6 I have not problem... ( maybe in the future..)
I use this configuration:
Code: | #include <18F45K22.h>
#Device PASS_STRINGS=IN_RAM //#ZERO_RAM
#define FASTER_BUT_MORE_ROM // Variables en memoria
#fuses HSM, NOWDT, BROWNOUT, PUT, NOPBADEN, NOHFOFST
#fuses NOPLLEN //HW PLL disabled, PLL enabled in software
#fuses MCLR //Master Clear pin enabled
#fuses PROTECT //Code protected from reads
#use delay(clock=12MHz,crystal=12MHz) |
and now the pic no stop... only reboot... but I have put resistor 1k for no reboot.
Ok thank so much ... Now i understand the problem. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19543
|
|
Posted: Sun Jun 05, 2016 12:31 am |
|
|
There are some 3.3v PIC's that do have a few '5v tolerant' I/O pins (mainly PIC24's and PIC30's).
Yours isn't one.
I must admit since you were using the 'F', not the 'LF' version, I assumed you were working at 5v.
The difference in behaviour is almost certainly due to what is 'nearby' on the chip die. Since A0, is immediately adjacent to the MCLR pin, the overvoltage is probably having an effect on this circuit. On the other pins, instead it just results in overheating of the internal diode in the output FET, and will damage the chip 'long term'.
If you are using 5v I/O, why not run the PIC at 5v?. |
|
|
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Sun Jun 05, 2016 10:14 am |
|
|
Ttelmah wrote: | There are some 3.3v PIC's that do have a few '5v tolerant' I/O pins (mainly PIC24's and PIC30's).
Yours isn't one.
I must admit since you were using the 'F', not the 'LF' version, I assumed you were working at 5v.
The difference in behaviour is almost certainly due to what is 'nearby' on the chip die. Since A0, is immediately adjacent to the MCLR pin, the overvoltage is probably having an effect on this circuit. On the other pins, instead it just results in overheating of the internal diode in the output FET, and will damage the chip 'long term'.
If you are using 5v I/O, why not run the PIC at 5v?. |
Yes. :(
I have other components that work 3.3. then I decided to leave everything to 3.3V ...
I thought if the pic works at 5V so IO can also. Now, I know I can not.
Maybe it is not problem, are 12 sensors that will be far from the pic ...
then the voltage will fall ...
Thank you all for commenting. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sun Jun 05, 2016 10:55 am |
|
|
If these 12 sensors are digital, giving 5V output, you might be able to use 3v3 LDO regulators as an 'interface'.
IE sensor 5v output > input to 3v3 regulator===output to PIC input pin.
I do this all the time for 'automotive' interfacing where the car is 12 volts, and the PIC runs at 5 volts.
Board layout is easy as well!
It might be an option for you.
2 properly chosen resistors should work though.
Jay |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Jun 05, 2016 11:13 am |
|
|
i have interfaced 5v logic signals to PIC 3.3v inputs using a 7.5k resistor in series plus a BAT54 schottky diode connected with anode to pic input pin- cathode to +3.3v supply and had no problem with signals up to 200 khz in frequency.......... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
|
|
|
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
|