Show Posts
Pages: [1]
1  Using Arduino / Audio / Re: Leonardo direct MIDI USB on: June 19, 2012, 02:16:43 am
Another interesting software is V-USB (http://www.obdev.at/products/vusb/index.html), which provides an USB stack and also an emulation of the USB physical layer using the old Arduino I/O ports.
Maybe the code can be changed so that instead of using the I/O ports, we configure directly the USB HW interface of Leonardo, in order to let Leonoardo to take care of the physical layer.

I am sorry if something is not precise, there is big confusion/lack of docs/explained code for the new USB capability of leonardo...

Y.
2  Using Arduino / Audio / Re: Leonardo direct MIDI USB on: June 07, 2012, 12:35:25 am
Hi!

yes it is possible, and I am very interested in this topic also. Please read: http://hifiduino.wordpress.com/2011/09/30/arduino-leonardo/, you can see that the new Arduino supports USB-HID class (HID=Human Interface Device), and in this class cathegory you will not need any driver on your computer, it will use the default one for MIDI.

The big step ahead of leonardo is that the USB interface-protocol is fully programmable, hence your Leonardo can act as USB mouse, keyboard, MIDI, as well as USB storage or USB-serial converter.
The big problems is that you need to have a USB protocolstack running on Leonardo, and for me it is not yet clear how to do it. I have had a look at the following stacks:
- LUFA
- AVR USB Stack
- Teensy
- FreakUSB

but I wanted something where the source code is simple and clear to understand (I want to learn some USB internals). I am looking into this direction...

Best,
Y.
3  Using Arduino / Programming Questions / Re: Strange behavior of Timer2 interrupt on: February 21, 2011, 02:06:59 am
Thank you very much!!!
You are completely right, if you do not put an infinite loop at the end of main() the execution terminates. I should not code by night...
BTW, I wonder about the power consumption when the infinite loop is executing, it should be a kind of 'busy form of waiting'.
Is there any instruction in this case to, let's say, put the execution to 'sleep', without consuming any cpu resources, hence running the code only when the interrupts are triggered?

Thanks again.

Y.
4  Using Arduino / Programming Questions / Strange behavior of Timer2 interrupt on: February 20, 2011, 05:05:21 pm
Hi everybody,

I am new to this forum so I take the occasion to say my greetings to all of you.
I am spending some time to play with Arduino and I have my first issue to understand a strange way of working of my code.
Here is the code

Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <WProgram.h>

volatile unsigned char tic_counter = 0;
volatile unsigned char led_toggle = 1;

// interrupt service routine that wraps a user defined function supplied by attachInterrupt
ISR(TIMER2_OVF_vect)         
{
    if (tic_counter++ == 61)
    {
        tic_counter = 0;
        PORTB = led_toggle ? 0xFF : 0x00;
        led_toggle = !led_toggle;
        Serial.println("tic!");
    }

}

// Cofiguration for Timer2
// 16 MHz / 1024 = 15625 Hz (prescaler 1024)
// 15625 Hz / 256 = 61.035 Hz (timer2 resolution)
void tic_setup(void)
{
    // Disable interrupts while setting registers
    cli();

    // Use internal clock - external clock not used in Arduino
    ASSR &= ~(1<<AS2);

    // 17.11.1 TCCR2A – Timer/Counter Control Register A
    //   Bit    7      6      5      4      3      2      1      0
    // (0xB0) COM2A1 COM2A0 COM2B1 COM2B0   –      –    WGM21 WGM20
    //          0      0      0      0      0      0      0      0
    // Compare output mode (OC2A): normal port operation
    // Compare output mode (OC2B): normal port operation
    // Waveform generation mode: normal
    TCCR2A = 0x00;
   
    // TCCR2B – Timer/Counter Control Register B
    //   Bit    7     6     5     4     3     2     1    0
    // (0xB1) FOC2A FOC2B   –     –   WGM22  CS22  CS21 CS20
    //          0     0     0     0     0     1     1    1
    // Output compare A & B: 0
    // Prescaler: clkT2S/1024 (From prescaler)
    TCCR2B = 0x07;
   
    // TCNT2 – Timer/Counter Register
    // When normal mode is selected int TCCR2A and TCCR2B, Timer2 counts
    // upwards
    TCNT2 = 0x00;
   
   
    // TIMSK2 – Timer/Counter2 Interrupt Mask Register
    // Bit      7     6     5     4     3     2     1     0
    // (0x70)   –     –     –     –     –  OCIE2B OCIE2A TOIE2
    //          0     0     0     0     0     0     0     1
    // Output Compare A & B Interr. Enable: 0
    // Overflow Interrupt Enable: 1
    TIMSK2 = 0x01;
   
    // Enable global interrupts
    sei();
}
   
int main()
{
    DDRB = 0xFF; // set PORTB for output
    PORTB = 0xFF;

    Serial.begin(115200);
    Serial.println("Initializing Timer Interrupt");
   
    tic_setup();
   
    while(1) ;   // <=== HERE IS THE PROBLEM!
}

Basically I configure Timer2 to trigger an interrupt with the frequency of ~61Hz.

The strange thing is on the infinite loop at the end of the file: if it is present, everything works fine, if not, then the interrupts are not triggered.
I would have expected that the ints were triggered even without the infinite loop.

I am using Linux and I am building using the command line.

Thanks in advance for any possible feedback.

Best,

Y.
Pages: [1]