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

Unable to print result

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

Unable to print result
PostPosted: Thu Apr 01, 2010 12:29 pm     Reply with quote

Code:

#include<18F452.h>
#include<stdlib.h>
#include<stdlibm.h>
#include<stdio.h>
#include<math.h>

#fuses HS,WDT,NOPROTECT,NOLVP
#use delay(clock=20000000,RESTART_WDT)
#use rs232(RESTART_WDT,TIMEOUT=1000,baud=38400, rcv=PIN_C7, STREAM=Input)
#use rs232(RESTART_WDT,TIMEOUT=1000,baud=9600, xmit=PIN_C6, STREAM=Output)

//Function Definition
float GetMaxValue(float*,int);
float GetMinValue(float*,int);

//Structuring Elements
int length_Bo=26;
int length_Bc=38;

//Clear the values after getting from adc
float OriginalECGSignal[90]={0
0.00105932203389831
0.00211864406779661
0.00317796610169492
0.00423728813559322
0.00529661016949153
0.00635593220338983
0.00741525423728814
0.00847457627118644
0.0451977401129944
0.0819209039548023
0.118644067796610
0.155367231638418
0.192090395480226
0.228813559322034
0.265536723163842
0.302259887005650
0.338983050847458
0.302259887005650
0.265536723163842
0.228813559322034
0.192090395480226
0.155367231638418
0.118644067796610
0.0819209039548022
0.0451977401129943
0.00847457627118644
0.00776836158192090
0.00706214689265537
0.00635593220338983
0.00564971751412429
0.00494350282485876
0.00423728813559322
0.00353107344632768
0.00282485875706215
0.00211864406779661
0.00141242937853107
0.000706214689265537
0,
-0.0960451977401130,
-0.192090395480226,
-0.288135593220339,
-0.0734463276836158,
0.141242937853107,
0.355932203389831,
0.570621468926554,
0.785310734463277,
1,
0.737288135593220,
0.474576271186441,
0.211864406779661,
-0.0508474576271187,
-0.313559322033898,
-0.576271186440678,
-0.838983050847458,
-0.559322033898305,
-0.279661016949153,
0,
0.000736919675755343,
0.00147383935151069,
0.00221075902726603,
0.00294767870302137,
0.00368459837877671,
0.00442151805453206,
0.00515843773028740,
0.00589535740604274,
0.00663227708179809,
0.00736919675755343,
0.00810611643330877,
0.00884303610906411,
0.00957995578481946,
0.0103168754605748,
0.0110537951363301,
0.0117907148120855,
0.0125276344878408,
0.0132645541635962,
0.0140014738393515,
0.0147383935151069,
0.0154753131908622,
0.0162122328666175,
0.0169491525423729,
0.0348399246704332,
0.0527306967984934,
0.0706214689265537,
0.0885122410546139,
0.106403013182674,
0.124293785310734,
0.142184557438795,
0.160075329566855,
0.177966101694915
};

int main()
{
//length of Signal
float AfterBaselineECG[5];
int n;
int m;
int i;
float * IntermediateArrayOpening;
float * IntermediateArrayClosing;
float * OpeningArray1;
float * OpeningArray2;
float * ClosingArray1;
float * ClosingArray2;

IntermediateArrayOpening=malloc(26*sizeof(float));
IntermediateArrayClosing=malloc(38*sizeof(float));
OpeningArray1=malloc(77*sizeof(float));
OpeningArray2=malloc(64*sizeof(float));
ClosingArray1=malloc(44*sizeof(float));
ClosingArray2=malloc(24*sizeof(float));

for(i=0;i<77;i++){
OpeningArray1[i]=0;
}

for(i=0;i<64;i++){
OpeningArray2[i]=0;
}

for(i=0;i<44;i++){
ClosingArray1[i]=0;
}
for(i=0;i<24;i++){
ClosingArray2[i]=0;
}

for(n=12;n<77;n++){
   for(m=0;m<length_Bo;m++){
    IntermediateArrayOpening[m]=OriginalECGSignal[n-12+m];
   }
   OpeningArray1[n]=GetMinValue(IntermediateArrayOpening,length_Bo-1);
}

for(n=12;n<64;n++){
   for(m=0;m<length_Bo;m++){
    IntermediateArrayOpening[m]=OpeningArray1[n-12+m];
   }
   OpeningArray2[n]=GetMaxValue(IntermediateArrayOpening,length_Bo-1);
}

free(IntermediateArrayOpening);
free(OpeningArray1);

for(n=19;n<44;n++){
   for(m=0;m<length_Bc;m++){
    IntermediateArrayClosing[m]=OpeningArray2[n-19+m];
   }
   ClosingArray1[n]=GetMaxValue(IntermediateArrayClosing,length_Bc-1);
}
free(OpeningArray2);

for(n=19;n<24;n++){
   for(m=0;m<length_Bc;m++){
    IntermediateArrayClosing[m]=ClosingArray1[n-19+m];
   }
   ClosingArray2[n]=GetMinValue(IntermediateArrayClosing,length_Bc-1);
}

free(IntermediateArrayClosing);
free(ClosingArray1);
fprintf(Output,"%9.5f",ClosingArray2[19]);

for(n=0;n<5;n++){
   AfterBaselineECG[n]=OriginalECGSignal[85+n]-ClosingArray2[19+n];
  }

free(ClosingArray2);

return 0;
}


float GetMaxValue(float *IntermediateArray,int WindowSize)
{
int8 i=0;
float MaxValue;
MaxValue=IntermediateArray[0];

for(i=0;i<WindowSize;i++)
{
if(MaxValue < IntermediateArray[i])   
   {
   MaxValue=IntermediateArray[i];
   }
}
return MaxValue;
}


float GetMinValue(float *IntermediateArray,int WindowSize)
{
int8 i=0;
float MinValue;

MinValue=IntermediateArray[0];

for(i=0;i<WindowSize;i++)
{
if(MinValue > IntermediateArray[i])   
   {
   MinValue=IntermediateArray[i];
   }
}

return MinValue;
}

I have written the above code. It works fine in any normal C compiler and gives the desired result but it doesn't work in the micro controller.
Initially I thought the code is too long and the WDT causes the code to start again before finishing. I tested this theory by lighting an LED after each for loop and switched each one off before the return statement. It worked fine all LEDs lit and were switched off indicating the entire code runs till the end but as soon as I try printing result on hyperterminal the code stops working. ANY IDEA WHATS GOING ON? ??
Please help me.
_________________
Regards,
Nasreen
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 01, 2010 12:45 pm     Reply with quote

Always post your compiler version if you suspect a compiler bug.
http://www.ccsinfo.com/devices.php?page=versioninfo
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

PostPosted: Thu Apr 01, 2010 1:56 pm     Reply with quote

my compiler version is 4.057

i don't think it is a compiler bug. I think I am missing out on something in relation to sending data to the PC.
_________________
Regards,
Nasreen
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 01, 2010 2:11 pm     Reply with quote

I installed vs. 4.057, and I modified your program to get rid of the two
software UART streams. Instead, I created one hardware UART stream
as shown below:
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=Output)
 

I also got rid of your WDT fuse. I changed it to NOWDT.

Then I compiled and ran the program in MPLAB simulator, using the
"UART1" feature of the simulator to display printf outpt in the Output Window.
It displayed this result:
Quote:
0.0007

This means there is nothing inherently causing it to lockup.
The math routines are not locking up. The printf does send
output to the hardware UART.

Try these changes and see if it works. If you are connecting the board
to a PC, you need a MAX232-type chip between the PIC and the PC.
If you don't have one, there are ways to do it without such a chip.
But normally, your board should have a MAX232-type chip on it.
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 1:24 am     Reply with quote

Thank you very much.
I have a max232 and will try the changes out and let you know Smile
_________________
Regards,
Nasreen
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 2:49 am     Reply with quote

#use delay(clock=20000000,RESTART_WDT)

Should I remove RESTART_WDT from the above statement also when I change the fuse to NOWDT???
_________________
Regards,
Nasreen
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 3:21 am     Reply with quote

It still doesn't work :((
and when i change the fuse to NOWDT it starts giving extremely unpredictable behavior. The test LEDs that I am lighting in the code light up sometimes and sometimes they don't.
so i guess i have to use WDT, got any other ideas?
Thanks
_________________
Regards,
Nasreen
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 9:53 am     Reply with quote

Start with a simple program that blinks an LED. Make that program
work reliably. Then try your program. Example:
Code:

#include <18F452.h>
#fuses HS, NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)   
//====================================
void main()
{

while(1)
  {
   output_high(PIN_B0);   
   delay_ms(500);

   output_low(PIN_B0);
   delay_ms(500);
  }

}
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 12:00 pm     Reply with quote

LED code works fine. I have tried lighting LEDs in between my code too that also works. I am just unable to print the output. If anyone could help me with that I would be very grateful. Is there anything wrong with my code?!!?
_________________
Regards,
Nasreen
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 12:18 pm     Reply with quote

Have you tested the rs232 output, to prove that it works ?
Try this simple test program.
Code:

#include <18F452.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//======================================
void main(void)
{

printf("Hello World\n\r");

while(1);

 
 
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 12:57 pm     Reply with quote

yes i have done this too.
have you reviewed my code? is there anything wrong with it?
_________________
Regards,
Nasreen
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 02, 2010 1:11 pm     Reply with quote

I copied and pasted the code from your first post into MPLAB.
I didn't change anything in it. I installed vs. 4.057. It compiled
with no errors. I programmed it into an 18F452 with an ICD2.
The 18F452 is plugged into a PicDem2-Plus board. I ran the
program in normal mode (not in debug mode). It displays
this on the terminal window on my PC:
Quote:

0.00070 0.00070 0.00070 0.00070

And it keeps on updating with the same thing.
So, it's working. I don't think I can do anything more for you.
My suggestion is to re-install the compiler.
nasreen.shayeq



Joined: 01 Apr 2010
Posts: 8

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 1:04 am     Reply with quote

Thank you very much for all your help, I will re-install my compiler now that I am sure my code works fine Smile
_________________
Regards,
Nasreen
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