View previous topic :: View next topic |
Author |
Message |
misaeldv
Joined: 10 Nov 2005 Posts: 11
|
Weird Loop Problem |
Posted: Wed May 23, 2007 9:17 am |
|
|
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
|
|
Posted: Wed May 23, 2007 9:21 am |
|
|
INTs are only 8bits wide, 0-255
declare your variable as int16 and it should work |
|
|
misaeldv
Joined: 10 Nov 2005 Posts: 11
|
|
Posted: Wed May 23, 2007 10:19 am |
|
|
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
|
|
Posted: Wed May 23, 2007 11:05 am |
|
|
I think all us have made the same mistake at one point or another |
|
|
|