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

Weird Loop Problem

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



Joined: 10 Nov 2005
Posts: 11

View user's profile Send private message

Weird Loop Problem
PostPosted: Wed May 23, 2007 9:17 am     Reply with quote

Hi, I'm having a problem with my for loop, the compiler is complaining that it is an endless loop (and it is indeed since the code that I have after that loop does not execute). I tried doing a while loop and incrementing the counter inside the while loop but I keep getting the same error and the same outcome. I've looked and looked but cannot find anything wrong with it, Am I missing a library or something? Thanks in advance.
Here is my code
Code:

#include "C:\Microcontrollers\source codes\PIC16F874A\Stepper_Controller_874A.h"
#use fast_io(A)
#use fast_io(B)
#include <math.h>


void main()
{
   int i,j;

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
 
   set_tris_b(0x00);    //Makes port b7-b0 function as outputs
   output_b(0x00);      //Makes all of port B outputs
   
   output_high(PIN_B5); //Enables the L297 stepper driver chip
   output_high(PIN_B6); //Selects current control to act on ABCD lines, instead of inhibit lines
   output_high(PIN_B1); //Selects half step operation
   output_high(PIN_B0); //Pulls reset input high so driver does not reset by mistake
   
   //Infinite Loop
   do{
   //i = 0;
   //j = 0;
   output_low(PIN_B7);
   output_high(PIN_B4); //slects CW rotation
   
   //for (i=0;i<=1050;++i){
   
   while(i<1050){
     
   //Pin B2 provides the clock (f = 1/T)
   output_high(PIN_B2);
   delay_us(1429);
   output_low(PIN_B2);
   delay_us(1429);
   
   i = i+1;
   }//end for CW
   
   output_high(PIN_B7);
   output_low(PIN_B4); //slects CCW rotation
   
   for (j=0;j<=1050;j++){ 
   
   ////////while(j<=1050){
   
   output_high(PIN_B2);
   delay_us(1429);
   output_low(PIN_B2);
   delay_us(1429);
   
   //////j = j+1;
   }//end for CCW
   
   }while(true);
   //end while

}
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Wed May 23, 2007 9:21 am     Reply with quote

INTs are only 8bits wide, 0-255

declare your variable as int16 and it should work
misaeldv



Joined: 10 Nov 2005
Posts: 11

View user's profile Send private message

PostPosted: Wed May 23, 2007 10:19 am     Reply with quote

Thanks, that did it. I guess it wasn't weird after all, just a mistake on my part.
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Wed May 23, 2007 11:05 am     Reply with quote

I think all us have made the same mistake at one point or another Smile
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