Show Posts
Pages: 1 ... 16 17 [18]
256  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Maximum pin toggle speed on: June 16, 2009, 12:31:23 am
Hey westfw,

i'm still having difficulties running AVR MacPack:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1245125011

so can you confirm this math model on how many extra cycles (overhead, surroundings,...) because I can only for the moment inspect by benchmarking or cycle-counting as I explain yesterday  :'(

Q1: While(true) only uses 2 cycles ?

Q2: For(i:=0;i<n;i++) uses 2 cycles to initialize then 6 cycles to either jump loop or leave the loop once completed ?

Q3: About your suggestion to decrement loop, do you confirm initialization will also take 2 cycles (starting from i=0 might not require same cycle as starting from i= non zero value).

Sorry for all this questions but I feel you understand what i'm trying to do: have precise math model of every cycle, every instructions to generate high speed multi PWM requiring reverse-engineer to set up parameters of for(), while(),...
257  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Maximum pin toggle speed on: June 15, 2009, 10:15:08 pm
hello westfw and condemned,

ok, from my Mac, i can see & go to /Applications/arduino-0015/hardware/tools/avr/bin/avr-objdump but how do I launch avr-objdump - S on my sketch.elf which is stored on another directory ?

About max toggling, does goto instead of while(true) has same assembly code & overhead / duty cycle time at each run ?
Code:
 while (true) {
    PORTD |= B1000;
    PORTD &= B11110111;
  }
Code:
m:  PORTD |= B1000;
    PORTD &= B11110111;
    goto m;
  }



258  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Maximum pin toggle speed on: June 15, 2009, 01:42:47 am
Oups, you're entirely right :smiley

I did benchmark with only
Code:
 for (int i=0; i < N; i++){
    PORTD = B1000;
    PORTD = B11110111;
  }
Many thanks, you helped found me a bug smiley-wink

So about my code, in particular last PORT call (extract_off), how many cycles the while(true) will use ?

Please note that I TDMA frame my pulses so i'm not using while() to toggle but rather tune parameters with cycle offset corrections to get proper timing.

Worthwhile noting if 2 pins belong same port, we can set or clear within same cycle two outputs.

Again many thanks for all your support on this thread & the other one about scaning USB activity in 2 cycles.
259  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Maximum pin toggle speed on: June 14, 2009, 10:13:06 pm
ok, i'm totally new with arduino plus I don't have a debugger, compiler or any other tool for the moment so I just play with my Macintosh, ATmega1280 board & official SDK arduino 15 downloaded from arduino website.

As you may have found in other thread, i'm working on very fast PWM for my power electronics inverters....

The average poor man's method I use to measure real CPU cycle is as follows
Code:
#define NOP __asm__("nop\n\t")

int N = 0;
// long N=0;
unsigned long time, time1, time2;

void setup()
{
  Serial.begin(9600);
}

void loop{
  if (Serial.available()) {
    val = Serial.read();
    if (val == '+') {
      N += 1000;
    }
    if (val == '-') {
      N -= 1000;
      if (N<0) N = 0;
    }
  }
  
  time1 = micros();
  
  for (int i=0; i < N; i++){
//    __asm__("nop\n\t");
    PORTD |= B1000;
    PORTD &= B11110111;
//   if (UCSR0A & _BV(RXC0)) {
//    }
  }
  
  time2 = micros();

  Serial.print("N: ");
  time=time2-time1;
  Serial.print(time);
  Serial.print(" / ");
  Serial.println(N);
  delay(1000);
}
so with big N value, it converges with average ns measurement for whatever set of instruction I have inside for(i=0;i<;N;i++). For example, 444/1000 print output means 444ns or roughly 7 cycles at 16MHz.

This is how I observed a NOP was really 1 cycle, PORTD |= B1000 (setting bit 3 of PORTD) was 1 cycle,... 6 cycles for INT i and 10 cyles for LONG i overhead or surrounding management of for(i=0;i<;N;i++).

About my project, please note what i'm doing to generate high speed PWM
Code:
void loop()
{
 cli();  // turn off interrupts
 while (true) {
// Turns ON coil charging opto-coupler #1
    PORTH |= B10000;
    for(i=0;i<charge_on;i++) NOP;

// Turns OFF coil charging opto-coupler #1
    PORTH &= B11101111;
    for(i=0;i<charge_off;i++) NOP;
  
// Turns ON coil FE extracting opto-coupler #2
    PORTA |= B1;
    for(i=0;i<extract_on;i++) NOP;

// Turns OFF coil FE extracting opto-coupler #2
    PORTA &= B11111110;
    for(i=0;i<extract_off;i++) NOP;

    if (UCSR0A & _BV(RXC0)) { // check uart  (register name changes per port)
      break;  // looks like there is data.  Break out of loop to handle it
    }
  } // end of time critical loop
  sei();  // interrupts back on
  delay(10); // wait for some characters to arrive
  while (Serial.available()) {
// Macintosh serial monitor parameter management to update 4 loops
  }
}
so which is why I need to know while(true) overhead to compensate the computation of charge_on, charge_off, extract_on & extra_off values to get precise duty cycle. Please note I already compensated by including 1 cycle for PORTX writing along with 2 cycles for USB RX from if (UCSR0A & _BV(RXC0)) and 6+1 cycles  for local for(i=0;i<...) NOP
260  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Maximum pin toggle speed on: June 14, 2009, 03:58:08 pm
@condemmed

i'm a bit surprised you come with 2 cycles for
Code:
PORTD |= B1000;
and 2 cycles for
Code:
PORTD &= B11110111;
because I've benchmarked & runned real time with big N this
Code:
for(i=0;i<N;i++){
    PORTD |= B1000;
    PORTD &= B11110111;
  }  
in the arduino standard sketch and I come up with one cycle each instruction. Of course, in that case the iteration overhead consumes 6 extra-cycles whatever inside the loop hence a total of 8 cycles.

Please note my benchmarking method cannot trace execution time when using
Code:
while (true) {
    .....
  }
which was my initial question.
261  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Maximum pin toggle speed on: June 14, 2009, 01:35:43 pm
Could someone tell exactly how many cycles uses the while(true), I mean the overhead or surrounding
Code:
cli();
  while (true) {
    PORTD |= B1000;
    PORTD &= B11110111;
  }
For example, each while(true) loop will take 2 cycles to execute both PORTD writing / toggling but how many cycles the while(true) itself will take each run whatever instructions inside the loop ?
262  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Maximum pin toggle speed on: June 13, 2009, 10:04:27 pm
You can save one cycle from
Code:
cli();
  while (1) {
    PORTD |= 0x8;
    PORTD |= 0x8;
    PORTD &= ~0x8;
  }

and get the higher square wave frequency with
Code:
cli();
  while (1) {
    PORTD |= B1000;
    PORTD &= B11110111;
  }

263  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino + Vacuum Tubes as a transistor on: October 21, 2009, 03:30:10 am
Well, with tesla engineering, low Ron value is necessary but it is also crucial to have very low rise on - fall of fet switching, very low rise on - fall off fet's body diode along with a capacity to accept high voltage power supply (i.e. 500V)  pulsing primary coil & very fast frequency with low duty cycle.

Once you hit 50KHz - 200Khz, PW between 5% and 50% as in my projects, i don't think arduino TTL output drivers have so much sharp edge plus cannot provide peak local current to charge fet's internal gate capacitor. From high voltage & back-emf protection point of view, I rather use digital isolator then high speed power mosfet driver to really make pure PWM and saturate my actual "classic mosfet".

As I said before, i don't know if "logic level mosfet" has internally the equivalent of high speed power mosfet driver (i.e. TC4423 or MCP1403) which would be neat to simplify PCB, remove additional power supplies and lower $ project costs.
264  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino + Vacuum Tubes as a transistor on: October 21, 2009, 02:04:37 am
Thx Grumpy and AWOL about bringing me awareness of "logic level mosfet".

Please note my projects involved Solid State Tesla Coil and Rife healing plasma tube devices with direct frequency and pulse width software generated by arduino. This is why i'm using specific Tesla Coil or Ruhmkorff driver including digital-isolator and IC driver to control mosfet to protect my arduino board and Macintosh.

It might not be relevant in this thread because the initial question does not involve same high voltage and fast frequency switching as found in Tesla engineering but do you think "logic level mosfet" has an advantage compared to "classic mosfet" i'm using so far such as IRF family and power IC drivers ?
265  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino + Vacuum Tubes as a transistor on: October 20, 2009, 06:08:18 am
Quote
Not entirely true; many FETs have a "logic" version, where saturation is achieved with logic level voltages.

I would be interested to have this reference or P/N of such FETs.

Please note my application uses IRF540 & IRF840 to pulse extremely sharp on-off up to 1Mhz with very low PW which requires external FET driver IC.

P.S. The main point being stressed in this thread being best to use an opto-isolator or other tech isolator between TTL arduino and any FET tech or vacuum tube otherwise boom arduino or computer via USB link smiley-wink
266  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino + Vacuum Tubes as a transistor on: October 20, 2009, 05:35:44 am
Grumpy_mike gives wisdom advice.

You need to opto-isolate (i.e. 4N25 for low speed switching) or for fast switching, best use magnetoresistive-isolator (i.e. IL610)

Indeed for saturating a mosfet or a vacuum tube, you need to bang it with higher voltage & peak current totally incompatible with arduino TTL outputs drivers.
Pages: 1 ... 16 17 [18]