Is arduino suitable for high frequency application

2019-08-10 12:05发布

问题:

Can I use the arduino for an application with a frequency of 4 MHz?

I need to create a clk with this frequency and send and receive data on the rising and falling edges. and it is not a normal SPI interface I have my own conditions so I need to do it manually.

If it is not suitable, is it technically possible?

回答1:

The maximum PWM you could generate with an arduino Mega 2560 is 62500 Hz. I don't think you can go beyond that. Method

You can use the internal SPI so with a 16MHz oscillator you could have upto some where from 16MHz to (16/128)MHz. Method



回答2:

You can PWM output at 4MHz with the Timer1 (ATMega328 and ATmega32U4), here is an example for UNO/NANO (ATMega328):

    pinMode(10, OUTPUT); // Output pin
    // Set Timer1 to phase and frequency correct mode. NON-inverted mode
    TCCR1A = _BV(COM1A1) | _BV(COM1B1); 

    // Set prescaler to clk/1 (outputs from 122,072Hz to 4MHz
    TCCR1B = _BV(WGM13) | _BV(CS10);

    //ICR Register, which controls the PWM total pulse length
    ICR1 = 2; // value 2 makes pulse width = 2 clock cycles (with clk/1 prescaler)
    //OCR Registers, which control the PWM duty cycle.
    // OCR1A + OCR1B must be = IRC1.
    OCR1A = 1; // 1 pulse of the IRC1 total pulse length will be HIGH
    OCR1B = 1; // 1 pulse of the IRC1 total pulse length will be HIGH

TIP: You can use other IRC1 and OCR1 values for other frequencies and duty cycles. Frequency = 8000000/IRC1.

Example: IRC1 = 4, OCR1A = 1, OCR1B = 3

Will output a PWM like this:

frequency of 8000000/IRC1 = 8000000/4= 2000000Hz = 2MHz

1 clock cycle will be HIGH (OCRA1=1), 3 clock cycles will be LOW (OCR1B=3)

duty cycle of OCR1A/IRC1 = 1/4 = 25%

NOTE: Any Arduino code that uses TIMER1 won´t work after this (or will work erratically). Arduino uses TIMER1 for Servo library.



标签: arduino