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

DLP-232PC

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



Joined: 03 Oct 2011
Posts: 5
Location: Serbia

View user's profile Send private message

DLP-232PC
PostPosted: Mon Oct 03, 2011 9:01 am     Reply with quote

I want to upgrade my cnc machine (now using LPT to operate) to USB. So, I've got DLP's DLP-232PC board, equipped with FT232R and PIC 18F2410 mcu. According to datasheet, FT232R gives 24Mhz clock to PIC, serial speed is 460800baud.
Comm software is written in Delphi (because of simplicity of D2XX library), using FT_in_buffer, FT_out_buffer, etc. Everything works fine with PIC's (DLP's) original firmware, sending single bytes, receiving ASCII replies, etc. But when I try to communicate with this code below, I recieve garbage, single byte, but always zero, PIC doesn't receive the stream I'm sending using Delphi program, and so on.
General idea is to send a packet of data (>1MByte, something like Gcode, but my own version), process it and send to pins. But I'm stuck with basics. HELP! I do appreciate any assitance!

PS I use CCS 4.124

Code:


#include <18F2410.h>
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
//#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled

#use delay(clock=24000000) //,RESTART_WDT)
#use rs232(UART1,stream=PC)

// CONSTANTS
#define BUFFER_SIZE   64

//GLOBAL VARS
int8 ch;
boolean trig=0;
int packet_buffer[BUFFER_SIZE];
int PC_buffer[BUFFER_SIZE];
int PC_next_in;
int PC_next_out;

#define DATA_IN   (PC_next_in != PC_next_out)

#int_RDA
void ISR_RDA() {
   int t;
   while(kbhit(PC)) {
      PC_buffer[PC_next_in] = fgetc(PC);
      t=PC_next_in;
      PC_next_in=(PC_next_in+1)%127;
      if (PC_next_in == PC_next_out) PC_next_in = t; //buffer full
   }
   output_toggle(PIN_A4);
}

int get_from_in_buffer() {
   int retval;
//   while(!DATA_IN);
   retval = PC_buffer[PC_next_out];
   if (++PC_next_out == BUFFER_SIZE) PC_next_out = 0;
   return retval;
}

void main()
{
   ch = 0; trig = 0;
   PC_next_in  = 0;
   PC_next_out = 0;


   //port_b_pullups(TRUE);
   //setup_adc_ports(NO_ANALOGS|VSS_VDD);
   //setup_adc(ADC_OFF);
   //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);
   //setup_oscillator(OSC_24MHZ|OSC_INTRC);
   //setup_uart_speed(460800);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
// TODO: USER CODE!!

//   fputc(0x01,PC);
//   putchar('A');
//   fputs("E",PC);
   fprintf(PC,"TEST");

   output_low(PIN_A4);
   while(1)
   {
/*      if (!DATA_IN) {
         output_high(PIN_A4);
         continue; // no data in buffer
      }
      ch = get_from_in_buffer();
      putc(ch);
      trig=!trig;
      if (trig) output_high(PIN_A4);
      else      output_low(PIN_A4);
*/
   }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Oct 03, 2011 9:21 am     Reply with quote

Several little comments:

1) Add ERRORS to the #use RS232. This _must_ be present when using the hardware UART, unless you yourself add error handling software. Without this, any comm error, _will_ result in the UART being hung....
2) The RS232 interrupt says that _one_ character is ready to be received. There is really no point in checking kbhit. Just receive the one character and get out.
3) Your RS232 code is setup to use a 127 byte buffer, but you have defined the buffer as 64 bytes.
4) Do a search here on why using the '%' is dangerous inside an interrupt. If used it should _only_ ever be used with binary buffer sizes (64, 128 etc.). Using it with '127', _will_ result in very slow interrupt handling, and potentially interrupts being disabled round any 8 bit division operations in the external code. Don't handle the buffer size this way. Use:
Code:

#int_RDA
void ISR_RDA(void) {
   int t;
   t=PC_next_in;
   PC_buffer[PC_next_in++] = fgetc(PC);
   if (PC_next_in) == BUFFER_SIZE) PC_next_in=0;
   if (PC_next_in == PC_next_out) PC_next_in = t; //buffer full
   output_toggle(PIN_A4);
}


Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Oct 03, 2011 9:59 am     Reply with quote

If this is true....

#FUSES INTRC_IO //Internal RC Osc, no CLKOUT

then you're not using the 24MHz clock from the FT232R module, and we all know the internal RC osc is NOT good(stable,temp,etc) for time critical functions.

I do know that you can get 1 Megabaud with an 18F4550 and the FT232R and Delphi combination(currently runnig a wall mounted CNC 6' x 8' 'printer'.
tbb



Joined: 03 Oct 2011
Posts: 5
Location: Serbia

View user's profile Send private message

PostPosted: Mon Oct 03, 2011 11:12 am     Reply with quote

Thank both of you for quick response, I do appreciate it very much!
Uhhh, I thought it's going to be easy for me to do this, but for sure I was wrong, a lot. I did all changes you suggested, but still same situation?
When PIC execute this code, I get in FT_in_buffer (Delphi code) 17bytes(all zeros), why not only 4, without control chars/codes, like with original firmware?
Code:

//   fputc(0x01,PC);
//   putchar('A');
//   fputs("E",PC);
   fprintf(PC,"TEST");
tbb



Joined: 03 Oct 2011
Posts: 5
Location: Serbia

View user's profile Send private message

PostPosted: Mon Oct 03, 2011 1:45 pm     Reply with quote

Got it from DLP support (Thank you Don), it's all about fuses! I would probably become bald before found it by myself...
Now 18F2410 is working ok! Thank you all for helping me=novice of the year!
Code:
#fuses EC_IO,WDT512,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NODEBUG,MCLR,NOPROTECT
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