|
|
View previous topic :: View next topic |
Author |
Message |
RHA
Joined: 25 Apr 2006 Posts: 31 Location: Germany
|
Problem with V4.131 |
Posted: Wed Mar 28, 2012 2:11 am |
|
|
Hi,
in my code for an PIC18F46k80 i declare in the header (*.h) some variables for initializing and selecting direction of port pins :
Code: | // Init Outputregister PortA
#define IO_A0_INI 0 //
#define IO_A1_INI 0 //
#define IO_A2_INI 0 //
#define IO_A3_INI 0 //
#define IO_A4_INI 1 //
#define IO_A5_INI 1 //
#define IO_A6_INI 1 //
#define IO_A7_INI 1 //
// In/Out PortA (0 = Output // 1 = Input)
#define IO_A0_DIR 0 // M2 Direction Left
#define IO_A1_DIR 0 // M2 Direction Right
#define IO_A2_DIR 0 // M1 Direction Left
#define IO_A3_DIR 0 // M1 Direction Right
#define IO_A4_DIR 1 //
#define IO_A5_DIR 1 //
#define IO_A6_DIR 1 // M1 Encoder Line A
#define IO_A7_DIR 1 // M1 Encoder Line B
|
The variables will be used in my init-routine :
Code: | output_bit (PIN_A0, IO_A0_INI); // Initialize Outputregister PortA
output_bit (PIN_A1, IO_A1_INI); //
output_bit (PIN_A2, IO_A2_INI); //
output_bit (PIN_A3, IO_A3_INI); //
// output_bit (PIN_A4, IO_A4_INI); //
output_bit (PIN_A5, IO_A5_INI); //
output_bit (PIN_A6, IO_A6_INI); //
output_bit (PIN_A7, IO_A7_INI); //
#if IO_A0_DIR == 1
output_float (PIN_A0); // Set In/Out PortA
#else
output_drive (PIN_A0);
#endif
#if IO_A1_DIR == 1
output_float (PIN_A1);
#else
output_drive (PIN_A1);
#endif
#if IO_A2_DIR == 1
output_float (PIN_A2);
#else
output_drive (PIN_A2);
#endif
#if IO_A3_DIR == 1
output_float (PIN_A3);
#else
output_drive (PIN_A3);
#endif
/*
#if IO_A4_DIR == 1
output_float (PIN_A4);
#else
output_drive (PIN_A4);
#endif
*/
#if IO_A5_DIR == 1
output_float (PIN_A5);
#else
output_drive (PIN_A5);
#endif
#if IO_A6_DIR == 1
output_float (PIN_A6);
#else
output_drive (PIN_A6);
#endif
#if IO_A7_DIR == 1
output_float (PIN_A7);
#else
output_drive (PIN_A7);
#endif
|
Since my update from V4.125 to V4.131 i get this result :
Code: | .................... output_bit (PIN_A0, IO_A0_INI); // Initialize Outputregister PortA
006D2: BCF F89.0
.................... output_bit (PIN_A1, IO_A1_INI); //
006D4: BCF F89.1
.................... output_bit (PIN_A2, IO_A2_INI); //
006D6: BCF F89.2
.................... output_bit (PIN_A3, IO_A3_INI); //
006D8: BCF F89.3
.................... // output_bit (PIN_A4, IO_A4_INI); //
.................... output_bit (PIN_A5, IO_A5_INI); //
006DA: BSF F89.5
.................... output_bit (PIN_A6, IO_A6_INI); //
006DC: BSF F89.6
.................... output_bit (PIN_A7, IO_A7_INI); //
006DE: BSF F89.7
.................... #if IO_A0_DIR == 1
.................... output_float (PIN_A0); // Set In/Out PortA
.................... #else
.................... output_drive (PIN_A0);
00718: BCF F92.0
.................... #endif
....................
.................... #if IO_A1_DIR == 1
.................... output_float (PIN_A1);
.................... #else
.................... output_drive (PIN_A1);
0071A: BCF F92.1
.................... #endif
....................
.................... #if IO_A2_DIR == 1
.................... output_float (PIN_A2);
.................... #else
.................... output_drive (PIN_A2);
0071C: BCF F92.2
.................... #endif
....................
.................... #if IO_A3_DIR == 1
.................... output_float (PIN_A3);
.................... #else
.................... output_drive (PIN_A3);
0071E: BCF F92.3
.................... #endif
.................... /*
.................... #if IO_A4_DIR == 1
.................... output_float (PIN_A4);
.................... #else
.................... output_drive (PIN_A4);
.................... #endif
.................... */
.................... #if IO_A5_DIR == 1
.................... output_float (PIN_A5);
00720: MOVLB 1
00722: BSF x06.5
00724: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A5);
.................... #endif
....................
.................... #if IO_A6_DIR == 1
.................... output_float (PIN_A6);
00728: BSF x06.6
0072A: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A6);
.................... #endif
....................
.................... #if IO_A7_DIR == 1
.................... output_float (PIN_A7);
0072E: BSF x06.7
00730: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A7);
.................... #endif
|
The problem is this :
Code: | .................... #if IO_A5_DIR == 1
.................... output_float (PIN_A5);
00720: MOVLB 1
00722: BSF x06.5
00724: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A5);
.................... #endif
....................
.................... #if IO_A6_DIR == 1
.................... output_float (PIN_A6);
00728: BSF x06.6
0072A: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A6);
.................... #endif
....................
.................... #if IO_A7_DIR == 1
.................... output_float (PIN_A7);
0072E: BSF x06.7
00730: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A7);
.................... #endif
|
Normally that only has to be :
Code: | .................... #if IO_A5_DIR == 1
.................... output_float (PIN_A5);
00xxx: BSF F92.5
.................... #else
.................... output_drive (PIN_A5);
.................... #endif
....................
.................... #if IO_A6_DIR == 1
.................... output_float (PIN_A6);
00xxx: BSF F92.6
.................... #else
.................... output_drive (PIN_A6);
.................... #endif
....................
.................... #if IO_A7_DIR == 1
.................... output_float (PIN_A7);
00xxx: BSF F92.7
.................... #else
.................... output_drive (PIN_A7);
.................... #endif
|
Is that problem in my code or is it from the compiler????
In the V4.125 it worked good!
Kindly regards
Ralph Harms
Last edited by RHA on Wed Mar 28, 2012 11:23 pm; edited 2 times in total |
|
|
RHA
Joined: 25 Apr 2006 Posts: 31 Location: Germany
|
|
Posted: Wed Mar 28, 2012 3:17 am |
|
|
Supplement :
I upgraded because i got this problem with V4.125 :
Code: | .................... port_d_pullups (True);
006D4: MOVLW 01
006D6: MOVLB F
006D8: MOVWF x5B
006DA: BSF x86.7
....................
|
The error is :
Correct is (it´s working with V4.131) :
Code: | .................... port_d_pullups (True);
006D4: MOVLW 01
006D6: MOVLB F
006D8: MOVWF x5B
006DA: BSF x56.7
....................
|
But, why is the pull-up of RB0 switched on with the "port_d_pullups (True)" ???? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Mar 28, 2012 5:12 am |
|
|
The difference is that they are maintaining a RAM copy of the TRIS setting.
This is done to fix another problem with the chip.
This doesn't affect the functionality at all. However what will affect the functionality, is that the old code is doing it the wrong way round!....
If you look at the old code, for the first 'output_float', it is clearing the bit. This is simply 'wrong'. TRIS bits need to be '1' to make the pin 'float'. The new code is doing it correctly.....
Best Wishes |
|
|
RHA
Joined: 25 Apr 2006 Posts: 31 Location: Germany
|
|
Posted: Wed Mar 28, 2012 6:11 am |
|
|
Ttelmah wrote: | However what will affect the functionality, is that the old code is doing it the wrong way round!....
If you look at the old code, for the first 'output_float', it is clearing the bit. This is simply 'wrong'. TRIS bits need to be '1' to make the pin 'float'. The new code is doing it correctly..... |
OK, i was too lazy to downgrade again to the V4.125 and make a snip of the code, so i have edited it manually (i have corrected it now in the first post). So this fault was mine. Sorry.
But at all, with the new code my outputs will not work.
Do you have an idea why?
I think it´s because the buffer byte (address 0x106) ist not defined before these operations. |
|
|
RHA
Joined: 25 Apr 2006 Posts: 31 Location: Germany
|
|
Posted: Wed Mar 28, 2012 6:42 am |
|
|
OK,
at the beginning of my init routine i have inserted this code :
Code: | #byte Test = 0x106;
Test = 0;
|
After compiling i have checked the list file :
Code: | ....................
.................... #byte Test = 0x106;
.................... Test = 0;
006D8: MOVLB 1
006DA: CLRF x06
....................
|
Code: | .................... #if IO_A5_DIR == 1
.................... output_float (PIN_A5);
0072A: BSF x06.5
0072C: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A5);
.................... #endif
....................
.................... #if IO_A6_DIR == 1
.................... output_float (PIN_A6);
00730: BSF x06.6
00732: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A6);
.................... #endif
....................
.................... #if IO_A7_DIR == 1
.................... output_float (PIN_A7);
00736: BSF x06.7
00738: MOVFF 106,F92
.................... #else
.................... output_drive (PIN_A7);
.................... #endif
....................
|
Then i checked the function, and it worked. So it seems that the problem is that the buffer byte is not defined before the operations. The buffer has to be set to the previous defined value in the TRIS. But i can´t do that manually, because the compiler selects the address for the buffer. Maybe after some changes it is another address. |
|
|
RHA
Joined: 25 Apr 2006 Posts: 31 Location: Germany
|
|
Posted: Wed Mar 28, 2012 6:52 am |
|
|
Oh, thats pretty nice.
If i use "#use standard_io (all)" before my init code (and #use fast_io (All) after that), i get this result and it works (but the problem with the "port_d_pullups (True); " is still alive) :
Code: | ....................
.................... #use standard_io (all)
....................
.................... #if IO_A0_DIR == 1
.................... // output_float (PIN_A0); // Set In/Out PortA
.................... #else
.................... output_drive (PIN_A0);
00722: BCF F92.0
.................... #endif
....................
.................... #if IO_A1_DIR == 1
.................... // output_float (PIN_A1);
.................... #else
.................... output_drive (PIN_A1);
00724: BCF F92.1
.................... #endif
....................
.................... #if IO_A2_DIR == 1
.................... // output_float (PIN_A2);
.................... #else
.................... output_drive (PIN_A2);
00726: BCF F92.2
.................... #endif
....................
.................... #if IO_A3_DIR == 1
.................... // output_float (PIN_A3);
.................... #else
.................... output_drive (PIN_A3);
00728: BCF F92.3
.................... #endif
.................... /*
.................... #if IO_A4_DIR == 1
.................... output_float (PIN_A4);
.................... #else
.................... output_drive (PIN_A4);
.................... #endif
.................... */
.................... #if IO_A5_DIR == 1
.................... output_float (PIN_A5);
0072A: BSF F92.5
.................... #else
.................... output_drive (PIN_A5);
.................... #endif
....................
.................... #if IO_A6_DIR == 1
.................... output_float (PIN_A6);
0072C: BSF F92.6
.................... #else
.................... output_drive (PIN_A6);
.................... #endif
....................
.................... #if IO_A7_DIR == 1
.................... output_float (PIN_A7);
0072E: BSF F92.7
.................... #else
.................... output_drive (PIN_A7);
.................... #endif
....................
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Mar 28, 2012 8:52 am |
|
|
On the pull up, that is an error with the device database accessing the wrong register. If you have the full IDE, the device editor will allow you to change this.
I'd report the other behaviour to CCS.
Best Wishes |
|
|
|
|
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
|