|
|
View previous topic :: View next topic |
Author |
Message |
orb Guest
|
16F526 RC0, RC1& RC2 generate pulses when DELAY_MS(XX) |
Posted: Wed Mar 25, 2009 8:33 am |
|
|
Hi all,
I am having a very strange problem with the 16F526. I am using it to drive pins B4, B5, C0, C1 & C2 but the device begins generating periodic square pulses on C0, C1 & C2 with the following simple code.
Here's what's weird, C0 puts out a 123kHz pulse, C1 a 61.6kHz and C2 a 30.8kHz instead of just toggling off/on once with a 500ms delay in between.
What's more interesting is that if I remove the "DELAY_MS(500);" line
C0, C1 & C2 stop generating the pulses I described above.
Is anything wrong with my code? What am I missing?
Code: | #include <16F526.h>
#fuses INTRC_IO, WDT, NOPROTECT, MCLR, IOSCFS_4
#use delay(clock = 4000000, RESTART_WDT)
#use fast_io(B)
#use fast_io(C)
//********************** I/O DEFINITIONS **************************************/
#define startSwitch PIN_B1
#define floatTop PIN_B2
#define startLED PIN_B4
#define drainLED PIN_B5
#define pumpDrive PIN_C0
#define valveTop PIN_C1
#define valveMiddle PIN_C2
#define floatBottom PIN_C3
#define floatMiddle PIN_C4
#define drainSwitch PIN_C5
void main() {
INT count=0, STATE;
setup_counters(RTCC_INTERNAL,WDT_1152MS);
set_tris_b(0x0E); // SET PORT B TO (xxoo iiio) < o= out, i=in
set_tris_c(0x38); // SET PORT C TO (xxii iooo) < o= out, i=in
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);
restart_wdt();
//********** INITIALIZATION LED SCAN *****************************************//
// INITIAL POWER UP LED STROBING //
OUTPUT_LOW(pumpDrive);
OUTPUT_LOW(valveTop);
OUTPUT_LOW(valveMiddle);
OUTPUT_LOW(startLED);
OUTPUT_LOW(drainLED);
delay_ms(500);
restart_wdt();
OUTPUT_HIGH(startLED);
OUTPUT_HIGH(drainLED);
OUTPUT_HIGH(pumpDrive);
OUTPUT_HIGH(valveTop);
OUTPUT_HIGH(valveMiddle);
while(TRUE) {
restart_wdt();
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 25, 2009 12:26 pm |
|
|
Do an experiment. Disable the Watchdog Timer by changing the fuse
to NOWDT. See if that fixes the problem. If so, the problem is related
to the Watchdog Timer.
Also post your compiler version. It's given at the top of the .LST file,
which is in your project directory. It's a 4-digit number in this format:
x.xxx |
|
|
Guest
|
|
Posted: Wed Mar 25, 2009 12:48 pm |
|
|
I tried removing the WDT by adding NOWDT to fuses but it had no effect.
I'm running version 4.089, I believe the latest.
You should also know that I first had a 16F505 running perfectly fine on this same circuit. I swapped out the 'F505 w/ the 'F526 to add the data EEPROM. They're supposed to be pin for pin compatible (f505 > f526).
This is the second 'F526 I used on this board b/c I thought the first one was bad.
Do you want me to post the entire *.lst file?
Thanks
Oscar |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Mar 25, 2009 12:56 pm |
|
|
setup_counters() (and setup_wdt() as well) seems to generate incorrect code for the 16F526 (checked with PCB V4.084)
Code: | ..... setup_counters(RTCC_INTERNAL,WDT_1152MS);
001B: MOVLW 0E
001C: MOVWF 07
001D: CLRF 01
001E: MOVLW 0F
001F: OPTION
0020: CLRWDT
0021: MOVF 07,W ; reads PORT C state
0022: OPTION ; write it to OPTION register |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 25, 2009 1:01 pm |
|
|
Post your setup_counters() code from the .LST file. We'll compare it
to FvM's code.
In fact, post everything in the .LST file from the start of main(), up to
and including the setup_counters() routine. |
|
|
orb Guest
|
|
Posted: Wed Mar 25, 2009 1:12 pm |
|
|
Good catch FvM. Here's my complete listing
Code: |
CCS PCB C Compiler, Version 4.089, 47826 25-Mar-09 13:59
Filename: F:\OTHER PROJECTS\pelonWaterWorks\FIRMWARE\PELONWATERWORKS.lst
ROM used: 77 words (8%)
Largest free fragment is 512
RAM used: 5 (20%) at main() level
6 (24%) worst case
Stack: 1 locations
*
0000: MOVWF 05
0001: GOTO 018
0002: GOTO 003
.................... //*****************************************************************************/
.................... // PELONWATERWORKS.C /
.................... // By: Oscar Robles /
.................... // Date: 17 FEB 2009 /
.................... // /
....................
.................... #include <16F526.h>
.................... //////// Standard Header file for the PIC16F526 device ////////////////
.................... #device PIC16F526
.................... #list
....................
.................... #fuses INTRC_IO, WDT, NOPROTECT, MCLR, IOSCFS_4
.................... #use delay(internal=4M, RESTART_WDT)
0003: MOVF 0D,W
0004: BTFSC 03.2
0005: GOTO 017
0006: MOVLW 01
0007: MOVWF 08
0008: MOVLW BF
0009: MOVWF 07
000A: CLRWDT
000B: DECFSZ 07,F
000C: GOTO 00A
000D: DECFSZ 08,F
000E: GOTO 008
000F: MOVLW 4A
0010: MOVWF 07
0011: DECFSZ 07,F
0012: GOTO 011
0013: NOP
0014: CLRWDT
0015: DECFSZ 0D,F
0016: GOTO 006
0017: RETLW 00
.................... #use fast_io(B)
.................... #use fast_io(C)
....................
.................... //********************** I/O DEFINITIONS **************************************/
....................
.................... #define startSwitch PIN_B1
.................... #define floatTop PIN_B2
.................... #define startLED PIN_B4
.................... #define drainLED PIN_B5
....................
.................... #define pumpDrive PIN_C0
.................... #define valveTop PIN_C1
.................... #define valveMiddle PIN_C2
.................... #define floatBottom PIN_C3
.................... #define floatMiddle PIN_C4
.................... #define drainSwitch PIN_C5
....................
....................
....................
.................... //************************ MAIN PROGRAM ***************************************/
....................
.................... void main() {
0018: CLRF 04
.................... INT count=0, STATE;
0019: CLRF 0A
.................... setup_counters(RTCC_INTERNAL,WDT_1152MS);
001A: MOVLW 0E
001B: MOVWF 07
001C: CLRF 01
001D: MOVLW 0F
001E: OPTION
001F: CLRWDT
0020: MOVF 07,W
0021: OPTION
.................... set_tris_b(0x0E); // SET PORT B TO (xxoo iiio) < o= out, i=in
0022: MOVLW 0E
0023: TRIS 6
.................... set_tris_c(0x38); // SET PORT C TO (xxii iooo) < o= out, i=in
0024: MOVLW 38
0025: TRIS 7
.................... SETUP_ADC(ADC_OFF);
0026: BCF 09.0
.................... SETUP_ADC_PORTS(NO_ANALOGS);
0027: BCF 09.6
0028: BCF 09.7
.................... setup_comparator(NC_NC_NC_NC);
0029: MOVLW 71
002A: MOVWF 08
002B: MOVLW 61
002C: MOVWF 0B
.................... restart_wdt();
002D: CLRWDT
....................
.................... //********** INITIALIZATION LED SCAN *****************************************//
....................
.................... // INITIAL POWER UP LED STROBING //
....................
.................... OUTPUT_LOW(pumpDrive);
002E: BCF 07.0
.................... OUTPUT_LOW(valveTop);
002F: BCF 07.1
.................... OUTPUT_LOW(valveMiddle);
0030: BCF 07.2
.................... OUTPUT_LOW(startLED);
0031: BCF 06.4
.................... OUTPUT_LOW(drainLED);
0032: BCF 06.5
.................... delay_ms(500);
0033: MOVLW 02
0034: MOVWF 0C
0035: MOVLW FA
0036: MOVWF 0D
0037: CALL 003
0038: DECFSZ 0C,F
0039: GOTO 035
.................... restart_wdt();
003A: CLRWDT
.................... OUTPUT_HIGH(startLED);
003B: BSF 06.4
.................... OUTPUT_HIGH(drainLED);
003C: BSF 06.5
.................... OUTPUT_HIGH(pumpDrive);
003D: BSF 07.0
.................... OUTPUT_HIGH(valveTop);
003E: BSF 07.1
.................... OUTPUT_HIGH(valveMiddle);
003F: BSF 07.2
.................... delay_ms(500);
0040: MOVLW 02
0041: MOVWF 0C
0042: MOVLW FA
0043: MOVWF 0D
0044: CALL 003
0045: DECFSZ 0C,F
0046: GOTO 042
.................... restart_wdt();
0047: CLRWDT
.................... OUTPUT_LOW(startLED);
0048: BCF 06.4
.................... OUTPUT_LOW(drainLED);
0049: BCF 06.5
.................... OUTPUT_LOW(pumpDrive);
004A: BCF 07.0
.................... OUTPUT_LOW(valveTop);
004B: BCF 07.1
.................... OUTPUT_LOW(valveMiddle);
004C: BCF 07.2
....................
.................... while(TRUE) {
....................
.................... restart_wdt();
004D: CLRWDT
.................... }
004E: GOTO 04D
.................... }
....................
....................
....................
004F: SLEEP
Configuration Fuses:
Word 1: 0FBC INTRC_IO WDT NOPROTECT MCLR IOSCFS_4 NOCPD |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Mar 25, 2009 1:36 pm |
|
|
Didn't change to V4.089. You can set WDT related registers manually - or disable WDT til a CCS bug fix. |
|
|
orb Guest
|
|
Posted: Thu Mar 26, 2009 6:55 am |
|
|
I'm not going to manipulate the hex file in any way. Thanks for the suggestion. CCS will have to fix the bug. I have the feeling that if I change something on my own something else will break.
thanks. |
|
|
orb Guest
|
RESOLVED! |
Posted: Thu Mar 26, 2009 11:32 am |
|
|
THANK YOU ALL FOR YOUR HELP, ESPECIALLY VfM.
CCS INC HAS BEEN NOTIFIED OF THE BUG AND A NEW DEVICES DATA FILE HAS BEEN UPDATED. |
|
|
|
|
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
|