Strange rebooting during function
viperfan7
Posts: 10
Well, for whatever reason, my code has started to cause the propeller to reboot itself when it runs, but I'm stuck, I have no clue why its not working, it was working very well at one point but now, t just doesn't work, works fine while being remote controlled though.
/* Welcome.c Welcome to SimpleIDE, the C programming environment that makes it easy to get started with the multi-core Propeller microcontroller! To run this program: - Is this the first Parallax software you've installed on your computer? If so, install USB driver's now: www.parallax.com/usbdrivers - Connect your Propeller board to your computer's USB. Also connect power to the board if needed, and if it has a power switch, turn it on. - Make sure to select your COM port from the toolbar dropdown menu in the upper-right corner. If you are unsure which COM port your board is connected to, disconnect it and click the dropdown to check the port list, then reconnect it and check again. - Click Program and select Run with Terminal (or click the Run with Terminal button). The SimpleIDE Terminal should appear and display the "Hello!" message. Next, check the Help menu for new online tutorials, software manual, and reference material. http://learn.parallax.com/propeller-c-tutorials */ // INCLUDES #include "simpletools.h" // Include simple tools #include "abdrive.h" #include "servo.h" #include "fdserial.h" #include "ping.h" #define DEBUG // DEFINES #define C6 1047 #define D6 1175 #define E6 1319 #define F6 1397 #define PING_PIN 17 //PING sensor pin #define TURRET_PIN 16 //PING sevo pin #define TURRET_CENTER 850 // centering pulse for turret #define TURRET_LEFT 1730 //left most turret position pulse #define TURRET_RIGHT 0 //RIghtmost turret position pulse #define SPEAKER_PIN 4 //Piezo speaker pin #define RX_PIN 9 //XBee RX #define TX_PIN 8 //XBee TX #define BLE_BAUD 115200 //Bluetooth baud rate #define MAX_SPEED 64 //Max speed for roaming #define BUTTON_PIN 5 //Pin for push button #define IRDET_LEFT 10 //Left IR Sensor pin #define IRDET_RIGHT 2 //Right IR Sensor pin #define IR_LEFT 11 //Left IR LED #define IR_RIGHT 1 //Right IR LED #define RAMP_STEP 16 //Speed step for single ramp itteration #define INPUT_MULT 1 fdserial *BLE; fdserial *ATCOM; char command[4] = {0,127,127,0}; float leftSpeed; float rightSpeed; //int rightMult; //int leftMult; int buttonState; int stateCanChange = 1; int main() // Main function { init(); buttonState = 0; while(!buttonState) { high(26); low(27); pause(250); low(26); high(27); pause(250); buttonState = input(BUTTON_PIN); } buttonState = 0; stateCanChange = 0; low(26); low(27); startBeep(); servo_angle(TURRET_PIN,TURRET_RIGHT); pause(500); servo_angle(TURRET_PIN,TURRET_CENTER); pause(500); servo_angle(TURRET_PIN,TURRET_LEFT); pause(500); servo_angle(TURRET_PIN,TURRET_CENTER); freqout(SPEAKER_PIN,250,noteFreq(18)); pause(50); freqout(SPEAKER_PIN,100,noteFreq(18)); pause(50); freqout(SPEAKER_PIN,100,noteFreq(18)); roam(); //remoteControl(); } void init() { servo_angle(TURRET_PIN,TURRET_CENTER); freqout(SPEAKER_PIN,50,noteFreq(18)); pause(50); freqout(SPEAKER_PIN,50,noteFreq(18)); pause(50); freqout(SPEAKER_PIN,50,noteFreq(18)); pause(50); //command[1]=100; //command[2]=100; //ATCOM = fdserial_open(RX_PIN,TX_PIN,0,115200) //fdserial_txChar(ATCOM,c) BLE = fdserial_open(RX_PIN,TX_PIN,0,BLE_BAUD); drive_setRampStep(RAMP_STEP); //square_wave(IR_LEFT,0,38000); //square_wave(IR_RIGHT,1,38000); } void startBeep() { freqout(SPEAKER_PIN,50,879); freqout(SPEAKER_PIN,50,659); freqout(SPEAKER_PIN,50,1244); } void changeBeep() { freqout(SPEAKER_PIN,50,noteFreq(20)); freqout(SPEAKER_PIN,50,noteFreq(24)); freqout(SPEAKER_PIN,50,noteFreq(22)); } void roam() { scanDist(); //drive_rampStep(128,128); int scanOn = 0; while(!buttonState) { if(stateCanChange) { buttonState = input(BUTTON_PIN); //print("%c ButtonState = %d%c",CLREOL,buttonState,HOME); if(buttonState) { stateCanChange = 0; } } else if(!input(BUTTON_PIN)) { stateCanChange = 1; //print("CanChange"); } if(ping_cm(PING_PIN) < 20) { scanOn = 1; } if(scanOn) { drive_ramp(0,0); pause(1000); scanDist(); //drive_ramp(MAX_SPEED,MAX_SPEED); scanOn = 0; } else { freqout(IR_LEFT,1,38000); int irLeft = input(IRDET_LEFT); freqout(IR_RIGHT,1,38000); int irRight = input(IRDET_RIGHT); if((irLeft && irRight) || (!irLeft && !irRight)) { drive_rampStep(MAX_SPEED,MAX_SPEED); } else if(irLeft) { drive_rampStep(MAX_SPEED/2,MAX_SPEED); } else if(irRight) { drive_rampStep(MAX_SPEED,MAX_SPEED/2); } } } //End of Drive loop buttonState = 0; changeBeep(); remoteControl(); } void remoteControl() { char c; while(!buttonState) { if(stateCanChange) { buttonState = input(BUTTON_PIN); //print("%c ButtonState = %d%c",CLREOL,buttonState,HOME); if(buttonState) { stateCanChange = 0; } } else if(!input(BUTTON_PIN)) { stateCanChange = 1; //print("CanChange"); } int leftMult; int rightMult; command[0] = fdserial_rxCheck(BLE); //print("%c",c); if(command[0] == 2) { //print("%c%c",CLREOL,HOME); //print("%x;",command[0] & 0xFF); for(int i = 1; i <= 3; i++) { c = fdserial_rxChar(BLE); fdserial_txChar(BLE,c); command[i] = c; //print("%x;",c & 0xFF); } //print("%c%s%c",HOME,command,CLREOL); //print("%c",CLREOL,HOME); //print("%d;%d;",command[1],command[2]); //print("%c%c %d,%d,%d,%d",CLREOL,HOME,command[0],command[1],command[2],command[3]); } leftMult = command[1]; rightMult = command[2]; //print("%c Left = %d \n Right = %d %c",HOME, (rightMult*2),(leftMult*2),CLREOL); drive_rampStep(((-128)+((leftMult*INPUT_MULT)+1)),((-128)+((rightMult*INPUT_MULT)+1))); } changeBeep(); buttonState = 0; roam(); } void scanDist() { int startDist[3]; int size = 3; //int scanMode = 1; int largest = 0; startDist[1] = ping_cm(PING_PIN); pause(50); servo_angle(TURRET_PIN,TURRET_CENTER-450); pause(500); startDist[2] = ping_cm(PING_PIN); pause(50); servo_angle(TURRET_PIN,TURRET_CENTER+450); pause(500); startDist[0] = ping_cm(PING_PIN); pause(50); servo_angle(TURRET_PIN,TURRET_CENTER); int prev = startDist[0]; //print("A0:%d\n",startDist[0]); //print("A1:%d\n",startDist[1]); //print("A2:%d\n",startDist[2]); //print("Left: %d\nMid: %d\nRight: %d\n",startDist[0],startDist[1],startDist[2]); //int largest = intLargestInArray(*startDist,3); for(int i = 0; i < size; i++) { //print("I:%d,A:%d,P:%d\n",i,array[i],prev); if(startDist[i] >= prev) { //print("%d\n",i); prev = startDist[i]; largest = i; } } print("%d\n",largest); freqout(IR_LEFT,1,38000); int irLeft = input(IRDET_LEFT); freqout(IR_RIGHT,1,38000); int irRight = input(IRDET_RIGHT); if(!irLeft && !irRight) { drive_goto(51,-51); pause(400); } else { if(largest == 1) { pause(200); //print("CENTER"); } else if(largest == 2) { drive_goto(13,-12); pause(200); //print("RIGHT"); } else if(largest == 0) { drive_goto(-13,12); pause(200); //print("LEFT"); } } } int intLargestInArray(int *array, int size) { int prev = 0; int largest = 0; //int size = sizeof(array)/sizeof(int); //print("Size:%d\n",size); print("A0:%d\n",array[0]); print("A1:%d\n",array[1]); print("A2:%d\n",array[2]); for(int i = 0; i < size; i++) { //print("I:%d,A:%d,P:%d\n",i,array[i],prev); if(array[i] >= prev) { //print("%d\n",i); prev = array[i]; largest = i; } } //print("%d\n",largest); return largest; } //Returns frequency of note <hSteps> away from root frequency (440 = A4) int noteFreq(int hSteps) { float fMult = 1.059463; int hMult = 1; const root = 440.0; float postCalc = 1; if(hSteps < 0) { hMult = -1; } else if(hSteps > 0) { hMult = 1; } else { return root; } for(int i = 0; i < ((hSteps*hMult)); i++) { if(hMult > 0) { postCalc = postCalc * fMult; } else { postCalc = postCalc / fMult; } } return root*postCalc; }
Comments
Tom