|
|
View previous topic :: View next topic |
Author |
Message |
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
set_tris_b using PIC16F716 and ICD2 not working |
Posted: Sat Jun 07, 2008 1:56 pm |
|
|
I am just begining to use the CCS compiler with an ICD2 debugger.
I have a very simple program that I have written to get familiar with this setup.
The problem is when I try to setup the ports.
I try to set PORTAs trisa as 0x1f and PORTBs trisb as 0x37.
Then all I want to do is read pin PIN_B4 and set PIN_B7 high if PIN_B4 is high and low if PIN_B4 is low.
When I step through the program and watch the tristate registers in a watch window in MPLAB 8.10 they are set to all zeros when the program executes the set_tris_a and set_tris_b commands.
Any ideas???
Code: |
#include <16F716.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use fixed_io(b_outputs = PIN_B3, PIN_B6, PIN_B7)
#define Z_CROSS PIN_B0
#define SENSOR PIN_B1
#define PWR_SW PIN_B2
#define HEARTBEAT PIN_B3
#define AC PIN_B4
#define DC_TOP PIN_B5
#define INTERLOCK_OUT PIN_B6
#define GATE PIN_B7
void main()
{
set_tris_a(0x1f);
set_tris_b(0x37);
SETUP_ADC_PORTS(ALL_ANALOG);
SETUP_ADC(adc_clock_div_32);
SET_ADC_CHANNEL(0);
while (1==1)
{
SETUP_TIMER_0(RTCC_DIV_8|RTCC_INTERNAL);
delay_cycles(1);
if(input(AC)) output_high(GATE);
delay_cycles(1);
if(!input(AC)) output_low(GATE);
delay_cycles(1);
}
} |
Here is the compiled listing:
Code: |
CCS PCM C Compiler, Version 4.010, 35415 07-Jun-08 16:51
Filename: to_ccs.lst
ROM used: 60 words (3%)
Largest free fragment is 1732
RAM used: 5 (4%) at main() level
5 (4%) worst case
Stack: 0 locations
*
0000: NOP
0001: MOVLW 00
0002: MOVWF 0A
0003: GOTO 004
.................... #include <16F716.h>
.................... //////// Standard Header file for the PIC16F716 device ////////////////
.................... #device PIC16F716
.................... #list
....................
....................
....................
.................... #fuses HS,NOWDT,NOPROTECT
.................... #use delay(clock=4000000)
.................... #use fixed_io(b_outputs = PIN_B3, PIN_B6, PIN_B7)
....................
.................... #define Z_CROSS PIN_B0
.................... #define SENSOR PIN_B1
.................... #define PWR_SW PIN_B2
.................... #define HEARTBEAT PIN_B3
.................... #define AC PIN_B4
.................... #define DC_TOP PIN_B5
.................... #define INTERLOCK_OUT PIN_B6
.................... #define GATE PIN_B7
....................
....................
.................... void main()
.................... {
0004: CLRF 04
0005: BCF 03.7
0006: MOVLW 1F
0007: ANDWF 03,F
0008: BSF 03.5
0009: BSF 1F.0
000A: BSF 1F.1
000B: BSF 1F.2
.................... set_tris_a(0x1f);
000C: MOVLW 1F
000D: MOVWF 05
.................... set_tris_b(0x37);
000E: MOVLW 37
000F: MOVWF 06
.................... SETUP_ADC_PORTS(ALL_ANALOG);
0010: BCF 1F.0
0011: BCF 1F.1
0012: BCF 1F.2
.................... SETUP_ADC(adc_clock_div_32);
0013: BCF 03.5
0014: BCF 1F.6
0015: BSF 1F.7
0016: BSF 1F.0
.................... SET_ADC_CHANNEL(0);
0017: MOVLW 00
0018: MOVWF 21
0019: MOVF 1F,W
001A: ANDLW C7
001B: IORWF 21,W
001C: MOVWF 1F
.................... while (1==1)
.................... {
.................... SETUP_TIMER_0(RTCC_DIV_8|RTCC_INTERNAL);
001D: BSF 03.5
001E: MOVF 01,W
001F: ANDLW C0
0020: IORLW 02
0021: MOVWF 01
.................... delay_cycles(1);
0022: NOP
.................... if(input(AC)) output_high(GATE);
0023: MOVLW 37
0024: MOVWF 06
0025: BCF 03.5
0026: BTFSS 06.4
0027: GOTO 02D
0028: MOVLW 37
0029: BSF 03.5
002A: MOVWF 06
002B: BCF 03.5
002C: BSF 06.7
.................... delay_cycles(1);
002D: NOP
.................... if(!input(AC)) output_low(GATE);
002E: MOVLW 37
002F: BSF 03.5
0030: MOVWF 06
0031: BCF 03.5
0032: BTFSC 06.4
0033: GOTO 039
0034: MOVLW 37
0035: BSF 03.5
0036: MOVWF 06
0037: BCF 03.5
0038: BCF 06.7
.................... delay_cycles(1);
0039: NOP
.................... }
003A: GOTO 01D
.................... }
003B: GOTO 03B
Configuration Fuses:
Word 1: 3FB2 HS NOWDT PUT NOPROTECT BORV40 NOBROWNOUT |
|
|
|
Ttelmah Guest
|
|
Posted: Sun Jun 08, 2008 2:30 am |
|
|
Start by looking at the data sheet. TrisA, is memory address 0x85, and TrisB is address 0x86. On the '16' chips, you can't wite directly to addresses over 0x7F, so addressing these will be done by talking to addresses 5, and 6, with bank 1 selected (which adds 0x80, to the address you actually talk to). To select Bank1, you need bit5, of register 3, set, and bit6 clear (both of these 'wake up', set to '0').
Now look at the assembler:
Line 8, sets bit 5 of register 3, as required. Nothing after this, to the 'tris' instructions, changes this.
Line C, puts '1F', into the accumulator, and then line D, writes this to address 5, _which addresses 0x85_, with the bank select set. Exactly what you have asked it to do.
Then line E, puts '37', into the accumulator, and line F, writes this to the TrisB.
The code is doing what you want it to do. If you are not seeing what you expect, 'look again', at what else you are doing.....
I'd suspect a problem with the ICD, or the interface with MPLAB.
As a 'minor' comment, for 4MHz, select XT, rather than HS in the fuses.
As a further comment, you don't actually have to do this at all. By 'default', the CCS compiler, will _automatically_ set the TRIS bit for every bit you use as an input, and clear the TRIS bit for everything you use as an output. Lines 26, and 27, do this for the input bit 'AC'. If you want to control the TRIS manually, use the #use fast_io option for the port. However unless you need this, why not just let the compiler do it's job....
Your problem is not in the code shown, but something in the way your development environment is working...
Best Wishes |
|
|
edbfmi Guest
|
|
Posted: Sun Jun 08, 2008 5:39 am |
|
|
Thanks for the input Ttelmah.
I read through the assembled code and did not see anything myself.
I also wrote the program without using the "tris" commands.
It still compiles correctly but when I debug it and watch the trisa and trisb registers they randomly switch to all outputs??
Also when I get to the
Code: |
SETUP_TIMER_0(RTCC_DIV_8|RTCC_INTERNAL);
|
command the OPTION register is set to all "0"
The assembled code looks right but the watch window shows a different story.
I agree that there must be something wrong with the development environment.
Does anyone have any suggestions where to look?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 08, 2008 11:18 am |
|
|
The first thing to do, is to go to the MPLAB "Configure" menu, and
open the "Select Device" window. Make sure that the device is
really set to "16F716". |
|
|
edbfmi Guest
|
|
Posted: Sun Jun 08, 2008 3:14 pm |
|
|
I did check to make sure the device selected is the PIC16F716.
I wish it were that simple. Still no luck.
I am beginning to question the actual ICD2 module.
Along those lines, has anybody had any luck eith the RealICE emulator?
I need to get this project off the ground and can't spend a lot of time messing around with hardware issues. |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Sun Jun 08, 2008 3:50 pm |
|
|
I just tried something that may help someone figure out what is going on.
I did FILE>IMPORT and imported the .hex file. When I did that the program seemed to run fine on my hardware. I could step into the program and watch the PORTB inputs change as I changed them on the target. Unfortunately when I do it this way I can't watch the Code Step through the program lines in the MPLAB window.
Does this shed any light on my issues? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jun 08, 2008 3:59 pm |
|
|
Code: | CCS PCM C Compiler, Version 4.010 | The first releases of the v4 version compiler were not stable and only to be used by people eager to try the new features. In fact, all releases before v4.030 releases were so bad quality that anything more intelligent than blinking a LED would fail.
Save everybody, yourself included, a lot of time and revert to the stable version from the time you bought the compiler (v3.249) or upgrade to the latest version (v4.073). If you forgot to download v3.249 send CCS an email and they will come with a solution. |
|
|
Ttelmah Guest
|
|
Posted: Sun Jun 08, 2008 4:03 pm |
|
|
It sounds as if the .cod file has problems, so the ICD, is not receiving the real information about the code. If I remember correctly, in the early days of the V4 compilers, the default settings in CCS, did not output the file in the format needed by MPLAB. This was changeable. However I have to 'second' the suggestion to move away from 4.011...
Best |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Sun Jun 08, 2008 4:44 pm |
|
|
Thanks for the insight.
One other thing I have tried that seems weird.
I moved the
Code: |
SETUP_TIMER_0(RTCC_DIV_8|RTCC_INTERNAL);
|
Outiside of the while (1 == 1) loop and then placed a breakpoint at
the delay_cycles(1); just in side the while loop.
If I RUN the program from the beginning to the breakpoint then STEP through the program it seems to work fine. But if I step through the program from the beginning it goofs up again.
Does this still make you believe that the Complier version I am using is bad?
How would I go about getting an earlier version of the compiler? do I just contact CCS and tell them the one I am currently using is buggy??
Thanks for everyones help. |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 09, 2008 3:04 am |
|
|
3.249, is still available from the download page, for exactly this reason....
Do you have the 'windows' environment, or the command line version?.
In the windowed version, 'Options', 'Project options', 'Output files'. The problem with ICD, was I think, to do with whether you selected 'Standard .COD', or 'Expanded .COD'. There were posts here about it when V4 was young.
Have a separate look at the 'Version 4 comments' sticky thread at the top of the forum. Posting in it really 'died' when V4, started to work. 4.011, was really still at the point in the V4 development, where it hardly worked....
Best Wishes |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Mon Jun 09, 2008 12:51 pm |
|
|
Well I just got version 3.249 installed and I am having the exact same issues.
I think I am going to get the Microchip RealICE on order today and have it flown in. I need to get past this so I can get this board developed.
I will keep everyone advised on the progress (or lack of) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 09, 2008 1:37 pm |
|
|
Are you using the special header that is required to do hardware
debugging with the 16F716 and the ICD2 ?
Download the ICD2 header specification and look at the table on page 12.
It shows that header p/n AC162054 is required. ("N" means it's needed).
http://ww1.microchip.com/downloads/en/DeviceDoc/51292P.pdf
I hope you don't go spend a couple thousand dollars when all you really
needed was a header. |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Mon Jun 09, 2008 1:55 pm |
|
|
Yep, I am using the header.
I agree, I really don't want to part with the extra$$$ if I don't have to.
(I can use it for GASOLINE )
But as I sit now I feel like I am dead in the water and need to try something to get this project moving forward. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 09, 2008 2:06 pm |
|
|
Why not do the development on a closely similar PIC that has built-in
debugging ? (And doesn't require a header). Debug it on that PIC.
Then move the completed project to the 16F716. Re-compile it for that
PIC and it will probably work. |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Mon Jun 09, 2008 2:27 pm |
|
|
That is a possibility.
I might give that a try as plan A. I am still going to get the RealICE in here tomorrow for Plan B. I just won't open it unless Plan A becomes too much of a bother.
I will keep you all posted. |
|
|
|
|
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
|