Show Posts
Pages: 1 ... 645 646 [647] 648 649 ... 1848
9691  Using Arduino / Programming Questions / Re: 16-bit sample & store, then readback & play, finally store to SD on: August 04, 2013, 11:28:32 am
"I will put together a a complete test sketch."
Thanks Bill.
I'm playing with the timer overflow create an interrupt part right now, making sure I understand what's happening.

Added:
Code:
// avr-libc library includes - added for timer interrupt
#include <avr/io.h>
#include <avr/interrupt.h>
Added:
Code:
// Added code for 1/44,100 Hz interrupt
    // initialize Timer1
    cli();             // disable global interrupts
    TCCR1A = 0x6B;        // set entire TCCR1 register to 363 (0x016B)
    TCCR1B = 0x01;
 
    // enable Timer1 overflow interrupt:
    TIMSK1 = (1 << TOIE1);
    // Set CS10 bit so timer runs at clock speed:
    TCCR1B |= (1 << CS10);
    // enable global interrupts:
    sei();
Added:
Code:
// Added a simple ISR to check the timing
ISR(TIMER1_OVF_vect)
{
    digitalWrite(activeLed, !digitalRead(activeLed));
}
Compiles ok, time to download and break out the scope again ...
9692  Using Arduino / Project Guidance / Re: Arduino 8x8 led table on: August 04, 2013, 11:16:50 am
I wasn't being sarcastic, just going with the facts. You need to check what 1mA will do with the PNP - most do not conduct very much with that little current flowing, and for turning on LEDs you want them to be full on and not have some large voltage drop across the emitter-collector.  If protecting the IO from 12V limits the current for driving the IO, then that's not a good mix.

If the goal is to drive a PNP with just 5V, then a current limit resistor as low as (5V-0.7V)/.02 = 220 should be pretty safe.
9693  Using Arduino / Project Guidance / Re: Arduino 8x8 led table on: August 04, 2013, 03:17:50 am
Atmel docs say the clamp diodes should see no more than 1mA. 2mA is more than 1mA. Anything more than 0.5V below Gnd and 0.5V above Vcc will turn on the diode.
The diode clamping and current limit are discussed in the attached.
9694  Using Arduino / General Electronics / Re: cell phone jammer using house Mains ground as antenna on: August 04, 2013, 02:56:08 am
I don't know, if I call from the back of my house I get crappy cell coverage, walk 18-20' to the front door and it's a lot better - maybe some self-jamming going on smiley-cool
9695  Using Arduino / Programming Questions / Re: 16-bit sample & store, then readback & play, finally store to SD on: August 04, 2013, 02:52:29 am
Ok, I am asking for programming help then. I don't know enough to tie all the pieces together.
The adafruit waveshield page says "It can play up to 22KHz, 12bit uncompressed audio files of any length."
http://www.adafruit.com/products/94

How do I get from there to 44.1K, 16 bit uncompressed?  I think I'm starting to get the concept: use the code above to interrupt every 7-8uS to get a sample, the code is free to run the rest of the time (22.767-8uS = say 15uS less any interrupt jumping back & forth time) to send data out to the SD via hardware-buffered SPI?
Looking at Nick's handy table here
http://www.gammon.com.au/forum/?id=11504
I see 40K, I see 50K.
Hmm, these seem to be timer 2 also - Timer 0 & Timer 2 are 8-bit. Timer1 & Timer3 are 16-bit - can Timer3 be programmed for 22.676uS interrupts?
Deeper hmm - (1/44,100)/(1/16,000,000) = interrupt every 362.8 (363) clock cycles - so from Nick's page 363 >255, so 16 bit timer is needed.
I may get this yet!

[Some further enticing 1284 info:
1284P has 2 UARTs - maybe use that in SPI mode to get some breathing room too.
"The USART RX and TX control logic is replaced by a common SPI transfer control logic."
Common with the regular SPI port, or just between the 2 UARTs?

"16-bit data transfer can be achieved by writing two data bytes to UDRn. A UART transmit complete interrupt will then signal that the 16-bit value has been shifted out."
Good for sending to the DAC - 3 bytes come in from the ADC (or 20 bits if one stop there as you did) so that doesn't really help on the acquisition side.]

Anyway, off to bed - gonna be dragging a  little tomorrow...
9696  Using Arduino / General Electronics / Re: Custom Wire Size on: August 04, 2013, 02:04:46 am
I used telephone wire for a long time, finally got tired of the stiffness of it (26 guage solid core wire) and bought a couple packs of these for breadboard use
http://www.nkcelectronics.com/breadboard-jumper-wire-70pcs-pa70.html
Then misplaced them, bought a couple more, and then found the originals, so now have lots!
For long runs at my fencing club (~65 feet), I bought a 500' spool of shielded 4-conductor security wiring from Home Depot, wired up lights together at the end of the strips that way. Have some left over that I use for the occasional project at home when I need a few feet of stranded hook up wire.
9697  Using Arduino / Project Guidance / Re: Arduino 8x8 led table on: August 04, 2013, 01:59:04 am
12V on the pin zaps the pin, unless the resistor is so big that only 1mA is allowed to flow, which is not likely to turn on the PNP very much when driven low.
You can use an Open drain shift register like TPIC6B595 to sink the PNP base to pull it low, its good for lots of current and up to 50V. Open drain means it's high impedance when not pulling low (and cannot drive high), and you use a pullup resistor to the high voltage on the PNP to turn it off.
9698  Using Arduino / Programming Questions / Re: 16-bit sample & store, then readback & play, finally store to SD on: August 03, 2013, 10:48:21 pm
Ok, testing is looking better:
Code:
Start recording
done from record memory
13253980
Start playback
done from playback memory
11735128
So readback looks like could be fast enough if I can find a fast DAC.
Writing still a little slow.
Entire code attached  below.
Write loop:
Code:
 // somehow put this in an interrupt timer ISR that runs at 22.676uS when sped up enough
  while (recording == 1){  // stay here until memory is full, or end is pressed    
      // access ADC
      PORTB = PORTB & B11110111; // clear csADC
      adc2 = SPI.transfer(0); // MSB 0000 xxxx
      adc1 = SPI.transfer(0); //     xxxx xxxx
      adc0 = SPI.transfer(0); //     xxxx 0000 LSB
      PORTB = PORTB | B00001000; // set csADC
      // clean up into 2 bytes
      upperADC = (adc2 <<4) + (adc1 >> 4);
      lowerADC = (adc1 <<4) + (adc0 >> 4);

      // write to SRAM
      PORTC = SRAMbank; // clear SRAM chip select 0 to 7
      SPDR = (SRAMinst);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (SRAMaddress2);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (SRAMaddress1);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (SRAMaddress0);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (upperDAC);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (lowerDAC);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      PORTC = 0xFF; // set SRAM chip select 0 to 7
      // update for next address and/or bank
      SRAMaddress0 = SRAMaddress0+1;
      if (SRAMaddress0 == 0){
        SRAMaddress1 = SRAMaddress1 +1; //
        if (SRAMaddress1 == 0){
          SRAMaddress2 = SRAMaddress2 + 1; //
          if (SRAMaddress2 == 2){ //gone thru all addresses,rollover to next bank
            SRAMaddress2 = 0; // clear upper bit, shift the 0 for next cs bit
            SRAMbank = (SRAMbank <<1) + 0x01; // B11111110 -> B11111101, etc.
            if (SRAMbank == 0xFF){  // shifted a 0 across all outputs
            endTime = micros();
              recording = 0; // Done!
              Serial.println ("done from record memory");
              Serial.println (endTime - startTime);
              
              PORTA = PORTA & B11111110; // turn off status LED
            } // SRAM bank rollover
          } // upper address rollover
        } // middle address rollover
      } // lower address rollover
  } // while record/store loop
Read loop:
Code:
 // somehow put this in an interrupt timer ISR that runs at 22.676uS when sped up enough
  while (playing == 1){ // stay here until playback is done, or end is pressed                      
      // read SRAM
      PORTC = SRAMbank; // clear SRAM chip select 0 to 7
      SPDR = (SRAMinst);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (SRAMaddress2);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (SRAMaddress1);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (SRAMaddress0);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;      
      upperDAC = SPI.transfer (0);
      lowerDAC = SPI.transfer (0);
      PORTC = 0xFF; // set SRAM chip select 0 to 7

      // write data to DAC 000000xx xxxxxxxx xxxxxxxx
      // first 2 bits are 0 for normal operations
      PORTB = PORTB & B11111011; // clear csDAC
      SPDR = (0);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (upperDAC);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      SPDR = (lowerDAC);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
      PORTB = 0xFF; // clear csDAC
      // update for next address and/or bank
      SRAMaddress0 = SRAMaddress0+1;
      if (SRAMaddress0 == 0){
        SRAMaddress1 = SRAMaddress1 +1;
        if (SRAMaddress1 == 0){
          SRAMaddress2 = SRAMaddress2 + 1;
          if (SRAMaddress2 == 2){ // gone thru all addresses,rollover to next bank
            SRAMaddress2 = 0; // clear upper bit, shift the 0 for next cs bit
            SRAMbank = (SRAMbank <<1) + 0x01; // B11111110 -> B11111101, etc.
            if (SRAMbank == 0xFF){  // shifted a 0 across all outputs
            endTime = micros();
            playing = 0; // Done!
              Serial.println ("done from playback memory");
              Serial.println(endTime - startTime);
              PORTA = PORTA & B11111110; // turn off status LED
            } // SRAM bank rollover
          } // upper address rollover
        } // middle address rollover
      } // lower address rollover
  } // while read/play loop

9699  Using Arduino / Programming Questions / Re: 16-bit sample & store, then readback & play, finally store to SD on: August 03, 2013, 10:15:42 pm
Yeah, you're correct - I missed the sentence in the datasheet that describes in figures 2-5 and 2-5 (now that I've re-read it)  the instruction bytes 0b00000010 & 0b00000011 before the 3 address byte and then 1 or more data bytes. Adding another byte only slows it down some more tho.

I realize I can't run the AD7680 that fast, I mentioned needing a faster ADC so I can use 8 MHz SPI.

Moving up to specialized code to achieve 22.676uS data rate is what I'm after. I could use the help in getting there. Once past direct port manipulation and SPI for speed, I'm kinda stuck.

I don't need to play back from the card, I'll do that at the PC as I clean up the sample. I only want to playback the SRAM to hear the sample on the spot and decide if it's good enough to put on the SD card.

I'll look at some other 16 bit ADC to find a faster one. I really want to reach 44,100 words/sec rate to sample & store from ADC to SRAM, and play from SRAM to DAC.

I was thinking today that parallel SRAM might be an option too.
19 address bits,
16 data bits,
3 control lines,
4 lines for serial ADC/DAC,
Hmm.  Use external counter that just need reset and clock line vs 19 address lines, single toggle to clock it up one.

I was able to send out 41 bytes of data really fast doing 41 lines of this:
Code:
    PORTB = PORTB & B11111011;  //digitalWrite(SSpin, LOW);
    // monitor D10, confirm XXuS timing
    SPDR = (testArray[fakestartPoint + 0]);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
    SPDR = (testArray[fakestartPoint + 1]);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
    SPDR = (testArray[fakestartPoint + 2]);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
    SPDR = (testArray[fakestartPoint + 3]);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
    SPDR = (testArray[fakestartPoint + 4]);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
    SPDR = (testArray[fakestartPoint + 5]);nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;nop; nop; nop;nop;  nop;
    PORTB = PORTB | B00000100;  //digitalWrite(SSpin, HIGH);
You thing doing the same for the SRAM would help?

9700  Using Arduino / General Electronics / Re: Custom Wire Size on: August 03, 2013, 05:55:29 pm
The gage needed depends on amount of current and the voltage used. Also how many conductors.
For low voltage projects, yoh can do a lot with telephone wire and CAT5 type wire. If you don't have an eleftronics supply house around, then try Home Depot  or Lowes.
9701  Using Arduino / Microcontrollers / Re: Program an external ATMEGA328 without removing the one in the Arduino on: August 03, 2013, 08:37:52 am
You're welcome.
9702  Using Arduino / Programming Questions / Re: 16-bit sample & store, then readback & play, finally store to SD on: August 03, 2013, 02:25:30 am
Okay, I've got this thing free-running, going flat out with no timing measurements or interrupts in the code, just whatever milis() and micros() are doing in the background.  Results from micros() captured just before sampling starts and right after it ends, and the same for playback:
Code:
Start recording
done from record memory
14696056 (uS)
Start playback
done from playback memory
13706116 (uS)
Total memory accessed: 8 * 128 *1024 = 1048576 bytes/2 = 524,288 words / 14.696 seconds = 35,675 16-bit samples/second while recording.
How do I squeeze a few more seconds out of this? I want to be down to 11.888 seconds, so 2.808 seconds faster.

Reading out, it's a little quicker because the 16 bits of data can go right from memory into the DAC, the 16 bits don't need to be pulled from the middle of the 24 bits out of the ADC.
524,288/13.706 = 38,252 samples/second. So I want 1.818 seconds improvement there.

The numbers above assume ADC, DAC, and memory running 8 MHz and not the 2MHz I started with, that was a big improvement:
Code:
Start recording
done from record memory
39953364 (uS)
Start playback
done from playback memory
38950760 (uS)

If I could find ADC & DAC that only needed 2 byte transfers to read out & write in, that would help:
Code:
Start recording
done from record memory
12123192 (uS)
Start playback
done from playback memory
12064720 (uS)
524,288/12.123sec = 43,246 samples/sec. Close to CD quality.

What else can I do to get faster? I don't know if 16 bit, 2-byte transfers ADC/DAC even exist, the choices were getting limited at 16 bit already, hence the AD7680 & AD5662B (datasheets posted earlier).

Here's the capture loop, full code is attached below:
Code:
 while (recording == 1){  // stay here until memory is full, or end is pressed
    //currentTime = micros();
    //if ( ( currentTime - previousTime) >=duration){
    //  previousTime = previousTime + duration;    
      // access ADC
      PORTB = PORTB & B11110111; // clear csADC
      adc2 = SPI.transfer(0); // MSB 0000 xxxx
      adc1 = SPI.transfer(0); //     xxxx xxxx
      //adc0 = SPI.transfer(0); //     xxxx 0000 LSB
      PORTB = PORTB | B00001000; // set csADC - csADC is toggling
      // clean up into 2 bytes
      //upperADC = (adc2 <<4) + (adc1 >> 4);
      //lowerADC = (adc1 <<4) + (adc0 >> 4);

      // write to SRAM
      //Serial.print(" sram sel ");
      //Serial.println (SRAMbank, HEX);
      PORTC = SRAMbank; // clear SRAM chip select 0 to 7
      SPI.transfer (SRAMaddress2);
      SPI.transfer (SRAMaddress1);
      SPI.transfer (SRAMaddress0);
      SPI.transfer (upperADC);
      SPI.transfer (lowerADC);
      PORTC = 0xFF; // set SRAM chip select 0 to 7
      // update for next address and/or bank
      SRAMaddress0 = SRAMaddress0+1;
      if (SRAMaddress0 == 0){
        // lower address rolled over, increment middle address
        //Serial.println ("low address roll");
        SRAMaddress1 = SRAMaddress1 +1; //
        if (SRAMaddress1 == 0){
          // middle address rolled over, increment upper address
          //Serial.println (" middle address roll");
          SRAMaddress2 = SRAMaddress2 + 1; //
          if (SRAMaddress2 == 2){ //gone thru all addresses,rollover to next bank
            SRAMaddress2 = 0; // clear upper bit, shift the 0 for next cs bit
            //Serial.print ("Sb ");
            SRAMbank = (SRAMbank <<1) + 0x01; // B11111110 -> B11111101, etc.
            //Serial.println (SRAMbank,BIN);
            if (SRAMbank == 0xFF){  // shifted a 0 across all outputs
            endTime = micros();
              recording = 0; // Done!
              Serial.println ("done from record memory");
              Serial.println (endTime - startTime);
              
              PORTA = PORTA & B11111110; // turn off status LED
            } // SRAM bank rollover
          } // upper address rollover
        } // middle address rollover
      } // lower address rollover
      // check endButton, stop if pressed - this read works
      //buttons = PINA;
      //if ((PINA & B01000000) == 0){
      //  recording = 0;
      //  Serial.println ("done from record end");
      //  PORTA = PORTA & B11111110; // turn off status LED
      //}
    //} // time check
  } // while record/store loop
9703  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Heating Up with DC Motor [Urgent] on: August 02, 2013, 11:23:26 pm
If you run the sketch without the transistor, does it still get hot?

If so, you may have smoked the chip by not having the resistor, and you're pretty much hosed. Put another chip on the board.  Don't leave out the resistor next time.

If it doesn't get  hot, then you need to power the fan circuit from something else.
9704  Using Arduino / General Electronics / Re: Arduino compatible board assembly. on: August 02, 2013, 06:38:39 pm
Yes - use ISP for bootloader, or sketch with no bootloader.

Use USB/Serial adapter to down via the bootloader.
Use offboard USB/Serial adapter if there is not one on the board.

An example - FTDI module & AVR ISP connector bootloading a '1284P card.
AVR ISP in this case is Atmel AVR ISP MKii, only senses power, FTDI module is actually powering the card.
9705  Using Arduino / Project Guidance / Re: Nano Power Dilema on: August 02, 2013, 06:00:34 pm
The onboard regulator is only good for 500mA max.
http://www.digikey.com/product-search/en?x=15&y=14&lang=en&site=us&KeyWords=ua78m05
You run it from 9.9V, outputting 5V, half of whatever current you draw is wasted as heat, dissipated by the chip. And its not very well heatsinked.
How much current do you need?
Maybe a separate switching regulator would be better - step-up for a single battery, step-down for multiple  batteries. Examples are here:
http://www.pololu.com/catalog/category/133
http://www.pololu.com/catalog/category/132
http://www.pololu.com/catalog/category/131
Pages: 1 ... 645 646 [647] 648 649 ... 1848