|
|
View previous topic :: View next topic |
Author |
Message |
jim Guest
|
12F629 wont toggle I/O pins |
Posted: Wed Feb 19, 2003 6:27 am |
|
|
i just got some 12F629's in and i am trying to toggle an I/O pin. i have used PIC's for over 3 years now so i am not a newbie looking for help, but more so as if anyone has had the same problems. PORTA ^=0x01 will NOT toggle I/O
but yet
while(1)
{
x^=0x01
PORTA = x;
}
will toggle the I/O ?????? whats up with that ?
below is the code i am running that dont work.
any ideas welcome. p.s. i am using hte latest version of the compiler.
#include <12F629.H>
#fuses HS,NOWDT,NOPROTECT,PUT,NOMCLR,BROWNOUT
#byte PORTA = 5
void main(void)
{
set_tris_a(0x00);
while(1)
{
PORTA ^=0x01;
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11866 |
|
|
Sherpa Doug Guest
|
Re: 12F629 wont toggle I/O pins |
Posted: Wed Feb 19, 2003 8:07 am |
|
|
:=i just got some 12F629's in and i am trying to toggle an I/O pin. i have used PIC's for over 3 years now so i am not a newbie looking for help, but more so as if anyone has had the same problems. PORTA ^=0x01 will NOT toggle I/O
:=but yet
:=
:=while(1)
:={
:= x^=0x01
:= PORTA = x;
:=}
:=
:=will toggle the I/O ?????? whats up with that ?
:=below is the code i am running that dont work.
:=any ideas welcome. p.s. i am using hte latest version of the compiler.
:=
:=
:=#include <12F629.H>
:=#fuses HS,NOWDT,NOPROTECT,PUT,NOMCLR,BROWNOUT
:=
:=#byte PORTA = 5
:=
:=void main(void)
:={
:= set_tris_a(0x00);
:=
:= while(1)
:= {
:= PORTA ^=0x01;
:= }
:=}
Could it be the notorious PIC read-modify-write problem? What is your clock speed and what are the loads on the toggling pins? The pins must be able to settle to the output state of the old instruction before they are read by the next instruction.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11871 |
|
|
Bruce R. Knox Guest
|
Re: 12F629 wont toggle I/O pins |
Posted: Wed Feb 19, 2003 8:11 am |
|
|
:=i just got some 12F629's in and i am trying to toggle an I/O pin. i have used PIC's for over 3 years now so i am not a newbie looking for help, but more so as if anyone has had the same problems. PORTA ^=0x01 will NOT toggle I/O
:=but yet
:=
:=while(1)
:={
:= x^=0x01
:= PORTA = x;
:=}
:=
:=will toggle the I/O ?????? whats up with that ?
:=below is the code i am running that dont work.
:=any ideas welcome. p.s. i am using hte latest version of the compiler.
:=
:=
:=#include <12F629.H>
:=#fuses HS,NOWDT,NOPROTECT,PUT,NOMCLR,BROWNOUT
:=
:=#byte PORTA = 5
:=
:=void main(void)
:={
:= set_tris_a(0x00);
:=
:= while(1)
:= {
:= PORTA ^=0x01;
:= }
:=}
Jim:
The difference between the two methods is that "PORTA ^= 0x01" operates by reading and modifying the port (0x05) in one instruction. This means that the initial state of the bit, before you XOR, comes from the port pins.
3.139 generates this:
.................... PORTA ^= 0x01;
0052: MOVLW 01
0053: XORWF 05,F
So, it's possible that, depending on the load on the pin, the pin has not completely changed state when your program gets there to invert it (XORWF reads the pin during Q2, does the operation in Q3, then writes back to the port in Q4).
When you use "x ^= 0x01; PORTA = x", 3.139 generates:
.................... x ^= 0x01;
0054: XORWF 29,F
....................
.................... PORTA = x;
0055: MOVF 29,W
0056: MOVWF 05
This inverts a file register bit, then copies it to the port. The initial state of the i/o pin doesn't matter anymore, and you say it works.
To verify this, you could slow down your clock (may have to slow down quite a bit) or put a delay_us(50) or something like that in the loop.
As an aside, 18 series lets you to access the output LATCHES (LATA, LATB, etc.) directly. This is handy because it avoids just such problems (the latches are essentially file registers connected to the i/o pins).
Hope this helps. Let us know if this fixes your problem.
Bruce
___________________________
This message was ported from CCS's old forum
Original Post ID: 11872 |
|
|
jim Guest
|
Re: 12F629 wont toggle I/O pins |
Posted: Wed Feb 19, 2003 9:11 am |
|
|
i see your point, but when i use a 12CE674 all works fine.
somthing is very strange here. when i add this statement PORTA =0x07; GP0 & GP2 are high but GP1 is low. however when i use the same code and change the #include to <12CE674> and recompile and pop that chip in the same board all 3 i/o's are high. p.s. all that is stuffed on the board is the power supply & xtal.
am i not turning on/off somthing properly in the setups for the 12F629?
main()
{
set_tris_a(0x00);
PORTA = 0x07;
while(1);
}
:=:=i just got some 12F629's in and i am trying to toggle an I/O pin. i have used PIC's for over 3 years now so i am not a newbie looking for help, but more so as if anyone has had the same problems. PORTA ^=0x01 will NOT toggle I/O
:=:=but yet
:=:=
:=:=while(1)
:=:={
:=:= x^=0x01
:=:= PORTA = x;
:=:=}
:=:=
:=:=will toggle the I/O ?????? whats up with that ?
:=:=below is the code i am running that dont work.
:=:=any ideas welcome. p.s. i am using hte latest version of the compiler.
:=:=
:=:=
:=:=#include <12F629.H>
:=:=#fuses HS,NOWDT,NOPROTECT,PUT,NOMCLR,BROWNOUT
:=:=
:=:=#byte PORTA = 5
:=:=
:=:=void main(void)
:=:={
:=:= set_tris_a(0x00);
:=:=
:=:= while(1)
:=:= {
:=:= PORTA ^=0x01;
:=:= }
:=:=}
:=
:=
:=Jim:
:=
:=The difference between the two methods is that "PORTA ^= 0x01" operates by reading and modifying the port (0x05) in one instruction. This means that the initial state of the bit, before you XOR, comes from the port pins.
:=
:=3.139 generates this:
:=
:=.................... PORTA ^= 0x01;
:=0052: MOVLW 01
:=0053: XORWF 05,F
:=
:=So, it's possible that, depending on the load on the pin, the pin has not completely changed state when your program gets there to invert it (XORWF reads the pin during Q2, does the operation in Q3, then writes back to the port in Q4).
:=
:=When you use "x ^= 0x01; PORTA = x", 3.139 generates:
:=
:=.................... x ^= 0x01;
:=0054: XORWF 29,F
:=....................
:=.................... PORTA = x;
:=0055: MOVF 29,W
:=0056: MOVWF 05
:=
:=This inverts a file register bit, then copies it to the port. The initial state of the i/o pin doesn't matter anymore, and you say it works.
:=
:=To verify this, you could slow down your clock (may have to slow down quite a bit) or put a delay_us(50) or something like that in the loop.
:=
:=As an aside, 18 series lets you to access the output LATCHES (LATA, LATB, etc.) directly. This is handy because it avoids just such problems (the latches are essentially file registers connected to the i/o pins).
:=
:=Hope this helps. Let us know if this fixes your problem.
:=
:=Bruce
___________________________
This message was ported from CCS's old forum
Original Post ID: 11878 |
|
|
jim Guest
|
Re: 12F629 wont toggle I/O pins |
Posted: Wed Feb 19, 2003 10:40 am |
|
|
My Thanks goes to Jeff Jackowski who said that the comparators are ON by default and needed to use "setup_comparator(NC_NC_NC_NC);" when i did that all worked great!
:=i just got some 12F629's in and i am trying to toggle an I/O pin. i have used PIC's for over 3 years now so i am not a newbie looking for help, but more so as if anyone has had the same problems. PORTA ^=0x01 will NOT toggle I/O
:=but yet
:=
:=while(1)
:={
:= x^=0x01
:= PORTA = x;
:=}
:=
:=will toggle the I/O ?????? whats up with that ?
:=below is the code i am running that dont work.
:=any ideas welcome. p.s. i am using hte latest version of the compiler.
:=
:=
:=#include <12F629.H>
:=#fuses HS,NOWDT,NOPROTECT,PUT,NOMCLR,BROWNOUT
:=
:=#byte PORTA = 5
:=
:=void main(void)
:={
:= set_tris_a(0x00);
:=
:= while(1)
:= {
:= PORTA ^=0x01;
:= }
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11889 |
|
|
|
|
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
|