CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Target halts prematurely
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

Target halts prematurely
PostPosted: Wed Apr 12, 2017 1:19 pm     Reply with quote

I am compiling code using PCWH 5.069 for a custom design target using a PIC16F1783. I'm using a PICKIT3 and MPLAB 8.90 IDE. The problem I'm having is that the target intermittently halts prematurely and the debugger shows the position in code past the final bracket. IDE output window indicates: Running...
Target halted
No breakpoint set.

Have trimmed the code down to the bare minimum and problem still occuring. MCLR line pulled up to Vdd through 47K resistor and the MCLR appear pretty normal. Using external crystal at 4.0 MHz.

Here's the simplified code. Anyone see anything that would be causing the code to go off into the weeds? Thanks so much for your additional suggestions.

MAIN:

Code:

//Released

#include <16F1783.h>
#include <Ready Ref RX(Rev A).h>


//===========================================================================================================
void Check_Sig_Level(void)
{

int16      RSSI;

Active_Signal= FALSE;
set_adc_channel(0);                            //ready to read sensor input
delay_us(50);                                   //AtoD set-up delay
RSSI =read_adc();                           //get value
if (RSSI <= Squelch_Level)
   Active_Signal= FALSE;
else
   Active_Signal= TRUE;

}
//===========================================================================================================
//===========================================================================================================
//System timing interrupt

#INT_TIMER1                                                   // This function is called every 5ms
void One_Second_timer(void)
{
Sec_Ticks++;

if (Sec_Ticks >= 30)
   {
   Sec_Ticks= 0;
   Sec_Flag= TRUE;
   
   }
}


//===========================================================================================================

//===========================================================================================================
void main()
{
signed int8   value;
int8   msg;
int8   i;

setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_2 );
set_timer1(0);
Sec_Ticks= 0;
Sec_Flag= FALSE;

enable_interrupts(INT_TIMER1);                // Enable timer0 interrupt
disable_interrupts(GLOBAL);                  // Enable all interrupts

//Setup AtoD converter
setup_adc(ADC_CLOCK_INTERNAL|ADC_CLOCK_DIV_8);
setup_adc_ports( sAN0,VSS_VDD);                     //AN0(RSSI)

output_low(RED_LED);

while (1)
   {
   Check_Sig_Level();
   if (Active_Signal==TRUE)
      {   
      delay_cycles(72);
      for(i=0; i<=8; ++i)
         {
            shift_left(&msg,1,input(RX_Data));
         delay_cycles(60);
         }
      Active_Signal= FALSE;
      }
   }
}


//===========================================================================================================


Platform Hardware:

Code:


#device adc=16

#FUSES    XT                      //External crystal 4MHz Osc
#FUSES    NOBROWNOUT               //No brownout reset
#FUSES   NOPUT               //Power up timer off for debugging
#FUSES   NOWDT   



#use delay(xtal=4MHz)         //using 4 MHz crystal

#define EXP_OUT_ENABLE  PIN_B1
#define EXP_OUT_CLOCK   PIN_B2
#define EXP_OUT_DO      PIN_B5
#define NUMBER_OF_74595 1

#define   RX_Data         PIN_C7
#define Red_LED         PIN_B3


#define      Squelch_Level   20000         //squelch level


int8 characters[11] = {0xFE, 0x30, 0xAD, 0xB9, 0x33, 0x9B, 0x1F, 0xB0,0xBF, 0xB3, 0x00  };


int8      Sec_Ticks;
int1      Sec_Flag;
int1      Active_Signal;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 1:55 pm     Reply with quote

Quote:
for(i=0; i<=8; ++i)
{
shift_left(&msg,1,input(RX_Data));
delay_cycles(60);
}

This loop will execute 9 times. Do you want that ? If you want 8 times,
the test should be i < 8.
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 1:58 pm     Reply with quote

That's a fact PCM! Fixed that. See anything else that would cause the halt issue?
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 2:32 pm     Reply with quote

This is wrong:

setup_adc(ADC_CLOCK_INTERNAL|ADC_CLOCK_DIV_8);

You want just ADC_CLOCK_DIV_8. This uses the master clock/8. ADC_CLOCK_INTERNAL selects the internal RC clock (which can't have a divider, and is not recommended above 1MHz).

Things that can be or'ed together, say in the include file. Other things must not be.

However I doubt this will cause a peculiar crash.

Check the actual listing file. What fuses actually are set?.

Target halted, suggests it has actually gone into the higher memory somewhere, and executed the 'sleep' instruction there.

I'd be suspicious of something like an electrical spike. What is being actually 'done' by the I/O lines?. Anything nearby?. What is the supply?.
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 4:56 pm     Reply with quote

Ttelmah: Thank you for the steer. Yes, after some investigation I did use the internal clock and have had no more crashes. I'll fix the AtoD setup issue. I kept thinking it had to do with MCLR noise, but that signal is solid.

All that make a lot of sense.

Thanks so much for your interest. Best regards.
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 6:10 pm     Reply with quote

I'm still puzzled by the 'one second timer' ISR , if called every 5 ms and updated 30 times ,isn't that just 150 ms ??
or am I missing 'something'....????
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Wed Apr 12, 2017 6:12 pm     Reply with quote

Good catch, but just mislabeled.
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 9:26 am     Reply with quote

I am having a strange issue(s) that are plaguing my development of a project. This is a continuing issue involving this particular progect. PCWH version 5.069, MPLab 8.90 IDE, target PIC16F1783, PICKit3 debugger.

Referencing the following code which is simplified to help troubleshooting

If I add a line in the top of my main routine to simply set a flag (Sec_Flag= FALSE;) the last instruction (output_low(RED_LED);) does not execute. This line could be any flag, not just Sec_Flag. Simply commenting this one line out fixes the problem. I think this problem is associated with the earlier problems I was having where the controller went to the weeds.

I beg the group's indulgence. Does anyone here see anything that would cause this problem. Hardware appears to be solid and this problem occurs intermittently. I'm attaching the listing files; one resulting in the issue, one resulting in no issue.

I'm stumped.

Code:


//Released

#include <16F1783.h>
#include <Ready Ref RX(Rev A).h>

//===========================================================================================================
void main()
{
int8   value;
int8   msg;
int8   i;
int16   t;

Sec_Ticks= 0;
Sec_Flag= FALSE;
setup_comparator_1(NC_NC);
setup_comparator_2(NC_NC);
setup_comparator_3(NC_NC);

disable_interrupts(GLOBAL);                  // Enable all interrupts

//Setup AtoD converter
setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports( sAN0);                     //AN0(RSSI)

output_low(RED_LED);

while (True)
   {
//   Sec_Flag= FALSE;   !!!!!!!!!! Line added causes issue !!!!!!!!!!!!!!!!


   set_adc_channel(0);                            //ready to read sensor input
   RSSI =read_adc();                           //get value
   if (RSSI > Squelch_Level)
      {
      output_high(RED_LED);
      delay_cycles(10);
      output_low(RED_LED);

      while (input(RX_Data));               //stay here while high

      output_high(RED_LED);
      delay_cycles(2);
      output_low(RED_LED);


      for(i=1; i<=8; ++i)
         {
         for(i=1; i<=8; ++i)
         delay_cycles(100);
         output_high(RED_LED);
         delay_cycles(10);
         output_low(RED_LED);
          }

      delay_us(1);

      }
   }
}


//===========================================================================================================



Listing of good code:
Code:

CCS PCM C Compiler, Version 5.069, xxxxx               14-Apr-17 10:57

               Filename:   F:\Grimm Ready Ref RX\Ready Ref RX(Rev XX).lst

               ROM used:   166 words (4%)
                           Largest free fragment is 2048
               RAM used:   25 (5%) at main() level
                           35 (7%) worst case
               Stack used: 0 locations
               Stack size: 15

*
0000:  NOP
0001:  MOVLP  00
0002:  GOTO   003
.................... //Released
.................... 
.................... #include <16F1783.h>
.................... //////////// Standard Header file for the PIC16F1783 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... ////        (C) Copyright 1996, 2014 Custom Computer Services          ////
.................... //// This source code may only be used by licensed users of the CCS C  ////
.................... //// compiler.  This source code may only be distributed to other      ////
.................... //// licensed users of the CCS C compiler.  No other use, reproduction ////
.................... //// or distribution is permitted without written permission.          ////
.................... //// Derivative programs created using this software in object code    ////
.................... //// form are not restricted in any way.                               ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC16F1783
.................... 
.................... #list
.................... 
.................... #include <Ready Ref RX(Rev A).h>
.................... #device adc=16
.................... 
.................... #FUSES    INTRC_IO                    //External crystal 4MHz Osc
.................... #FUSES    NOBROWNOUT               //No brownout reset
.................... #FUSES   NOPUT               //Power up timer off for debugging
.................... #FUSES   NOWDT   
.................... 
.................... 
.................... 
.................... #use delay(int=4MHz)         //using 4 MHz crystal
.................... 
.................... #define EXP_OUT_ENABLE  PIN_B1
.................... #define EXP_OUT_CLOCK   PIN_B2
.................... #define EXP_OUT_DO      PIN_B5
.................... #define NUMBER_OF_74595 1
.................... 
.................... #define   RX_Data         PIN_C7
.................... #define Red_LED         PIN_B3
.................... 
.................... 
.................... #define      Squelch_Level   7000         //squelch level
.................... 
.................... 
.................... int8 characters[11] = {0xFE, 0x30, 0xAD, 0xB9, 0x33, 0x9B, 0x1F, 0xB0,0xBF, 0xB3, 0x00  }; 
.................... 
.................... 
.................... int8      Sec_Ticks;
.................... int1      Sec_Flag;
.................... int1      Active_Signal;
.................... 
.................... int16      RSSI;
.................... 
.................... 
.................... //===========================================================================================================
.................... void main()
0003:  MOVLW  6A
0004:  MOVLB  01
0005:  MOVWF  19
0006:  MOVLB  03
0007:  CLRF   0C
0008:  CLRF   0D
0009:  MOVLB  02
000A:  CLRF   12
000B:  CLRF   11
000C:  MOVLW  FE
000D:  MOVLB  00
000E:  MOVWF  20
000F:  MOVLW  30
0010:  MOVWF  21
0011:  MOVLW  AD
0012:  MOVWF  22
0013:  MOVLW  B9
0014:  MOVWF  23
0015:  MOVLW  33
0016:  MOVWF  24
0017:  MOVLW  9B
0018:  MOVWF  25
0019:  MOVLW  1F
001A:  MOVWF  26
001B:  MOVLW  B0
001C:  MOVWF  27
001D:  MOVLW  BF
001E:  MOVWF  28
001F:  MOVLW  B3
0020:  MOVWF  29
0021:  CLRF   2A
.................... {
.................... int8   value;
.................... int8   msg;
.................... int8   i;
.................... int16   t;
.................... 
.................... Sec_Ticks= 0; 
0022:  CLRF   2B
.................... Sec_Flag= FALSE;
0023:  BCF    2C.0
.................... setup_comparator_1(NC_NC);
0024:  MOVLW  3F
0025:  MOVLB  02
0026:  MOVWF  12
0027:  CLRF   11
.................... setup_comparator_2(NC_NC);
0028:  MOVWF  14
0029:  CLRF   13
.................... setup_comparator_3(NC_NC);
002A:  MOVWF  1F
002B:  CLRF   1E
.................... 
.................... disable_interrupts(GLOBAL);                  // Enable all interrupts
002C:  BCF    0B.6
002D:  BCF    0B.7
002E:  BTFSC  0B.7
002F:  GOTO   02D
.................... 
.................... //Setup AtoD converter
.................... setup_adc(ADC_CLOCK_DIV_8);
0030:  MOVLB  01
0031:  BSF    1E.4
0032:  BCF    1E.5
0033:  BCF    1E.6
0034:  BCF    1E.7
0035:  BSF    1D.0
.................... setup_adc_ports( sAN0);                     //AN0(RSSI)
0036:  BCF    1E.0
0037:  BCF    1E.1
0038:  BCF    1E.2
0039:  MOVLW  01
003A:  MOVLB  03
003B:  MOVWF  0C
003C:  MOVLW  00
003D:  MOVWF  0D
.................... 
.................... output_low(RED_LED);
003E:  MOVLB  01
003F:  BCF    0D.3
0040:  MOVLB  02
0041:  BCF    0D.3
.................... 
.................... while (True)
....................    {
.................... //   Sec_Flag= FALSE;
....................    set_adc_channel(0);                            //ready to read sensor input
0042:  MOVLW  00
0043:  MOVWF  78
0044:  MOVLB  01
0045:  MOVF   1D,W
0046:  ANDLW  83
0047:  IORWF  78,W
0048:  MOVWF  1D
0049:  MOVLW  0F
004A:  MOVWF  78
004B:  MOVF   1F,W
004C:  ANDLW  F0
004D:  IORWF  78,W
004E:  MOVWF  1F
....................    RSSI =read_adc();                           //get value
004F:  BSF    1D.1
0050:  BTFSC  1D.1
0051:  GOTO   050
0052:  MOVF   1C,W
0053:  MOVWF  7A
0054:  MOVF   1B,W
0055:  MOVLB  00
0056:  MOVWF  2D
0057:  MOVF   7A,W
0058:  MOVWF  2E
....................    if (RSSI > Squelch_Level)
0059:  MOVF   2E,W
005A:  SUBLW  1A
005B:  BTFSC  03.0
005C:  GOTO   0A3
005D:  XORLW  FF
005E:  BTFSS  03.2
005F:  GOTO   064
0060:  MOVF   2D,W
0061:  SUBLW  58
0062:  BTFSC  03.0
0063:  GOTO   0A3
....................       {
....................       output_high(RED_LED);
0064:  MOVLB  01
0065:  BCF    0D.3
0066:  MOVLB  02
0067:  BSF    0D.3
....................       delay_cycles(10);
0068:  MOVLW  03
0069:  MOVWF  77
006A:  DECFSZ 77,F
006B:  GOTO   06A
....................       output_low(RED_LED);
006C:  MOVLB  01
006D:  BCF    0D.3
006E:  MOVLB  02
006F:  BCF    0D.3
.................... 
....................       while (input(RX_Data));               //stay here while high
0070:  MOVLB  01
0071:  BSF    0E.7
0072:  MOVLB  00
0073:  BTFSS  0E.7
0074:  GOTO   077
0075:  MOVLB  02
0076:  GOTO   070
.................... 
....................       output_high(RED_LED);
0077:  MOVLB  01
0078:  BCF    0D.3
0079:  MOVLB  02
007A:  BSF    0D.3
....................       delay_cycles(2);
007B:  GOTO   07C
....................       output_low(RED_LED);
007C:  MOVLB  01
007D:  BCF    0D.3
007E:  MOVLB  02
007F:  BCF    0D.3
.................... 
.................... 
....................       for(i=1; i<=8; ++i) 
0080:  MOVLW  01
0081:  MOVLB  00
0082:  MOVWF  31
0083:  MOVF   31,W
0084:  SUBLW  08
0085:  BTFSS  03.0
0086:  GOTO   0A2
....................          {
....................          for(i=1; i<=8; ++i) 
0087:  MOVLW  01
0088:  MOVWF  31
0089:  MOVF   31,W
008A:  SUBLW  08
008B:  BTFSS  03.0
008C:  GOTO   093
....................          delay_cycles(100);
008D:  MOVLW  21
008E:  MOVWF  77
008F:  DECFSZ 77,F
0090:  GOTO   08F
0091:  INCF   31,F
0092:  GOTO   089
....................          output_high(RED_LED);
0093:  MOVLB  01
0094:  BCF    0D.3
0095:  MOVLB  02
0096:  BSF    0D.3
....................          delay_cycles(10);
0097:  MOVLW  03
0098:  MOVWF  77
0099:  DECFSZ 77,F
009A:  GOTO   099
....................          output_low(RED_LED);
009B:  MOVLB  01
009C:  BCF    0D.3
009D:  MOVLB  02
009E:  BCF    0D.3
009F:  MOVLB  00
00A0:  INCF   31,F
00A1:  GOTO   083
....................           }
.................... 
....................       delay_us(1);
00A2:  NOP
.................... 
....................       }
00A3:  MOVLB  02
00A4:  GOTO   042
....................    }
.................... }
.................... 
00A5:  GOTO   0A5
.................... 
.................... //===========================================================================================================

Configuration Fuses:
   Word  1: 19E4   INTRC_IO NOWDT NOPUT MCLR NOPROTECT NOCPD NOBROWNOUT NOCLKOUT IESO NOFCMEN
   Word  2: 0EFF   NOWRT NOVCAP PLL_SW STVREN BORV19 NOLPBOR DEBUG NOLVP

   Some fuses have been forced to be compatible with the ICD debugger.



Listing of BAD code:
Code:

CCS PCM C Compiler, Version 5.069, xxxxx               14-Apr-17 10:54

               Filename:   F:\Grimm Ready Ref RX\Ready Ref RX(Rev XX).lst

               ROM used:   167 words (4%)
                           Largest free fragment is 2048
               RAM used:   25 (5%) at main() level
                           35 (7%) worst case
               Stack used: 0 locations
               Stack size: 15

*
0000:  NOP
0001:  MOVLP  00
0002:  GOTO   003
.................... //Released
.................... 
.................... #include <16F1783.h>
.................... //////////// Standard Header file for the PIC16F1783 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... ////        (C) Copyright 1996, 2014 Custom Computer Services          ////
.................... //// This source code may only be used by licensed users of the CCS C  ////
.................... //// compiler.  This source code may only be distributed to other      ////
.................... //// licensed users of the CCS C compiler.  No other use, reproduction ////
.................... //// or distribution is permitted without written permission.          ////
.................... //// Derivative programs created using this software in object code    ////
.................... //// form are not restricted in any way.                               ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC16F1783
.................... 
.................... #list
.................... 
.................... #include <Ready Ref RX(Rev A).h>
.................... #device adc=16
.................... 
.................... #FUSES    INTRC_IO                    //External crystal 4MHz Osc
.................... #FUSES    NOBROWNOUT               //No brownout reset
.................... #FUSES   NOPUT               //Power up timer off for debugging
.................... #FUSES   NOWDT   
.................... 
.................... 
.................... 
.................... #use delay(int=4MHz)         //using 4 MHz crystal
.................... 
.................... #define EXP_OUT_ENABLE  PIN_B1
.................... #define EXP_OUT_CLOCK   PIN_B2
.................... #define EXP_OUT_DO      PIN_B5
.................... #define NUMBER_OF_74595 1
.................... 
.................... #define   RX_Data         PIN_C7
.................... #define Red_LED         PIN_B3
.................... 
.................... 
.................... #define      Squelch_Level   7000         //squelch level
.................... 
.................... 
.................... int8 characters[11] = {0xFE, 0x30, 0xAD, 0xB9, 0x33, 0x9B, 0x1F, 0xB0,0xBF, 0xB3, 0x00  }; 
.................... 
.................... 
.................... int8      Sec_Ticks;
.................... int1      Sec_Flag;
.................... int1      Active_Signal;
.................... 
.................... int16      RSSI;
.................... 
.................... 
.................... //===========================================================================================================
.................... void main()
0003:  MOVLW  6A
0004:  MOVLB  01
0005:  MOVWF  19
0006:  MOVLB  03
0007:  CLRF   0C
0008:  CLRF   0D
0009:  MOVLB  02
000A:  CLRF   12
000B:  CLRF   11
000C:  MOVLW  FE
000D:  MOVLB  00
000E:  MOVWF  20
000F:  MOVLW  30
0010:  MOVWF  21
0011:  MOVLW  AD
0012:  MOVWF  22
0013:  MOVLW  B9
0014:  MOVWF  23
0015:  MOVLW  33
0016:  MOVWF  24
0017:  MOVLW  9B
0018:  MOVWF  25
0019:  MOVLW  1F
001A:  MOVWF  26
001B:  MOVLW  B0
001C:  MOVWF  27
001D:  MOVLW  BF
001E:  MOVWF  28
001F:  MOVLW  B3
0020:  MOVWF  29
0021:  CLRF   2A
.................... {
.................... int8   value;
.................... int8   msg;
.................... int8   i;
.................... int16   t;
.................... 
.................... Sec_Ticks= 0; 
0022:  CLRF   2B
.................... Sec_Flag= FALSE;
0023:  BCF    2C.0
.................... setup_comparator_1(NC_NC);
0024:  MOVLW  3F
0025:  MOVLB  02
0026:  MOVWF  12
0027:  CLRF   11
.................... setup_comparator_2(NC_NC);
0028:  MOVWF  14
0029:  CLRF   13
.................... setup_comparator_3(NC_NC);
002A:  MOVWF  1F
002B:  CLRF   1E
.................... 
.................... disable_interrupts(GLOBAL);                  // Enable all interrupts
002C:  BCF    0B.6
002D:  BCF    0B.7
002E:  BTFSC  0B.7
002F:  GOTO   02D
.................... 
.................... //Setup AtoD converter
.................... setup_adc(ADC_CLOCK_DIV_8);
0030:  MOVLB  01
0031:  BSF    1E.4
0032:  BCF    1E.5
0033:  BCF    1E.6
0034:  BCF    1E.7
0035:  BSF    1D.0
.................... setup_adc_ports( sAN0);                     //AN0(RSSI)
0036:  BCF    1E.0
0037:  BCF    1E.1
0038:  BCF    1E.2
0039:  MOVLW  01
003A:  MOVLB  03
003B:  MOVWF  0C
003C:  MOVLW  00
003D:  MOVWF  0D
.................... 
.................... output_low(RED_LED);
003E:  MOVLB  01
003F:  BCF    0D.3
0040:  MOVLB  02
0041:  BCF    0D.3
.................... 
.................... while (True)
....................    {
....................    Sec_Flag= FALSE;
0042:  MOVLB  00
0043:  BCF    2C.0
....................    set_adc_channel(0);                            //ready to read sensor input
0044:  MOVLW  00
0045:  MOVWF  78
0046:  MOVLB  01
0047:  MOVF   1D,W
0048:  ANDLW  83
0049:  IORWF  78,W
004A:  MOVWF  1D
004B:  MOVLW  0F
004C:  MOVWF  78
004D:  MOVF   1F,W
004E:  ANDLW  F0
004F:  IORWF  78,W
0050:  MOVWF  1F
....................    RSSI =read_adc();                           //get value
0051:  BSF    1D.1
0052:  BTFSC  1D.1
0053:  GOTO   052
0054:  MOVF   1C,W
0055:  MOVWF  7A
0056:  MOVF   1B,W
0057:  MOVLB  00
0058:  MOVWF  2D
0059:  MOVF   7A,W
005A:  MOVWF  2E
....................    if (RSSI > Squelch_Level)
005B:  MOVF   2E,W
005C:  SUBLW  1A
005D:  BTFSC  03.0
005E:  GOTO   0A5
005F:  XORLW  FF
0060:  BTFSS  03.2
0061:  GOTO   066
0062:  MOVF   2D,W
0063:  SUBLW  58
0064:  BTFSC  03.0
0065:  GOTO   0A5
....................       {
....................       output_high(RED_LED);
0066:  MOVLB  01
0067:  BCF    0D.3
0068:  MOVLB  02
0069:  BSF    0D.3
....................       delay_cycles(10);
006A:  MOVLW  03
006B:  MOVWF  77
006C:  DECFSZ 77,F
006D:  GOTO   06C
....................       output_low(RED_LED);
006E:  MOVLB  01
006F:  BCF    0D.3
0070:  MOVLB  02
0071:  BCF    0D.3
.................... 
....................       while (input(RX_Data));               //stay here while high
0072:  MOVLB  01
0073:  BSF    0E.7
0074:  MOVLB  00
0075:  BTFSS  0E.7
0076:  GOTO   079
0077:  MOVLB  02
0078:  GOTO   072
.................... 
....................       output_high(RED_LED);
0079:  MOVLB  01
007A:  BCF    0D.3
007B:  MOVLB  02
007C:  BSF    0D.3
....................       delay_cycles(2);
007D:  GOTO   07E
....................       output_low(RED_LED);
007E:  MOVLB  01
007F:  BCF    0D.3
0080:  MOVLB  02
0081:  BCF    0D.3
.................... 
.................... 
....................       for(i=1; i<=8; ++i) 
0082:  MOVLW  01
0083:  MOVLB  00
0084:  MOVWF  31
0085:  MOVF   31,W
0086:  SUBLW  08
0087:  BTFSS  03.0
0088:  GOTO   0A4
....................          {
....................          for(i=1; i<=8; ++i) 
0089:  MOVLW  01
008A:  MOVWF  31
008B:  MOVF   31,W
008C:  SUBLW  08
008D:  BTFSS  03.0
008E:  GOTO   095
....................          delay_cycles(100);
008F:  MOVLW  21
0090:  MOVWF  77
0091:  DECFSZ 77,F
0092:  GOTO   091
0093:  INCF   31,F
0094:  GOTO   08B
....................          output_high(RED_LED);
0095:  MOVLB  01
0096:  BCF    0D.3
0097:  MOVLB  02
0098:  BSF    0D.3
....................          delay_cycles(10);
0099:  MOVLW  03
009A:  MOVWF  77
009B:  DECFSZ 77,F
009C:  GOTO   09B
....................          output_low(RED_LED);
009D:  MOVLB  01
009E:  BCF    0D.3
009F:  MOVLB  02
00A0:  BCF    0D.3
00A1:  MOVLB  00
00A2:  INCF   31,F
00A3:  GOTO   085
....................           }
.................... 
....................       delay_us(1);
00A4:  NOP
.................... 
....................       }
00A5:  GOTO   043
....................    }
.................... }
.................... 
00A6:  GOTO   0A6
.................... 
.................... //===========================================================================================================

Configuration Fuses:
   Word  1: 19E4   INTRC_IO NOWDT NOPUT MCLR NOPROTECT NOCPD NOBROWNOUT NOCLKOUT IESO NOFCMEN
   Word  2: 0EFF   NOWRT NOVCAP PLL_SW STVREN BORV19 NOLPBOR DEBUG NOLVP

   Some fuses have been forced to be compatible with the ICD debugger.


PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 10:14 am     Reply with quote

Could you point out exactly what line doesn't execute. Because the
actual "last line" is the delay_us(1); line. Post the main() program
and add a comment to the line that doesn't execute.

2nd thing. You have this weird construct here:
Quote:
for(i=1; i<=8; ++i)
{
for(i=1; i<=8; ++i)
delay_cycles(100);
output_high(RED_LED);
delay_cycles(10);
output_low(RED_LED);
}

You have a 2nd for() loop stuck in there, using the same index variable 'i'.
The inner loop will finish with 'i' set to 8. This will make the outer loop
end after the first pass. Is this what you want ?

3rd. This comment should be corrected:
Quote:
disable_interrupts(GLOBAL); // Enable all interrupts
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:01 am     Reply with quote

PCM: Thanks for your reply. It's been a long time since I've had this amount of randomness in performance. Yes, I did have the inside index the same index as the outside. Fixed now.. When it works, it works as expected. I'm just trying to mark the positions of operation on a scope using a probe on an existing LED.

Frustrating thing now the code run once through the main routine and drops past the last bracket and halts.

Just randomness! I'm almost to the point that I think I have a bad PIC!

Before, when I added any flag set to true on the first line in MAIN, the code did not execute the final output_high(Red_LED); (marked). Take out that line and the code runs as expected by executing the final output_high(Red_LED);

Believe me, I stripped-out a lot of code to find this (these) issues. Here's the code, fixed as you requested.

Thanks so much for your eyes on this.

Code:

//Released

#include <16F1783.h>
#include <Ready Ref RX(Rev A).h>

//===========================================================================================================
void main()
{
int8   value;
int8   msg;
int8   i;
int16   t;

Sec_Ticks= 0;
Sec_Flag= FALSE;
setup_comparator_1(NC_NC);
setup_comparator_2(NC_NC);
setup_comparator_3(NC_NC);

enable_interrupts(GLOBAL);                  // Enable all interrupts

//Setup AtoD converter
setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports( sAN0);                     //AN0(RSSI)

output_low(RED_LED);

while (True)
   {
//   Sec_Flag= FALSE;     !!!!!!! Add this line and the last output_high(Red_LED); doesn't execute
   set_adc_channel(0);                            //ready to read sensor input
   RSSI =read_adc();                           //get value
   if (RSSI > Squelch_Level)
      {
      output_high(RED_LED);
      delay_cycles(10);
      output_low(RED_LED);

      while (input(RX_Data));               //stay here while high

      output_high(RED_LED);
      delay_cycles(2);
      output_low(RED_LED);


      for(i=1; i<=8; ++i)
         {
         for(t=1; t<=8; ++t)
            delay_cycles(100);
         output_high(RED_LED);
         delay_cycles(10);
         output_low(RED_LED);   //!!!!!!!!! this line doesn't execute !!!!!
          }

      delay_us(1);

      }
   }
}



And the .h file:

Code:

#device adc=16

#FUSES    INTRC_IO                    //External crystal 4MHz Osc
#FUSES    NOBROWNOUT               //No brownout reset
#FUSES   NOPUT               //Power up timer off for debugging
#FUSES   NOWDT   



#use delay(int=4MHz)         //using 4 MHz crystal

#define EXP_OUT_ENABLE  PIN_B1
#define EXP_OUT_CLOCK   PIN_B2
#define EXP_OUT_DO      PIN_B5
#define NUMBER_OF_74595 1

#define   RX_Data         PIN_C7
#define Red_LED         PIN_B3


#define      Squelch_Level   7000         //squelch level


int8 characters[11] = {0xFE, 0x30, 0xAD, 0xB9, 0x33, 0x9B, 0x1F, 0xB0,0xBF, 0xB3, 0x00  };


int8      Sec_Ticks;
int1      Sec_Flag;
int1      Active_Signal;

int16      RSSI;

Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:14 am     Reply with quote

You do realise, that:
Code:

         for(t=1; t<=8; ++t)
            delay_cycles(100);

Is just equivalent to

delay_cycles(700);

.......
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:18 am     Reply with quote

Yes, I know. That's another thing! Delays (us and ms) were unpredictable.
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:24 am     Reply with quote

Ttelmah: Am I wrong?

Syntax:
delay_cycles (count)

Parameters:
count - a constant 1-255
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:37 am     Reply with quote

Tell us how you're testing this. Are you compiling with MPLAB set to
Debug mode (in the dropdown box on the MPLAB menu bar) ?
Are you stepping through the code in debug, or using Animate ?
Or are you clicking on the Run button ?

What happens if you compile in Release mode and run it ?
Does it then work ?

Tell us about the board. Did you build it yourself or did you buy it ?
If you bought it, post a link to the board's webpage.

What is the Vdd voltage of the PIC on the board ?

Is the board self-powered, or is the Pickit used to supply power ?
If self powered, describe the power supply.

If you built the board, does it have 100 nF cap on the Vdd pin ?
JerryR



Joined: 07 Feb 2008
Posts: 167

View user's profile Send private message

PostPosted: Fri Apr 14, 2017 11:52 am     Reply with quote

OK, all good questions.


I've tried both, compiling in Debug and release mode. Same thing.

If I single-step through code- steps through Main loop once then falls right through all end brackets and ends up Halting. Same hing also happens in Animate. Running results in Run then halt.


What happens if you compile in Release mode and run it ?
Does it then work ?

Same thing- Release and Debug modes

Proprietary design. Pretty simple- Vdd is 4.98volts. MCLR pulled-up to 4.92 volts through 47K resistor. Known good PICKit3. I'll try both an ICD3 and realICE later to see if that may be the issue.

Board is self-powered. Good clean DC on microcontroller, bypassed with 0.1uF at the chip. Regulator 7805 from 24 volts bus. Well bypassed and loaded approximately 50mA.

Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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