Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: Improving Arduino Leonardo USB CDC Baudrate and Data transfer. on: March 29, 2014, 10:04:47 am
Paul,
This is my understanding....
Packet size of Data received by Arduino.
vMaxPacketSize: Its the amount of Byte received (don't know which one is for Host PC or Arduino) for a specific Interval defined by: bInterval in ms.

Meaning in Interrupt mode: 16byte can be transferred in 64ms
another is  Interrupt mode: 64byte can be transferred in 1ms
then  Bulk mode: 64byte can be transferred in no interval??

So which mode or interval  Arduino Leonardo is using for communication, when the data is transferred from PC to Arduino via Serial port??
2  Using Arduino / Programming Questions / Re: Improving Arduino Leonardo USB CDC Baudrate and Data transfer. on: March 29, 2014, 08:20:30 am
Quote
Wondering  Arduino Leonardo  Serial.read() is Interrupt or Bulk transfer type?
This question is meaningless. It is neither. The Serial.read() function gets the next character from the incoming serial data buffer. How the data gets into that buffer may be Interrupt or Bulk Transfer, but how it gets out is neither.

Agree..but how to increase packet size? I tried in CDC.cpp but it has no effect what so ever... smiley-cry smiley-cry
any suggestion?

3  Using Arduino / Programming Questions / Re: Improving Arduino Leonardo USB CDC Baudrate and Data transfer. on: March 29, 2014, 08:14:56 am
You might have a look at the teensy (implementation) - which has a really fast USB port

Would love to but Teensy is not opensource and can't find the code in readable format....
BTWay we are Team Arduino!!
4  Using Arduino / Programming Questions / Re: Improving Arduino Leonardo USB CDC Baudrate and Data transfer. on: March 29, 2014, 07:26:58 am
PaulS has some points here.

Thanks...I realized now....but just read other posts on this forum and Paul seems to in Attacking mode today!  smiley-zipper
5  Using Arduino / Programming Questions / Re: Improving Arduino Leonardo USB CDC Baudrate and Data transfer. on: March 29, 2014, 07:21:17 am

Found this from Device Manager..



Wondering  Arduino Leonardo  Serial.read() is Interrupt or Bulk transfer type?
And how to increase the packat size to 128Bytes? Can this increase the Data received per 1ms interval??
6  Using Arduino / Programming Questions / Re: Improving Arduino Leonardo USB CDC Baudrate and Data transfer. on: March 29, 2014, 06:56:37 am
Come on Paul... what do you drink Tea/Coffee?

Here reading all the bytes together with Serial.readBytes()
Code:
  char buf[128];
  int count=0;
 
void setup() {
  delay(9000);
//   DDRD = DDRD | B11110011;
pinMode(2, OUTPUT);
  Serial.begin(0);
  while (!Serial) { ;}
}

void loop() {
 
digitalWrite(2,LOW);
while (Serial.available()){
  digitalWrite(2,HIGH);
  Serial.readBytes(buf,128);
//  for (count=0; count < 128; count++) {
//   buf[count] = Serial.read();
//  }
  digitalWrite(2,LOW);
}
delay(1000);
}

Its gone even worse to 1.68ms than 0.466ms previously!!

BTWay   Serial.begin(Any integer goes);  for Arduino Leonardo

How about using flush()??
7  Using Arduino / Programming Questions / Improving Arduino Leonardo USB CDC Baudrate and Data transfer. on: March 29, 2014, 06:20:50 am
Hi Everyone,
ATmega32u4 can provide 12Mbps Baudrate; however current configuration of Arduino Leonardo is not up to the scratch!

I have tested transferring 128Bytes of data from PC to Arduino Leonardo via COM port and received the data in approx. 0.466ms, which gives Baudrate of 10*128Byte/0.466ms = 2.76Mbps

Here goes the code;
Code:
 
char buf[128];
int count=0;

void setup() {
 delay(9000);
//   DDRD = DDRD | B11110011;
 pinMode(2, OUTPUT);
  Serial.begin(9600);
  while (!Serial) { ;}
}

void loop() {
 
  digitalWrite(2,LOW);
  while (Serial.available()){
  digitalWrite(2,HIGH);
  for (count=0; count < 128; count++) {
    buf[count] = Serial.read();
  }
  digitalWrite(2,LOW);
}
delay(1000);
}}
and the Timing



Question is: How to improve this rate at-least 2 or 3 fold?


8  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 19, 2012, 12:34:38 am
That will determine where / when  you disable / re-enable the interrupts.

A general rule I try to follow is to use interrupts only where necessary, and when using interrupts disable them only where necessary.

By default interrupts are Enable in Arduino, isn't it? Thats why I was getting errors. Also whenever one use Serial.Read/Write function or Delay() interrupts are Enabled, isn't it??
9  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 19, 2012, 12:21:26 am
yes it disables all Interrupts...

It disables entry into an interrupt service routine. In other words, the servicing of interrupts. However as dhenry said, if an interrupt "event" occurs (eg. a timer overflows) then that will be remembered and processed (in interrupt priority order) next time interrupts are enabled.

Nick,
These Timer/ Counters are great piece of kits but not much focus or references are available.
Why don't you make a guide specific to atmega328 & 32u4 for Arduino users about Timers/Counters??

P.S. would like to help you out in terms of preparing Graphics & illustrations.
10  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 19, 2012, 12:14:02 am
Nick;

 That's a very impressive application of a timer. I have a few questions:

1. Can the OCR2A&B registers be changed 'on the fly' to other values without having to do anything else?
2. What would the max and min frequencies be on a standard 16 Mhz board with retaining @ 50% duty cycle?
3. What would be the commands to stop the timer at any time, and to restart it at any time.

Sure seems like this could be made into a nice simple general purpose function clock generator?

Lefty


Lefy,
Absolutely this is what I was thinking , these Timer/Counter are great piece of kits that can be used in many more ways!
Also thanks Nick for answering the questions.
11  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 19, 2012, 12:02:25 am
If you have to protect the transmission, you may want to think what it is that you are trying to protect: you can protect the pulse width (high or low, or high and low); you can protect every 8 pulses; or you can protect all 24 pulses.

That will determine where / when  you disable / re-enable the interrupts.

The key is to minimize the duration of disabling them.

...Meaning put it in "for" loop where u need it?
Code:
for(int j=0;j <5; j++)
     { cli();
       ....
       .....
12  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 18, 2012, 11:58:21 pm
Quote
cli (); is needed to Disable Interrupt flag.

It doesn't disable interrupt flags: it disable interrupt execution. The flags will be set as they otherwise would be, except that they don't trigger isrs anymore.

Before you disable it, think hard if you have to. If your pulses needs to be generated absolutely as you had written, without interruption, you then have no choice but to disable interrupts.


yes it disables all Interrupts...
13  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 18, 2012, 11:57:28 pm
Before you disable it, think hard if you have to. If your pulses needs to be generated absolutely as you had written, without interruption, you then have no choice but to disable interrupts.

Even then there will be glitches at the end of loops, as I pointed out above. He has "no choice" but to use the hardware timers if he wants glitch-free pulses.

What frequency are you after? 1 MHz? This sketch does that, nice and simple:

Code:
const byte LED = 3;  // Timer 2 "B" output: OC2B

const long frequency = 1000000;  // 1 MHz

void setup()
 {
  pinMode (LED, OUTPUT);

  TCCR2A = _BV (WGM20) | _BV (WGM21) | _BV (COM2B1); // fast PWM, clear OC2A on compare
  TCCR2B = _BV (WGM22) | _BV (CS20);         // fast PWM, no prescaler
  OCR2A =  (F_CPU / frequency) - 1;          // zero relative 
  OCR2B = ((OCR2A + 1) / 2) - 1;             // 50% duty cycle
  }  // end of setup

void loop()
  {
  // do other stuff here
  }

Glitch-free output:



Plus you are free to do whatever you want in the main loop, interrupts, serial send/receive, whatever.
Thanks Nick!
Just woke up  smiley-wink

I need pulses of min 250nS or max 400ns. I need to learn how to use your approach though.


14  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 18, 2012, 04:16:34 pm
The timer interrupt fires every 1.024 mS which would stop your loop temporarily. If you want a proper signal use the hardware timers, not a timed loop. Examples here:

http://www.gammon.com.au/forum/?id=11504


Thanks a lott Nick..you are a super star!!
I tried to scan through the whole Timer and Interrupt topics...understood few bits and pieces but finally found out that
cli (); is needed to Disable Interrupt flag. I put that after "While" in the loop and it works!!
Code:
while(1)
   {
cli ();
    for(int j=0;j <5; j++)
     {

But the question is would that affect any other Interrupt routine in the "While" loop?? i.e. if I'm using  Serial.read function then??
15  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 18, 2012, 03:33:19 pm
There is also a small gap just after where you have 40 uS on the screenshot (which is after 24 pulses) which would be where the loop of 24 ends.

true
..1st let me refer to the link you send...brb
Pages: [1] 2 3 4