avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-chat] Need help with simple inline assembly code


From: Ben Mann
Subject: RE: [avr-chat] Need help with simple inline assembly code
Date: Wed, 6 Jul 2005 09:10:48 +0800

Hi Reza,

Something like this has worked for me in the past:

        //remove the nop line if the ldi achieves the same delay
        //requirement
        asm volatile ( 
                "ldi r24, %1\n\t" 
                "out %0, r24\n\t" 
                "nop\n\t"
                :: "g"(_SFR_ADDR(PORTD)), "g"(value) : "r24" );

Bear in mind the avr instruction set - "out" transfers a register's contents
not a literal value, so you have to load the register first. Constraint "g"
might not be technically correct but works perfectly.

On an aside, generating 10Mhz from 15Mhz is going to leave substantial
jitter in the resulting signal - ie it can't be 'exactly' 10mhz without
outside help - ie an external clock and logic. If you find a way I'm all
ears.

Ben

-----Original Message-----
I'm trying to generate a very fast (10mhz-ish) bit train from an avr 
running at ~15mhz.  The only way i can think of doing it is using inline 
assembly.  I've been trying to compile something like tihs, but I'm 
getting no love.  Any suggestions?

thnx,
reza

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/pgmspace.h>
#include <avr/delay.h>
#include <inttypes.h>
#include <stdio.h>


int main(void) {
        while(1) {
                asm volatile("out %0, %1":: "I" 
(_SFR_IO_ADDR(PORTD))),"M" (254);
                asm volatile("nop"::);
                asm volatile("out %0, %1":: "I" 
--snip!--







reply via email to

[Prev in Thread] Current Thread [Next in Thread]