Jump to content

syphon

EstablishedMember
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

0 Neutral

About syphon

  • Rank
    Newbrie
  1. Hi all, I'm currently doing a project which isn't working and I'm trying to find out the cause of it. One of the possible reasons that my team have come up with is a compatibility issue between Sourceboost BoostC and the Pickit2 Programmer from Microchip. The ICs we are currently using are the 16F690 and 16F917. I believe there is no compatibility issue for the 16F690 since there have been working programs using that IC. For the 16F917 however, I am not so sure. Can someone please confirm if there is a possible compatibility issue between Sourceboost BoostC and the Pickit2 Programmer? At the end of his wits, Chris
  2. Hey Jacob, thanks for replying The suggestions are extremely helpful. I'm not using arrays because I was trying to limit my code size, but that was before I got the license and overcame the code size limitations So I might be going back to arrays again. Again, thanks alot
  3. hey everyone, I currently have a problem in my code used to turn 3 stepper motors. Here'r the functions that take care of the phase changes in the motor static unsigned char seq_x = 0b00001100; // current phase of motors static unsigned char seq_y = 0b00001100; static unsigned char seq_z = 0b11000000; void motor_check (void){ if(seq_x == 0b00000001 || seq_x == 0b00011000) seq_x = 0b00001001; if(seq_y == 0b00000001 || seq_y == 0b00011000) seq_y = 0b00001001; if(seq_z == 0b10000000 || seq_z == 0b00011000) seq_z = 0b10010000; } void motor_move (unsigned char axis, unsigned char polarity){ if(axis == 'x' && polarity == 1){ // one step right seq_x = seq_x >> 1; motor_check(); PORTA = seq_x; } else if(axis == 'x' && polarity == 0){ // one step left seq_x = seq_x << 1; motor_check(); PORTA = seq_x; } else if(axis == 'y' && polarity == 1){ // one step up seq_y = seq_y >> 1; motor_check(); PORTD = seq_y | seq_z; } else if(axis == 'y' && polarity == 0){ // one step down seq_y = seq_y << 1; motor_check(); PORTD = seq_y | seq_z; } else if(axis == 'z' && polarity == 1){ // one step in seq_z = seq_z >> 1; motor_check(); PORTD = seq_y | seq_z; } else if(axis == 'z' && polarity == 0){ // one step out seq_z = seq_z << 1; motor_check(); PORTD = seq_y | seq_z; } } Basically the motors are hooked up to gears and stuff to control 3 axis movement. The problem is, not that it doesn't work (I'm not sure if it does yet since I only get to test it out on Monday). If I write the code like this, then I won't be able to use A7 to A4 on port A since it will always be cleared whenever moving the x-axis motor. Also, I can't set and clear the bits individually as I am using interrupts in my program to control another component. If I set them individually and the isr runs while the main is setting and clearing the bits, the motor will start jerking because at certain points in time, the motors will have incorrect phases while the isr is running. Any suggestions to improve it? I was thinking if there was a way to define a 4 bit data type and map it to A0 to A3 then the top four MSBs would be freed up, but I have no idea how to do that, or if it is even possible. I tried looking it up, but the closest thing I found was used in java
  4. Hi, me again I decided to try using the lcd library functions. But I'm getting a weird output. It displays the test message for a very brief period of time before looping it very very very fast and there are just like a million characters going past the lcd a sec. Here's my current code. I extracted some bits from the sample program lcd.c #include <system.h> #define LCD_ARGS 2, /* Interface type: mode 0 = 8bit, 1 = 4bit(low nibble), 2 = 4bit(upper nibble) */ \ 0, /* Use busy signal: 1 = use busy, 0 = use time delays */\ PORTC, TRISC, /* Data port and data port tris register */ \ PORTB, TRISB, /* Control port and control port tris register */ \ 4, /* Bit number of control port is connected to RS */ \ 6, /* Bit number of control port is connected to RW */ \ 5 /* Bit number of control port is connected to Enable */ #include <lcd_driver.h> // include the LCD template code #pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC #pragma CLOCK_FREQ 4000000 // Sim doesn't run as fast as actual device, so we change the delays so we don't // have to wait too long for the tests to complete #define RUN_UNDER_SIM // sim doesn't run in real time, so we will use shorter delays under sim. #ifdef RUN_UNDER_SIM #define DELAY delay_ms( 36 ) #define DELAY_SHORT delay_ms( 12 ) #else #define DELAY delay_s( 2 ) #define DELAY_SHORT delay_ms( 100 ) #endif void main() { ansel = 0; anselh = 0; lcd_setup(); lprintf("4bit test :)"); DELAY; } I also tried adding a while(1); to the bottom of the main, but if I do that then the lcd just shows the 2nd and 4th rows blackened.
  5. hey guys, i managed to get it to work. get this, there is NOTHING WRONG with the program. Apparently, you can program a faulty IC and still get it to show that it has been successfully programmed LOL. I changed the IC to another one that my supervisor was using and it worked. Maybe I should write a complaint to Microchip Well, thanks for all the help Very much appreciated Syphon
  6. hey, thanks for the code. I tried it but its still giving me the same output. The second and fourth rows are all black squares. The first and third are clear. I tried something else in my_init. Here it is. void my_init(void){ /***** A to D Code **** * Settings: 1=analog, 0=digital, Tad 2 us */ ansel = 0b00000000; anselh = 0b00000000; adcon1 = 0b00010000; rcsta.7 = 0; EN = 0; RS = 0; porta = 0; portb = 0; delay(15); // for the LCD to stabilise portc = 0b00111000; // initialising the LCD: 2-line mode, 5x7 dots enable(); delay(10); portc = 0b00001111; // initialising the LCD: on, underline cursor, blink enable(); delay(10); portc = 0b00000110; // shifts cursor after each character write enable(); delay(1000); // portc = 0b00000001; // clear display // enable(); // delay(10); } There is nothing in the main except a call to this function. As you can see, I commented out the part for clearing the display. If I don't clear the display, all 4 rows have black squares on it. If I do, the 4 rows stay black for a second, and then the 1st and 3rd rows clear, leaving the 2nd and 4th black. Also, even if I don't clear the display and try to write a character, I still get the 2nd and 4th rows blacked out, and the character still doesn't appear, and yes I did set RS = 1 before writing a character. I'm really confused.
  7. hey david, R/W is tied to ground. I tried what you suggested [Adding the line RS = 0 into my_init()] but its still not working. Nothing is showing up on screen, not even the cursor. I'm not even sure if its clearing the screen during my_init(). Am i supposed to turn the knob for the potentiometer all the way until I see squares? here's my current main() void main(void) { init(); // Function call inserted by C-Wiz my_init(); RS = 1; portc = 0x30; enable(); } sorry for being such a noob I haven't written lcd routines before
  8. Hi all, the LCD I'm using is ATM2004D which is a 4x20 and I'm using the 16F690 IC. I'm quite sure that the LCD follows the standard Hitachi LCD configuration thing. However, I can't seem to output any characters onto the LCD. It compiles and builds ok. Any help/suggestions are appreciated main.c #include <system.h> #include "definitions.h" #pragma DATA _CONFIG, _EXTRC_OSC_CLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOR_OFF & _IESO_ON & _FCMEN_ON // LCD FUNCTIONS // enable function for LCD in isr void enable(void){ unsigned char i = 159; EN = 1; asm { NOP } EN = 0; while (--i) continue; // 160 us delay } // delay function void delay(unsigned int milli_secs){ unsigned char i; do { i = 180; do { asm{ NOP NOP } } while (--i); } while (--milli_secs); } // clears LCD display void disp_clear_all(void){ portc = 0b00000001; // clear display enable(); delay(5); portc = 0b00000010; // return home enable(); delay(5); } // controls location of current cursor position on LCD void disp_cursor_pos(unsigned char pos){ unsigned char output = 0x80; RS = 0; if(pos == 'x'){ output = output|xposcoords; portc = output; } else if(pos == 'y'){ output = output|yposcoords; portc = output; } else if(pos == 'z'){ output = output|zposcoords; portc = output; } else if(pos == 'l'){ output = output|limitcoords; portc = output; } else if(pos == 'm'){ output = output|movingcoords; portc = output; } else if(pos == 's'){ output = output|stoppedcoords; portc = output; } else if(pos == '1'){ output = output|line1coords; portc = output; } else if(pos == '2'){ output = output|line2coords; portc = output; } else if(pos == '3'){ output = output|line3coords; portc = output; } else if(pos == '4'){ output = output|line4coords; portc = output; } enable(); } // writes a string of characters to the lcd for isr void disp_write(const char* message){ unsigned char k = 0; RS = 1; while(message[k] != 0) { portc = message[k]; enable(); k++; } } // clear an entire line on the LCD void disp_clear(unsigned char line){ unsigned char i; disp_cursor_pos(line); for(i = 0; i < 20; i++){ portc = 0x20; enable(); } } // writes the characters that do not change to the LCD void disp_eternal(void){ RS = 0; // setting pos of "X" portc = 0x80|0x16; enable(); disp_write("X"); // writing "X" RS = 0; // setting pos of "Y" portc = 0x80|0x1D; enable(); disp_write("Y"); // writing "Y" RS = 0; // setting pos of "Z" portc = 0x80|0x24; enable(); disp_write("Z"); // writing "Z" } // writes the "Stopped" message to the LCD void disp_stopped(void){ disp_clear('2'); disp_cursor_pos('s'); disp_write("Stopped"); } // writes the "* Limit Reached" message to the LCD where * denotes axis of reached limit void disp_limit (unsigned char dir){ disp_clear('1'); disp_cursor_pos('l'); if(dir == 3 || dir == 4) disp_write("X Limit Reached"); else if(dir == 1 || dir == 2) disp_write("Y Limit Reached"); else if(dir == 5 || dir == 6) disp_write("Z Limit Reached"); else disp_write("Limit Error"); } // writes the "Moving *" message to the LCD where * denotes direction of movement w.r.t magnified image void disp_moving (unsigned char num){ disp_clear('2'); disp_cursor_pos('m'); if(num == 0) disp_stopped(); else if(num == 1) disp_write("Moving Up"); else if(num == 2) disp_write("Moving Down"); else if(num == 3) disp_write("Moving Left"); else if(num == 4) disp_write("Moving Right"); else if(num == 5) disp_write("Moving In"); else if(num == 6) disp_write("Moving Out"); else disp_write("Moving Error"); } // function to convert coordinates to string for output to LCD char* int_to_str (signed int IntNum){ int* NumArray; char* str; unsigned char i = 0, k = 0, c = 0, space_counter = 0; // i controls str index, k controls NumArray index // c controls index of for loop to insert empty spaces //Taking Magnitude only if(IntNum < 0){ IntNum = IntNum * -1; // str[i] = '-'; // Uncomment if // i++; // minus sign required } //Splitting into ten thousands, thousands, hundreds, tens and ones if(IntNum/10000 != 0){ NumArray[k] = IntNum/10000; // ten thousands IntNum -= NumArray[k]*10000; k++; } else space_counter++; if(IntNum/1000 != 0){ NumArray[k] = IntNum/1000; // thousands IntNum -= NumArray[k]*1000; k++; } else space_counter++; if(IntNum/100 != 0){ NumArray[k] = IntNum/100; // hundreds IntNum -= NumArray[k]*100; k++; } else space_counter++; if(IntNum/10 != 0){ NumArray[k] = IntNum/10; // tens IntNum -= NumArray[k]*10; k++; } else space_counter++; NumArray[k] = IntNum; // ones for(; i <= k; i++) str[i] = NumArray[i] + '0'; // conversion to string for(; c < space_counter; c++, i++) // adding of spaces str[i] = ' '; str[i] = 0; return str; } // function to output coordinates to LCD void disp_coords(unsigned char axis, signed int coords){ disp_cursor_pos(axis); disp_write(int_to_str(coords)); } void init(void){ /***** Common Code **** * Portbit7:4 interrupt-on-change disabled * Peripheral interrupts not enabled * Global interrupt disabled during initialization */ intcon = 0b00000000; /* * Weak pullup on PORT disabled */ option_reg = 0b10000000; /* * Port directions: 1=input, 0=output */ trisc = 0b00000000; /***** 16F690 Code **** * Internal oscillator set to 4MHz */ osccon = 0b01100000; /***** PortB Code **** * Port directions: 1=input, 0=output */ trisb = 0b00000000; } // initialization for A/D converter and LCD void my_init(void){ /***** A to D Code **** * Settings: 1=analog, 0=digital, Tad 2 us */ // ANSEL = 0b11000000; // ADCON1 = 0b00010000; // EN = 1; // enable pin of LCD is 1 - not asserted // RS = 1; // LCD RS pin is in data mode // PORTA &= 0b00001100; // initialise all to zero except RA3 and AN2 // PORTB &= 0b00000000; // initialise all to zero portb = 0; delay(15); // for the LCD to stabilise portc = 0b00001111; // initialising the LCD: on, underlne cursor, blink enable(); portc = 0b00111000; // initialising the LCD: 2-line mode, 5x7 dots enable(); disp_clear_all(); } void main(void) { init(); my_init(); disp_write("Hello"); /* delay(2000); disp_clear(1); disp_eternal(); disp_coords('x',19977); disp_coords('y',15846); disp_coords('z',12585); disp_moving(1); delay(2000); disp_stopped(); disp_limit(1); */ } defnitions.h #ifndef DEFINITIONS_H_ #define DEFINITIONS_H_ static volatile bit RB4 @ 0x06.4; static volatile bit RB5 @ 0x06.5; // ***** LCD Definitions ***** // LCD Control Bit Definitions #define RS RB4 // Register Select #define EN RB5 // Enable // LCD Position Control Definitions // User Defined Symbols outputs #define xleftcoords 0x15 #define xrightcoords 0x17 #define yupcoords 0x1E #define ydowncoords 0x1C #define zforwardcoords 0x25 #define zbackcoords 0x23 // Motor Definitions #define delay1 100 // varies actual speed of motor #define delay2 50 #define delay3 5 #define value1 10 // varies duration between speed increase #define value2 100 #define firststep_delay 250 #define keypad_delay 20 // settling time for switch press #define a2d_tol 3 // tolerance for A to D conversions // Message and Distance Positions #define xposcoords 0x54 // output pos of x coords #define yposcoords 0x5B // output pos of y coords #define zposcoords 0x62 // output pos of z coords #define limitcoords 0x03 // pos of limit msg #define movingcoords 0x44 // pos of moving msg #define stoppedcoords 0x46 // pos of stopped msg #define line1coords 0x00 #define line2coords 0x40 #define line3coords 0x14 #define line4coords 0x54 // ***** MOTOR Definitions ***** // Step Size Definitions #define step_size 1 // Step size 1 micron #endif /*DEFINITIONS_H_*/
  9. Oh so ADRESH and ADRESL are defines? I didn't know that lol. Well thx for the help full program compiles fine now, I just get an error when I try to build 'cause I exceeded the license space limitations
  10. Please take a look at BoostC help first. It describes the compiler including it's language extensions that are different between most if not all compilers. In this particulat case instead of #asm BoostC uses asm or _asm operands. Regards, Pavel Well, the manual was kinda long, so I didn't read it but I replaced the #asm instructs with asm{}. That problem was solved but then I got multiple 'left operand must be l-value' errors on standard registers like INTCON and PIR1 as well as bit addressable registers such as RA0, RA1, etc. For the benefit of those who might encounter the same problem, I'll post my solution here. I might have done it wrongly though, since I haven't done this before, so it would help if someone could check it #1 : There is no bit addressable register for IO pins and certain registers, it has to be declared manually eg : static volatile bit RA0 @ 0x05.0; static volatile bit tmr2if @ 0x0C.1; static volatile bit gie @ 0x0B.7; #2 : Some of the standard registers such as TRISC or PORTA have to be used in lower case (trisc or porta) However, the odd thing is that ADRESH and ADRESL, the quantized output of the A to D converter module, doesn't give me any errors even while I left it in upper case. Any comment? (btw I use A to D in the full program)
  11. Hi all, I'm a novice programmer doing my final year project and I'm trying to port over a compilable project in Hi-Tech C to Sourceboost At first I got a EOF in comment error, which didn't reappear after I remade the project but now I'm getting a 'missing right paren' error when I try to use #asm in my delay function. I'm assuming paren means parenthesis, but it shouldn't be missing one since its compilable in Hi-Tech C I've also rewritten the _CONFIG line to suit Sourceboost, but I'm not entirely sure that its correct since I've never used #pragma before. I can't think of anything that might give this problem, help please? The program is meant to be a test program to test out the functions, which is why the main is simple. I'm using a PIC16F917. 16F917v3.c // This is a test program for the stepper motor using a PIC16F917 IC. // Program is combined into one c file as global static variables are used. #include <system.h> #include "definitions.h" #include "init.h" #include "PIC16F917.h" static signed int x_val = 0, y_val = 0, z_val = 0; // coordinates -- current position w.r.t ref. point static unsigned char seq_x = 0b00001100; // current phase of motors static unsigned char seq_y = 0b00001100; static unsigned char seq_z = 0b11000000; #pragma DATA _CONFIG, _EC_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _BOD_ON & _IESO_OFF & _FCMEN_OFF & _DEBUG_OFF // Peripheral initialization function void init(void){ /***** Common Code **** * Timer 2 interrupt enabled. * CCP Module 1 interrupt disabled. */ PIE1 = 0b00000010; /* * Port directions: 1=input, 0=output */ TRISC = 0b00000000; /* * Portbit7:4 interrupt-on-change disabled * Peripheral interrupts enabled * Global interrupt disabled during initialization */ INTCON = 0b01000000; /* * Weak pullup on PORT disabled */ OPTION = 0b10000000; /***** 16F917 Code **** * Internal oscillator set to 4MHz */ OSCCON = 0b01100000; /***** CCP Module 1 Code **** * CCP Module 1 enabled * CCP Module 1 in PWM mode * Output cleared on match */ CCP1CON = 0b00011001; /* * DutyCycle set to 0.25 uSec */ CCPR1L = 0b00000000; /***** PortA Code **** * Port directions: 1=input, 0=output */ TRISA = 0b01110000; /***** PortB Code **** * Port directions: 1=input, 0=output */ TRISB = 0b00000000; /***** PortD Code **** * Port directions: 1=input, 0=output */ TRISD = 0b00000000; /***** PortE Code **** * Port directions: 1=input, 0=output */ TRISE = 0b00000110; /***** Timer 2 Code **** * Prescale ratio is 1:4 * Timer 2 is active * Postscale ratio set to 1:1 */ T2CON = 0b00000101; /* * Period register set to 0xFF */ PR2 = 0b11111111; } // MOTOR & KEYPAD CONTROL FUNCTIONS // Making sure the correct bits are set void motor_check (void) { if(seq_x == 0b00000001 || seq_x == 0b00011000) seq_x = 0b00001001; if(seq_y == 0b00000001 || seq_y == 0b00011000) seq_y = 0b00001001; if(seq_z == 0b10000000 || seq_z == 0b00011000) seq_z = 0b10010000; } // Changing the appropriate bits to move motors to next phase depending on axis and direction void motor_move (unsigned char axis, unsigned char polarity) { if(axis == 'x' && polarity == 1){ // one step right seq_x = seq_x >> 1; motor_check(); if((seq_x & 0x08) == 0x08) // Setting and clearing bits individually RA3 = 1; else RA3 = 0; if((seq_x & 0x04) == 0x04) RA2 = 1; else RA2 = 0; if((seq_x & 0x02) == 0x02) RA1 = 1; else RA1 = 0; if((seq_x & 0x01) == 0x01) RA0 = 1; else RA0 = 0; x_val += step_size; // Changing coordinates } else if(axis == 'x' && polarity == 0){ // one step left seq_x = seq_x << 1; motor_check(); if((seq_x & 0x08) == 0x08) RA3 = 1; else RA3 = 0; if((seq_x & 0x04) == 0x04) RA2 = 1; else RA2 = 0; if((seq_x & 0x02) == 0x02) RA1 = 1; else RA1 = 0; if((seq_x & 0x01) == 0x01) RA0 = 1; else RA0 = 0; x_val -= step_size; } else if(axis == 'y' && polarity == 1){ // one step up seq_y = seq_y >> 1; motor_check(); if((seq_y & 0x08) == 0x08) RD3 = 1; else RD3 = 0; if((seq_y & 0x04) == 0x04) RD2 = 1; else RD2 = 0; if((seq_y & 0x02) == 0x02) RD1 = 1; else RD1 = 0; if((seq_y & 0x01) == 0x01) RD0 = 1; else RD0 = 0; y_val += step_size; } else if(axis == 'y' && polarity == 0){ // one step down seq_y = seq_y << 1; motor_check(); if((seq_y & 0x08) == 0x08) RD3 = 1; else RD3 = 0; if((seq_y & 0x04) == 0x04) RD2 = 1; else RD2 = 0; if((seq_y & 0x02) == 0x02) RD1 = 1; else RD1 = 0; if((seq_y & 0x01) == 0x01) RD0 = 1; else RD0 = 0; y_val -= step_size; } else if(axis == 'z' && polarity == 1){ // one step in seq_z = seq_z >> 1; motor_check(); if((seq_z & 0x80) == 0x80) RD7 = 1; else RD7 = 0; if((seq_z & 0x40) == 0x40) RD6 = 1; else RD6 = 0; if((seq_z & 0x20) == 0x20) RD5 = 1; else RD5 = 0; if((seq_z & 0x10) == 0x10) RD4 = 1; else RD4 = 0; z_val += step_size; } else if(axis == 'z' && polarity == 0){ // one step out seq_z = seq_z << 1; motor_check(); if((seq_z & 0x80) == 0x80) RD7 = 1; else RD7 = 0; if((seq_z & 0x40) == 0x40) RD6 = 1; else RD6 = 0; if((seq_z & 0x20) == 0x20) RD5 = 1; else RD5 = 0; if((seq_z & 0x10) == 0x10) RD4 = 1; else RD4 = 0; z_val -= step_size; } } // Initialization of bits controlling motors void motor_init(void) { RA0 = 0; // Phase A RA1 = 0; // Phase B RA2 = 1; // Phase A* RA3 = 1; // Phase B* RD0 = 0; // Phase A RD1 = 0; // Phase B RD2 = 1; // Phase A* RD3 = 1; // Phase B* RD4 = 0; // Phase A RD5 = 0; // Phase B RD6 = 1; // Phase A* RD7 = 1; // Phase B* } // delay function void delay(unsigned int milli_secs) { unsigned char i; do { i = 180; do { #asm NOP NOP #endasm } while (--i); } while (--milli_secs); } void main() { init(); // Function call inserted by C-Wiz motor_init(); while(1){ motor_check(); motor_move('x',1); // motor_move('x',0); // motor_move('y',1); // motor_move('y',0); // motor_move('z',1); // motor_move('z',0); delay(5); } } definitions.h #ifndef DEFINITIONS_H_ #define DEFINITIONS_H_ // ***** LCD Definitions ***** // LCD Control Bit Definitions #define RS RE0 // Register Select #define EN RC0 // Enable // LCD Position Control Definitions // User Defined Symbols outputs #define xleftcoords 0x15 #define xrightcoords 0x17 #define yupcoords 0x1E #define ydowncoords 0x1C #define zforwardcoords 0x25 #define zbackcoords 0x23 // Motor Definitions #define delay1 100 // varies actual speed of motor #define delay2 50 #define delay3 5 #define value1 10 // varies duration between speed increase #define value2 100 #define firststep_delay 250 #define keypad_delay 20 // settling time for switch press #define a2d_tol 3 // tolerance for A to D conversions // Message and Distance Positions #define xposcoords 0x54 // output pos of x coords #define yposcoords 0x5B // output pos of y coords #define zposcoords 0x62 // output pos of z coords #define dcoords 0x43 #define limitcoords 0x03 // pos of limit msg #define movingcoords 0x44 // pos of moving msg #define stoppedcoords 0x46 // pos of stopped msg #define line1coords 0x00 #define line2coords 0x40 #define line3coords 0x14 #define line4coords 0x54 // ***** MOTOR Definitions ***** // Step Size Definitions #define step_size 1 // Step size 1 micron #endif /*DEFINITIONS_H_*/
×
×
  • Create New...