Pages: [1]   Go Down
Author Topic: High Frequency Outputs with Arduino?  (Read 383 times)
0 Members and 1 Guest are viewing this topic.
Nelson, BC
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am wondering if it is possible to get output frequencies of between 100kHz and 200kHz with Arduino?

From reading the ATMEGA168 data sheet it certainly seems possible if I were to program it in assembly, but I think that would mean I would have to get a new programmer. I'd prefer to just program the ATMEGA using my Arduino board.

Is it possible to access the timers through the Arduino programming environment so that I can get high frequency outputs?

Thanks!

Logged

Brisbane, Australia
Offline Offline
God Member
*****
Karma: 1
Posts: 593
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if I were to program it in assembly, but I think that would mean I would have to get a new programmer.
A) Said programmer is only 4 resistors or so. smiley
B) C is translated to a .hex file and then transfered. Assembly is processed the same way. You'd just need to figure out the right commands to use assembly.
Logged

Nelson, BC
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I found the answer in several posts.

To summarize: you can use the built in Port Manipulation: DDRx, PORTx, PINx to set or clear the pin(s)  and use inline assembly NOPs (or loops of them) to delay the amount you need to create the frequency you need. Each NOP takes 62ns. To execute a NOP you use the inline assembly directive: asm("NOP"); or __asm__("NOP");

http://www.arduino.cc/en/Reference/PortManipulation
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1169088394

Hope this helps anyone else who wants to create fast output frequencies.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Of course, you can put more than "nop" instructions into inline assembler statements, even within code that is to be compiled and downloaded from the arduino environment.  The arudino/wiring/etc encourages use of a somewhat limited subset of the C/C++ languages, but it doesn't restrict you to that subset.

In theory, you  can also write assembler in some other assembly language and somehow produce library files that are compatible with the gnu avr linker.  (I don't know which assemblers can produce these, but there might be SOME!)
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
From reading the ATMEGA168 data sheet it certainly seems possible if I were to program it in assembly, but I think that would mean I would have to get a new programmer. I'd prefer to just program the ATMEGA using my Arduino board.

Someone please correct me if I'm wrong but my understanding is that you could write a pure-assembly program and upload it to the chip on the Arduino using the tools supplied with Arduino.

Until a couple of days ago I hadn't realised this but my research indicates any .hex file can be uploaded to the chip on the Arduino board.

My notes on the topic:

  http://code.rancidbacon.com/Arduino#Bootloader10

But if it met your need, inline assembly sounds like a much better option.

--Phil.
Logged

Pages: [1]   Go Up
Jump to: