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

vdrive2 speed
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Wed Oct 29, 2014 10:13 am     Reply with quote

Read the manual....

set_uart_speed(xxxxx);

Just setup the uart with #use rs232 to use 9600bps.

Print the speed change command to the Vdrive.
putc(0x1A);
putc(0);
putc(0);

Then either just delay for 2 character times (2.08mSec), or poll the TRMT bit in the UART.

set_uart_speed(115200);

Robert's your Father's brother....
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 2:44 am     Reply with quote

Ttelmah wrote:
Read the manual....

set_uart_speed(xxxxx);

Just setup the uart with #use rs232 to use 9600bps.

Print the speed change command to the Vdrive.
putc(0x1A);
putc(0);
putc(0);

Then either just delay for 2 character times (2.08mSec), or poll the TRMT bit in the UART.

set_uart_speed(115200);

Robert's your Father's brother....



Dear Ttelmah,

Thanks for the quick reply!
I've been playing with the VDrive2 ever since but still no succes at higher uart speeds. It is very happy at 9600 baud though, everything works perfectly fine at that speed.

Here is the code i'm using right now. I hope you can see where the problem lays..


Code:
void main()
{
int16 READU1

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

putc(0x1A);
putc(0);
putc(0);

delay_us(2080);

#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

         set_adc_channel(U1);    // spanning 1
         READU1 = read_adc();

/////////////////////////////////VDRIVE TEST///////////////////////////////////
      if       (INPUT(SWITCH1) == 0) {}
      if       (INPUT(SWITCH1) == 0)
               {
                           printf("OPW TEST.txt\r");     //create file and open it

                           printf("WRF ");               // write to file
                           putc(0x00);
                           putc(0x00);
                           putc(0x00);
                           putc(0x04);
                           putc(0x0d);
                           printf("%3Lu,", READU1);

                           printf("CLF TEST.txt\r");     //close currently open file
                           printf("OPW TEST.txt\r");     //create file and open it
                           printf("CLF TEST.txt\r");     //close currently open file
               }     
}


So, without the whole speed change and the #rs232 at 9600 this works just fine and a .txt file is on my USB with the READU1 value.

Sidenote: The extra OPW and CLF at the end is necessary because otherwise no .txt file is made and no data is written.

I've also tried it at just double speed (19200) with
putc(0x9C);
putc(0x80);
putc(0);

but still no luck there. The VDrive just stops working and the green LED stays on no matter what happens. Bummed Out
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 3:13 am     Reply with quote

You can't change speed with #USE RS232 like this. #USE RS232, is a _preprocessor_ directive, _not_ a line of code. This is why I said use 'set_uart_speed'.
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 3:48 am     Reply with quote

I've tried it with the set_uart_speed command as well. Still the VDrive gets stuck and lets the green LED stay on.

Maybe the problem lays with the use of the RTS and CTS pins? In my program the RTS pin is set high (and the CTS low), otherwise the VDrive doesn't do anything at all.

Btw, i'm using an external 20MHz crystal so the clock speed of the PIC controller is very accurate.
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 3:53 am     Reply with quote

It is just that if I don't write the new baud rate to the VDrive, then everything works just fine. As soon as the putc(..) is written to the VDrive, it just stops working Confused
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 4:04 am     Reply with quote

I wouldn't push the timing so much.

You are assuming that as soon as the processor starts, the Vdrive is ready to accept commands. Generally PIC's start faster than many devices like this. You should either be connecting the CTS line to see when the device is ready, or wait till the device sends the 'Ready' prompt, before starting to send it commands. The unit sends the message 'Ver something Vxxx On-Line:' before it is ready to accept commands.
Then similarly after the rate switch. The 2080uSec, is the minimum for the TX hardware to finish sending the command. The device responds with a couple of bytes reply at this point, and I waited for these before attempting to send any more commands.
Then when each command is sent, you should wait for the Vdrive to acknowledge before sending the rest. Simply reading the incoming data, and looking for carriage return is the easiest. Running faster, you have to ensure the drive has finished with a command, before sending the next.
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 4:24 am     Reply with quote

Alright, so I moved the set baud rate code. Now it sets the baudrate after the push button is pushed so enough time has passed for the VDrive to initialise the USB and let the green LED show. Now I can clearly see a short blink in the green LED right after the button is pushed so commands are recieved by the VDrive and written to the USB.
Only there is still no .txt file on the USB with the written data.
The code i use now is the following:
Code:
printf("SBD ");
putc(0x1A);
putc(0);
putc(0);
putc(0x0d);
delay_us(2080);

set_uart_speed(115200);


Is this right? Because these lines of code are causing the VDrive to freeze. Without it the VDrive works, only too slow for my application to work properly.
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 4:55 am     Reply with quote

Keeping in mind all the requirements needed for high speed bauds, the code is still the problem here.
If I manually set the baudrate to 9600 with the code from my last post, the VDrive still freezes. Same for double baud 19200 and 115k2 baud. And if I do nothing and only set the #rs232 to 9600 it works perfectly.
temtronic



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

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 6:25 am     Reply with quote

hmm.. I'll have to dig out the vdrive stuff and code but I did have mine running at 115K200, without handshaking 2-3 years ago. I did reprogram the Vinculum using their PC software,then downloaded it. 'Fun' part is that I have 2 of them and got 'confused' which was high speed and which wasn't. Arrgh a simple mark on the high speed one would have saved a few hours of frustration.

jay
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 8:01 am     Reply with quote

Hello Jay,

Thanks for your response!
Luckily, there is no need for multiple baudrates in my application. Right now my code works just fine. But 9600 is just too slow, because it takes 12.4ms to write a 8-bit integer to the VDrive.
My goal is to set the baud to 115k2.

Ttelmah pointed out that the baud can be changed with just a few lines of PIC code, that's why I'm going down this road.

As you can see I've tried to up the baud by sending the Set Baud Rate (SBD) command. No luck there, unfortunately. The VDrive gets stuck because of the newly added code.

Maybe I can up the baudrate by reprogramming the VDrive, as you pointed out. It just isn't my favorite option because different USB disks are going to be used.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 8:06 am     Reply with quote

As I said as the last line of my previous post:

"Then when each command is sent, you should wait for the Vdrive to acknowledge before sending the rest. Simply reading the incoming data, and looking for carriage return is the easiest. Running faster, you have to ensure the drive has finished with a command, before sending the next."

At the higher baud rates, you _must_ start reading the reply, and not sending another command, till each is accepted. The actual timing for the individual commands does not improve much over 9600bps, but what changes massively is how fast you can send the actual data.
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 8:33 am     Reply with quote

Ttelmah, right now the problem is in the code which sets the baud rate of the VDrive. The moment I set the baudrate by sending the SBD command with the associated putc(), the VDrive freezes. Not only at 115k2, but also at 9600.
I blame the code because without it, the VDrive works perfectly (at standard 9600 of course). And as soon as i set the baud manually with SBD to 9600, the VDrive stops working.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 8:46 am     Reply with quote

What firmware version are you on?.
Try doing a search on this version online, and seeing if there are any known issues.
DanielTPE



Joined: 20 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 9:20 am     Reply with quote

My PCW Compiler has recently been updated to Version 5.026.
I've done some googling but no fellow programmers seems to have this issue.
There must be a fault in the code I posted. I'm going to keep trying different approaches. If i get it working with pic code, i'll let you all know.
If someone finds a solution in the meantime, please let me know Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 03, 2014 9:47 am     Reply with quote

Not compiler version, _firmware_. The code in the Vdrive.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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