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 support@ccsinfo.com

Help - Dont find the glue with Buffer Array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Andreas
Guest







Help - Dont find the glue with Buffer Array
PostPosted: Sun Oct 10, 2004 10:40 am     Reply with quote

Hi Friends,

I am still working on a rather large Project with teh 18F8720 and having
again a problem with RAM Buffer alloction.

Pls see in my code the line where I am defining a new BufferArray

Line : Buffer[256];

When I remove this line the whole program runs fine, after including
this line the program just makes nuts !!

The attached code is ofcourse a testcode with all the major parts removed, but also this reduced code makes the same trouble.

If You would like to test this code >You just need the processor and one attched com cable.
First it puts out the const arry and than it should only output the input changes

After I put this definition line in the output lines from the const array
is allready scrambled.

PLEASE HELP



Andreas


Code:
#include "/Test/Fern.h"
#include <string.h>
#include <stdio.h>


byte Inport[4] = {0xff,0xff,0xff,0xff};         // Data Array for Actual Input Status

                        // Variable Definitions

#org 0x6000,0x7000

static const char Pin_def[33][34] = {"Eingang  0 Aktiv Test Definition","Eingang  1 Aktiv Test Definition",
"Eingang  2 Aktiv Test Definition","Eingang  3 Aktiv Test Definition","Eingang  4 Aktiv Test Definition",
"Eingang  5 Aktiv Test Definition","Eingang  6 Aktiv Test Definition","Eingang  7 Aktiv Test Definition",
"Eingang  8 Aktiv Test Definition","Eingang  9 Aktiv Test Definition","Eingang 10 Aktiv Test Definition",
"Eingang 11 Aktiv Test Definition","Eingang 12 Aktiv Test Definition","Eingang 13 Aktiv Test Definition",
"Eingang 14 Aktiv Test Definition","Eingang 15 Aktiv Test Definition","Eingang 16 Aktiv Test Definition",
"Eingang 17 Aktiv Test Definition","Eingang 18 Aktiv Test Definition","Eingang 19 Aktiv Test Definition",
"Eingang 20 Aktiv Test Definition","Eingang 21 Aktiv Test Definition","Eingang 22 Aktiv Test Definition",
"Eingang 23 Aktiv Test Definition","Eingang 24 Aktiv Test Definition","Eingang 25 Aktiv Test Definition",
"Eingang 26 Aktiv Test Definition","Eingang 27 Aktiv Test Definition","Eingang 28 Aktiv Test Definition",
"Eingang 29 Aktiv Test Definition","Eingang 30 Aktiv Test Definition","Eingang 31 Aktiv Test Definition",
"Eingang 32 Aktiv Test Definition"};



BYTE cnt1,cnt2,cnt3;
BYTE ico;
BYTE ic;
BYTE i;
Byte c;
BYTE KeyIn;             // InputBuffer
int16 Tim3C;            // Timer 3 Counter for Sendb Flag
int16 IORead;           // Counter for Periodic Input Reads
BYTE Tout;              // Output Bit Register
BYTE Status;
byte Reg;
byte Seco;
char Disp[28];
char Disp1[34];


int8 Buffer[256];  // THIS LINE MAKES TROUBLES !!!!!!!!


int8 InBuf;
int8 OutBuf;
int8 Bufcnt;

Char Level;
Byte index;


int timeold;
int KeyTime;

int32 AllIn = 00;
int32 AllOld = 0xFFFFFFFF;
int32 AllBou = 0x00;
int32 AllLev = 0x00;
int32 AllCheck = 0x00;
int32 AllDis = 00;
int32 DebZero = 0x00;
int8  DebCnt[33];
int8  DebPos[33];

int32 Labl;


                        // Definitions for FLAGS
int1 IODis;             // Flag for Displaying Input Status
int1 IOR;               // Flag to Set Next Input Read Sequenz
int1 IOBou;             // I/O Bounce Flag
int1 DisIO;             // Flag Set if Input Changes Detected
int1 SendB;             // 1ms Flag for Sending Time and Date to Display
int1 SetOut;            // Flag for Setting Output Bits
int1 IOBounce;          // Flag to Test for Bouncing
int1 NoUpd;
int1 Bounce;            // Flag after Bouncecounter is timed out



Byte Debounce = 40;      // Debounce Counter
Byte IOScan= 50;        // IOScan Counter = 50 ms - Fixed Scanrate


int1 Keypressed = false;
int1 KeyOK = false;



#int_ext                // External Interrupt 0 - RTC Interrupt
void Ext0_isr()
{
Output_High(Pin_c3);    // Set Test PIN_C3
SetOut = true;          // Flag for Display Routine
 sendb = true;
tim3c = 1000;
}


#int_timer3
void timer3_isr() {

set_timer3(0xfA20);     // Setupt Timer3 as ms Timer FA20


   if (--IORead==0)     // If Time elapsed than restart and Set IORead Flag
      {
      IORead = IOScan;
      IOR = true;
      }

Bounce = true;       // Set Flag every 1ms for Debounce Checker
}





void IO_Read()                // Read All Input Ports
{
   Byte cnt;
      Output_High(E_Input);    //Enable All Input Buffers
      delay_cycles(3);
      Output_Low(OE_1);       //Select Input Buffer 1
      delay_cycles(3);
      Inport[0] = input_D();
      output_High(OE_1);
      Output_Low(OE_2);       //Select Input Buffer 2
      delay_cycles(3);
      Inport[1] = input_D();
      output_High(OE_2);
      Output_Low(OE_3);       //Select Input Buffer 3
      delay_cycles(3);
      Inport[2] = input_D();
      output_High(OE_3);
      Output_Low(OE_4);       //Select Input Buffer 4
      delay_cycles(3);
      Inport[3] = input_D();
      output_High(OE_4);
      Output_Low(E_Input);    //Disable All Input Buffers

      AllIn = 0;              // Convert 4 Input Values to one 32Bit Value !
   for (cnt=4; cnt > 0; --cnt)
      {
      AllIn <<=8;
      AllIn |= Inport[cnt-1];
      }
}

void main()
{
      // Set All Output Signals to Init Values
      // Flash Interface Signals

Output_High(RReset);          // RAM Reset
Output_Low(RReset);           // RAM Reset
Output_High(RReset);          // RAM Reset
Output_High(CLK);


Output_High(ROut_E);          // RAM Output Enable
Output_High(RDir);            // RAM Data Direction Set to Write to Flash
Output_High(E_Out_Buffer);    // Disable Output Driver
Output_Low(WP);               // Page Write Protect

Output_High(RB_1);             // Ready /-Busy RAM
Output_High(RB_2);
Output_High(RB_3);
Output_High(RB_4);

Output_High(CS_1);             // -Chip Select for RAM
Output_High(CS_2);
Output_High(CS_3);
Output_High(CS_4);

      // Output Driver Interface
Output_Low(E_OUT);            // Disable Output Latch
OutLatch = 0x00;              // Clear Output Latch Variable

      // LED Backlight Control

      // General Setups

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,0xFF,8);
   setup_timer_3(T3_INTERNAL|T3_DIV_BY_4);
 //  setup_timer_4(T4_INTERNAL|T4_DIV_BY_8);
   setup_ccp2(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   set_timer3(0xFA20);

   output_High(PIN_C2);       // Test Output Signal



Tout = 0;                           //  Output Bit Register

IORead = 50;                        // Threshold for Input Reads
IODis = false;                      // Flag for Input Status Write to Display
IOBou = false;

set_tris_c(0x40);                   // Set RX1 Pin to Input
set_tris_b(0x01);
CCP_2_LOW = 0x10;

Set_Tris_H(0xff);                   // Set All Keyboard Lines to Input

delay_ms(5);
delay_ms(1);
SetOut = false;
NoUpd = true;

Seco = 0;
tim3c = 1000;                       // Second Timer


Output_High(CLK);                   // Set Clk for Polarity Low Timing


         // Setup for Interrupts
         //enable_interrupts(int_timer3);

         // Setup for Ext Interrupt 0
         // Used for Periodic Int from RTC !!

ext_int_edge(0,H_TO_L);             // Select Edge
Output_High(PIN_B0);                // Set Pin to High Imp to allow Interrupt !!


for (cnt2=0;cnt2 <33; ++cnt2)
    {
    strcpy(Disp1,Pin_def[cnt2]);
    fprintf(com1,Disp1);
    fprintf(com1," \n\r");
    }


labl = label_address(Pin_def);


Output_High(WP);
delay_ms(2);


fprintf(com1," \n\r");
delay_ms(500);

enable_interrupts(global);
enable_interrupts(int_Ext);         // Enable External Interrupt 0
enable_interrupts(int_timer3);

InBuf = 1;
OutBuf = 1;
Bufcnt = 0;

while(1)
{



if (sendb) {                        // If Second Timer Elapsed then Display Time and Date
      sendb = false;
}

if (SetOut) {
}


if (Bounce)                            // Check every 1ms for Debounce Counting
{
   if (IOBou)                          // Check only if at least 1 Input is for Debouncing
   {
   IOBounce = false;                   // Reset Bounce Flag
   Bounce = false;
   {
//                Output_High(PIN_J1);

   for (ic=0;ic <=32; ++ic)
       {
       if (Debcnt[ic] !=0)
          {
           --Debcnt[ic];                    // Decrement each Debounce ctr
           if (Debcnt[ic] == 0)
               {
               (bit_set(DebZero,ic));  // Mark the Debounced Bit
               IOBounce = true;        // If at least one counter reached Zero set Flag !
               Bounce = true;
               }
          }
       }
   }
   }
//         Output_Low(PIN_J1);
}



if (IOBounce)                                                  // Debounce Counter expired
   {
   NoUpd = true;

                   Output_High(PIN_J1);

   IO_Read();
   IOBou = false;                                               // Read All Inputs again
   for (cnt1=0;cnt1 <=32; ++cnt1)
           {
            if (bit_test(AllBou,cnt1) ==1)                       // Check for Bounce Bits
               {
               if (bit_test(AllIn,cnt1) == bit_test(AllLev,cnt1))   // If new Input is equal all Level
                  {
                     if (bit_test(AllIn,cnt1))  Level = '1';
                        else Level= '0';
                        bit_clear(AllBou,cnt1);
                        index = cnt1+1;
                        cnt3 = index;
                        strcpy(Disp1,Pin_def[cnt3]);
                        fprintf(com1,Disp1);
                        fprintf(com1,"   %U  ",cnt3);
                        fprintf(com1," %C ",Level);
                  }
               }
           }
      AllOld = AllLev;
      AllBou = 0x00;       // Reset All Bounce Flags
      IOBounce = false;
      IOBou = false;
      NoUpd = false;

               Output_Low(PIN_J1);
}



if (IOR) {
   NoUpd = true;                            // If Input Read Flag Set _ Read all Inputs and Compare to previous Read !
   IO_Read();
   if (AllIn != AllOld)                     // Inputs Changed
      {
      AllLev = AllIn;                       // Store Input Level
      AllCheck = AllIn ^ AllOld;            // In XOR Old to see which Input changed
           for (ico=0;ico <32; ++ico)       // Check all Bits for changes
               {
               if (bit_test(AllCheck,ico))  // Test on Input changes
                  {
                   (bit_set(AllBou,ico));   // Mark Changed Input
                   Debcnt[ico] = Debounce;  // Set for each changed Input the debounce Counter
                   IOBou = True;            // Set Debounce Flag if at least one input changed
                   Bounce = true;
                  }
               }
      }
   IOR = false;                             // Reset Input Read Flag !!!
   NoUpd = false;
}



} //while(1)
} //main
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 10, 2004 12:02 pm     Reply with quote

Read the errata for the device. If you are having strange results by just changing a small portion of the code, this might be your cause.
Guest








PostPosted: Sun Oct 10, 2004 5:19 pm     Reply with quote

Andreas,
Your const string is (to say the least) horrible, !
With very little efort you can produce the same results using sprintf()

Something like this...
sprintf( buf,"Eingang %d Aktiv Test Definition", InputNumber );
Will reduce your code size by about 33 * 34 bytes = 1100 bytes. !

If your code fails because of the Buffer[256] declaration, then try looking at the projectname.SYM file and see if you r other memory usage allows for a 256 byte buffer.

Also consider using #locate which forces the compiler to allocate memory where you want it.

char Buffer[256];
#locate Buffer = 0Xyour_adress_in_HEX
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 10, 2004 7:06 pm     Reply with quote

Quote:

Something like this...
sprintf( buf,"Eingang %d Aktiv Test Definition", InputNumber );
Will reduce your code size by about 33 * 34 bytes = 1100 bytes. !


Those are just initial values. The user has the option to change the string. That is why he did it the way he did.

Look at the date code on the chip. If it starts with 03 then that chip is very suspect to the errata. I had huge problems with the 18F6720. The bad chips are still surfacing. Left a bad taste in my mouth. I just got back from Freescale's (Motorola) Embedded Connectivity Summit. Might have to give them a shot.
Andreas
Guest







PostPosted: Sun Oct 10, 2004 10:39 pm     Reply with quote

Hi Mark,

You are right about the reason why i am using this f. const array, I will give it try with the locate statemant but I am not shure how to use it at the ram space.

I am very mnuch disappointed about the way how ´CCS is treating compiler faults :
Although i can understand that nothing is perfect but having missbehaviour without telling absolutly nothing that is really bitching me.



TRhe date code is definitly not the case , I had this problem allready with an other projedct , took me about 4 month to find the problem and had big troubles to convince the customer that the fault was at microichip at not at the programmer.

best regards and thanks for Your thoughts.

Andreas
Guest








Might be compiler bug
PostPosted: Sun Oct 10, 2004 10:48 pm     Reply with quote

3.210 A PIC18 problem with arrays exactly 256 bytes is fixed Twisted Evil

Which version are you using ? go get the latest 3.212 !

Try

int8 Buffer[257];

or

int8 Buffer[255];

to see if nuts become fruits Mr. Green

Best wishes
Andreas
Guest







PostPosted: Sun Oct 10, 2004 11:37 pm     Reply with quote

Hello Guest,

This looks like its not the problem, also defining only 20 Bytes
generates the problem


best regards
ANdreas
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Oct 11, 2004 12:01 am     Reply with quote

Post your .SYM file (with the 256-byte array included in your code), it may give us some clues.
Andreas
Guest







PostPosted: Mon Oct 11, 2004 12:49 am     Reply with quote

Hi Haplo

Here is the Sym File. It looks okay

bets regards

Andreas

Code:
000     @SCRATCH
001     @SCRATCH
001     _RETURN_
002     @SCRATCH
003     @SCRATCH
004     @SCRATCH
005     @INTERRUPT_AREA
006     @INTERRUPT_AREA
007     @INTERRUPT_AREA
008     @INTERRUPT_AREA
009     @INTERRUPT_AREA
00A     @INTERRUPT_AREA
00B     @INTERRUPT_AREA
00C     @INTERRUPT_AREA
00D     @INTERRUPT_AREA
00E     @INTERRUPT_AREA
00F     @INTERRUPT_AREA
010     @INTERRUPT_AREA
011     @INTERRUPT_AREA
012     @INTERRUPT_AREA
013     @INTERRUPT_AREA
014     @INTERRUPT_AREA
015     @INTERRUPT_AREA
016     @INTERRUPT_AREA
017.0   NoUpdate
017.1   IODis
017.2   IOR
017.3   IOBou
017.4   DisIO
017.5   SendB
017.6   SetOut
017.7   IOBounce
018     OutLatch
019-01A strtok.save
01B-01E Inport
01F     cnt1
020     cnt2
021     cnt3
022     ico
023     ic
024     i
025     c
026     KeyIn
027-028 Tim3C
029-02A IORead
02B     Tout
02C     Status
02D     Reg
02E     Seco
02F-04A Disp
04B-06C Disp1
06D-16C Buffer
16D     InBuf
16E     OutBuf
16F     Bufcnt
170     Level
171     index
172     timeold
173     KeyTime
174-177 AllIn
178-17B AllOld
17C-17F AllBou
180-183 AllLev
184-187 AllCheck
188-18B AllDis
18C-18F DebZero
190-1B0 DebCnt
1B1-1D1 DebPos
1D2-1D5 Labl
1D6.0   NoUpd
1D6.1   Bounce
1D6.2   Keypressed
1D6.3   KeyOK
1D7     Debounce
1D8     IOScan
1D9-1DA @MUL1616.P1
1D9     IO_Read.cnt
1D9     main.@SCRATCH
1DA     @PRINTF_U_9600_31766_31767.P1
1DA     @delay_ms1.P2
1DA     IO_Read.@SCRATCH
1DA     main.@SCRATCH
1DB-1DC @MUL1616.P1
1DB     @PRINTF_U_9600_31766_31767.P2
1DB     main.@SCRATCH
1DC     @DIV88.P1
1DC     main.@SCRATCH
1DD     @DIV88.P1
1DD     @MUL1616.@SCRATCH
1DE     @DIV88.@SCRATCH
F71-F72 CCP_5
F71     CCP_5_LOW
F72     CCP_5_HIGH
F74     CCP_4_LOW
F74-F75 CCP_4
F75     CCP_4_HIGH
F83     PSP_DATA
FB4.6   C1OUT
FB4.7   C2OUT
FB8-FB9 CCP_3
FB8     CCP_3_LOW
FB9     CCP_3_HIGH
FBB-FBC CCP_2
FBB     CCP_2_LOW
FBC     CCP_2_HIGH
FBE-FBF CCP_1
FBE     CCP_1_LOW
FBF     CCP_1_HIGH

00E2  @delay_ms1
6000  @const142
00A2  Ext0_isr
00B8  timer3_isr
012C  IO_Read
026E  main
010A  @MUL1616
01C8  @DIV88
01F4  @PRINTF_U_9600_31766_31767
026E  @cinit

Project Files:
    D:\Test\Fern.c
    \Test\Fern.h
    C:\Programme\PICC\devices\18F8720.h
    C:\Programme\PICC\drivers\string.h
    C:\Programme\PICC\drivers\stddef.h
    C:\Programme\PICC\drivers\ctype.h
    C:\Programme\PICC\drivers\stdio.h

Compiler Settings:
    Processor:      PIC18F8720
    Pointer Size:   16
    ADC Range:      0-255
    Opt Level:      9
    Short,Int,Long: 1,8,16
    ICD Provisions: Yes

Output Files:
    Errors:      D:\Test\Fern.err
    INHX32:      D:\Test\Fern.HEX
    Symbols:     D:\Test\Fern.SYM
    List:        D:\Test\Fern.LST
    Debug/COFF:  D:\Test\Fern.cof
    Call Tree:   D:\Test\Fern.tre
    Statistics:  D:\Test\Fern.sta
Guest








Try this
PostPosted: Mon Oct 11, 2004 8:11 pm     Reply with quote

I did not study your sym fiule in detail but the chip you are using has 3840 bytes of RAM.

Looks like you have some RAM to spare.

char Buffer[256];
#locate Buffer=0X300

Your buffer should now start at location 0X300
The compiler will reserve that space and should leave it alone. Remember if you locate more ram YOU have to mange the locations and make sure you are not walking over other RAM which has been #locate

If that does not works try 0X400 etc.

Also make sure your code does not have a runtime error !
If you are exceeding the buffer with read/writes your code will blow up...

I'm using the 6720 and have two 512 byte buffers with NO problems, my SYM file is a lot longer than yours !.... I had problems before someone (forget who, but thanks!) put me onto the #locate and told me to start larger buffers at around 0X300, try it, it worked for me.

Good luck.
Hans W
Andreas
Guest







PostPosted: Tue Oct 12, 2004 12:59 am     Reply with quote

Hi Guest,

thanks for Your reply, will try it in the next hours, I really hope to get that thing running now.

In case this will help, I have to consider where to got in the future. With a compiler that makes errors without telling you anything is really crazy !

Will keep You informed about the result.

BTW, can You contact me directly, like to discuss some points ?

My email: apock@csie-data.com

best regards
Andreas
Guest








PostPosted: Tue Oct 12, 2004 6:53 am     Reply with quote

Hi, Andreas:

Which version are you using ?

Have you tried version 3.212 ?

Best wishes
Andreas
Guest







PostPosted: Tue Oct 12, 2004 1:19 pm     Reply with quote

Hello Guest,

I am using 3.209, had no time to try it until now

best regards and thanks for your thoughts

Andreas
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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