View previous topic :: View next topic |
Author |
Message |
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
16F690 port problem & simple program |
Posted: Tue Jan 25, 2011 1:50 pm |
|
|
I had a program that worked.
Long story short, I methodically stripped it down to where I cant even get the IO ports to work in the PICSIM, let alone in the circuit.
Ultimately, I want to control PIN_C6 high/low, and PIN_C4 tristate/low.
But I've gotten to the point I can't even turn on the IO pins in the sim.
I've re-re-re-read the datasheet and tried everything I could think of trying. (I know I reversed my AND/OR's, just want to see the outputs change.)
I know CCS did something cause I originally had a XMIT_ON_LOW_TO_HIGH in their header for the SPI, my latest upgrade didn't have that.
Can anyone tell me why I can't get the (TRIS-low) outputs to toggle in this simple program. I've tried CCS functions and tried writing directly to the registers as a final act of defiance or frustration (not sure which).
Code: | #include <16f690.h>
#device ADC=10
#fuses XT,BROWNOUT,NOWDT,PUT,MCLR,NOFCMEN,BROWNOUT_SW,NOIESO
#use delay(clock=4000000)
#Byte TRISC = 0x87
#Byte PORTC = 0x07
#define PIN_RESET PIN_C4
#define PIN_CS PIN_C6
//*** using FAST IO instead ***
//#use fixed_io(a_outputs=PIN_A2)
//#use fixed_io(b_outputs=PIN_B4,PIN_B6,PIN_B7)
//#use fixed_io(c_outputs=PIN_C2,PIN_C4,PIN_C5,PIN_C6,PIN_C7)
//#use fast_io(all)
//#use STANDARD_IO(C)
/***************************************************************************/
/****************************** MAIN ***************************************/
void main()
{
set_tris_c(0); //0b00001011);
setup_adc_ports(NO_ANALOGS);
/**************************** MAIN LOOP *******************************/
while(TRUE)
{
/*** reset PD ***/
PORTC |= 0b00010000;
// output_low(PIN_RESET);
delay_uS(2);
// output_high(PIN_RESET);
PORTC &= 0b11101111;
// output_float(PIN_RESET);
PORTC = 0xFF;
PORTC = 0;
/*** pulse CS ***/
PORTC |= 0b01000000;
// Output_Low(PIN_CS);
delay_us(4);
PORTC &= 0b10111111;
// Output_High(PIN_CS);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Tue Jan 25, 2011 3:45 pm |
|
|
I thought that WAS pretty simple.
Okay, here. I'm using PICSIM to watch the outputs cuz I am tired of loading it in my board and probing. (done it about 100 different ways).
CCS PCM C Compiler, Version 4.118, 93506982 25-Jan-11 16:39
mplab V 8.50
just step thru this and tell me why C6 refuses to go high.
Also, notice that setup_adc_ports(NO_ANALOGS); doesn't clear ANSEL.
Code: |
#include <16f690.h>
#device ADC=10
#fuses XT,BROWNOUT,NOWDT,PUT,MCLR,NOFCMEN,BROWNOUT_SW,NOIESO
#use delay(clock=4000000)
#Byte TRISC = 0x87
#Byte PORTC = 0x07
#Byte ANSEL = 0x11E
#define PIN_RESET PIN_C4
#define PIN_CS PIN_C6
/***************************************************************************/
/****************************** MAIN ***************************************/
void main()
{
setup_adc_ports(NO_ANALOGS);
ANSEL = 0;
/**************************** MAIN LOOP *******************************/
while(TRUE)
{
output_low(PIN_RESET);
output_high(PIN_RESET);
output_Low(PIN_CS);
output_High(PIN_CS);
output_b(0xFF);
}
} |
and list:
Code: |
CCS PCM C Compiler, Version 4.118, 93506982 25-Jan-11 16:39
Filename: G:\JPD\Project Files\ENG051 Hoosier Transmitter Design\16F690\Eng051.lst
ROM used: 50 words (1%)
Largest free fragment is 2048
RAM used: 5 (2%) at main() level
5 (2%) worst case
Stack: 0 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 004
0003: NOP
....................
....................
.................... #include <16f690.h>
.................... //////// Standard Header file for the PIC16F690 device ////////////////
.................... #device PIC16F690
.................... #list
....................
.................... #device ADC=10
....................
.................... #fuses XT,BROWNOUT,NOWDT,PUT,MCLR,NOFCMEN,BROWNOUT_SW,NOIESO
.................... #use delay(clock=4000000)
....................
.................... #Byte TRISC = 0x87
.................... #Byte PORTC = 0x07
.................... #Byte ANSEL = 0x11E
.................... #define PIN_RESET PIN_C4
.................... #define PIN_CS PIN_C6
....................
.................... //*** using FAST IO instead ***
.................... //#use fixed_io(a_outputs=PIN_A2)
.................... //#use fixed_io(b_outputs=PIN_B4,PIN_B6,PIN_B7)
.................... //#use fixed_io(c_outputs=PIN_C2,PIN_C4,PIN_C5,PIN_C6,PIN_C7)
.................... //#use fast_io(all)
.................... //#use STANDARD_IO(C)
....................
....................
.................... /***************************************************************************/
.................... /****************************** MAIN ***************************************/
.................... void main()
.................... {
0004: CLRF 04
0005: BCF 03.7
0006: MOVLW 1F
0007: ANDWF 03,F
0008: BSF 03.6
0009: MOVF 1E,W
000A: ANDLW C0
000B: MOVWF 1E
000C: CLRF 19
000D: CLRF 1A
000E: BSF 03.5
000F: CLRF 1E
0010: BCF 03.5
0011: CLRF 1B
0012: BCF 03.6
0013: BCF 0D.5
....................
.................... setup_adc_ports(NO_ANALOGS);
0014: BSF 03.6
0015: MOVF 1E,W
0016: ANDLW C0
0017: MOVWF 1E
.................... ANSEL = 0;
0018: CLRF 1E
.................... /**************************** MAIN LOOP *******************************/
....................
.................... while(TRUE)
.................... {
.................... output_low(PIN_RESET);
0019: BSF 03.5
001A: BCF 03.6
001B: BCF 07.4
001C: BCF 03.5
001D: BCF 07.4
.................... output_high(PIN_RESET);
001E: BSF 03.5
001F: BCF 07.4
0020: BCF 03.5
0021: BSF 07.4
.................... output_Low(PIN_CS);
0022: BSF 03.5
0023: BCF 07.6
0024: BCF 03.5
0025: BCF 07.6
.................... output_High(PIN_CS);
0026: BSF 03.5
0027: BCF 07.6
0028: BCF 03.5
0029: BSF 07.6
.................... output_b(0xFF);
002A: BSF 03.5
002B: CLRF 06
002C: MOVLW FF
002D: BCF 03.5
002E: MOVWF 06
.................... }
002F: BSF 03.6
0030: GOTO 019
.................... }
0031: SLEEP
Configuration Fuses:
Word 1: 31E1 XT NOWDT PUT MCLR NOPROTECT NOCPD BROWNOUT_SW NOIESO NOFCMEN
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 25, 2011 4:03 pm |
|
|
I'm using the "low pin count" demo board that comes with the PicKit 2
to test your 16F690 program. That board doesn't have a crystal on it
so I changed the oscillator fuse from XT to INTRC_IO. I compiled it
with vs. 4.118 and it works. It toggles pin C6. On my oscilloscope
it goes high for 12us and then it goes low for 12us, continuously. |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Tue Jan 25, 2011 4:58 pm |
|
|
Well, I'm baffled.
I'll try it again in the morning.
If the problem can't be duplicated, maybe it won't be duplicated by me in the morning, either.
Thanks for the effort. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Tue Jan 25, 2011 5:48 pm |
|
|
Pin shorted to ground ???? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Jan 26, 2011 2:55 am |
|
|
Or oscillator not working, or MCLR not pulled up.
Try INTRC_IO, and if it starts working, you have found the problem.
Check the voltage on the MCLR pin. If it is not up near the 5v, again 'found reason'.
Best Wishes |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Wed Jan 26, 2011 8:10 am |
|
|
Hmmm...
I put the old (20MHz) xtal in the new board and read the program off of the old working board and loaded it...and it worked fine.
Then I recompiled the original program (after correcting the now missing define) and it...worked fine (still with the old 20MHz xtal).
I guess it's possible the board just doesn't like the shiney new 4MHz xtal, and that in the process I accidentally found some other bug to chase in PICSIM??
I'll scope out the xtal signals, although I'm not really sure what I'm looking for (overdriving?).
And then review my code again for changes needed for the new xtal. Maybe I missed something?
fuse to XT (also tried HS and INTOSC)
clock = 4000000
PWM registers adjusted
AD clock changed
SPI clock changed (but not really critical, would just run slower)
Timer2 adjusted (interrupt to blink LED)
That's really about all this little program uses. |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Thu Jan 27, 2011 6:39 am |
|
|
got a reply from CCS.
They sent me a corrected device & header file.
So I had:
wrong resistor value
bad pic (in 2 units, didn't expect that)
compiler bug
No wonder it was confusing. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Thu Jan 27, 2011 6:49 am |
|
|
It's nice to actually figure out WHAT was wrong! Far better than, 'mysteriously' it started to work right !!! |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Thu Jan 27, 2011 7:04 am |
|
|
roger that.
Now the next mystery:
It APPEARS that changing the xtal to 4mhz (and associated code) killed the PIC. I am going to switch back to the 20mhz and see if it comes back to life or not. I'm guessing not. I know that doesn't make sense.
will know this morning.
Like Sherlock Holmes once said:
When you rule out the logical explanations, whatever is left, no matter how illogical, must be the truth! (or something like that) |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Thu Jan 27, 2011 7:51 am |
|
|
using the new device & header files from CCS has caused my "simple" program that wasn't working in PICSIM to WORK in PICSIM!
PCMProgrammer, why did it work for you? Maybe you had the updated support files already? |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Thu Jan 27, 2011 12:25 pm |
|
|
No pic problems.
It was an illusion caused by the compiler bugs.
It had somehow caused my SPI data to update on the opposite clk edge,
and caused one of my IO lines to behave strangely.
Add to that the unexpected change of crystal and the wrong resistor in the feedback circuit...
works fine now. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 27, 2011 1:36 pm |
|
|
Quote: | PCMProgrammer, why did it work for you |
I have the PCM command line compiler, vs. 4.118, downloaded on Jan 22, 2011.
I did a fresh install just now. I took your source code from this post
http://www.ccsinfo.com/forum/viewtopic.php?t=44550&start=2
and pasted it into a MPLAB 16F690 project. I changed only one thing.
I changed the oscillator fuse to INTRC_IO. I compiled it and programmed
it into the 16F690 on my Microchip "Low pin count demo board" that comes
with the Pickit 2. I looked at pin C6 with my scope and it's toggling at
about 40 KHz. It works. |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Thu Jan 27, 2011 2:11 pm |
|
|
Thanks for looking at it, PCM.
There are 2 registers for configuring ports to analog/digital.
C6-7 are actually in ANSELH, which CCS wasn't setting up properly. (Something I also missed when I configured them directly.)
So they were never set up as IO lines.
Don't know why it worked for you but not for me. |
|
|
|