Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Direct Digital Synthesis. (DDS)
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Tue Jun 24, 2008 7:00 am    Post subject: Reply with quote

A comment to Matrixx. Its gross overkill to use a DDS just to generate squarewaves. You can do that just by adjusting the reload value of a timer, and using the timer hardware outputs already built into the AVR. But you will find that a squarewave does not sound all that pleasant. For continous audio I tend to use a triangle output, which the DDS does very well.
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
DerWichtel

Bascom Member



Joined: 03 Jul 2008
Posts: 18

blank.gif
PostPosted: Fri Jul 04, 2008 12:51 pm    Post subject: Reply with quote

Does anybody know how I can change the frequency and waveform without interrupts?

I want to a rotary pulse encoder to adjust the frequency and another button to change the waveform.
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Fri Jul 04, 2008 2:37 pm    Post subject: Reply with quote

Hi,

What's wrong with doing that in the interrupt service routine?
The reason to use an interrupt was to keep the assembly loop as shorter as possible.
In the thread there is a sample using INT0 and a sample using the pin change interrupt.

Best regards,

Luciano


Last edited by Luciano on Fri Jul 18, 2008 6:21 am; edited 1 time in total
Back to top
View user's profile
DerWichtel

Bascom Member



Joined: 03 Jul 2008
Posts: 18

blank.gif
PostPosted: Sun Jul 06, 2008 11:41 am    Post subject: Reply with quote

thanks for your answer Luciano but the problem is, that I don't have that many interrupt pins on my avr.

For example how would you use a rotary encoder to adjust the frequency with interrupts?
I have only 2 interrupt pins. int0 and int1 so there is no pin left for the waveformswitchbutton
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sun Jul 06, 2008 4:21 pm    Post subject: Reply with quote

Hi,

Connect one of the encoder line to the INT0 pin. Any logical change on
INT0 will generates an interrupt request. (CONFIG INT0 = CHANGE).

Connect the wave form push button to the INT1 pin. The falling edge of
INT1 will generate an interrupt request. (CONFIG INT1 = FALLING).

Best regards,

Luciano
Back to top
View user's profile
DerWichtel

Bascom Member



Joined: 03 Jul 2008
Posts: 18

blank.gif
PostPosted: Thu Jul 17, 2008 11:09 pm    Post subject: Reply with quote

Hi,
I'm trying to make a code which can adjust the frequency with a button but however I can't get the delta phase written to r24-r26.

this is my code in the interrupt:
Code:

$asm
Loadadr Ldeltaphase , X
ld r24,X+
ld r25,X+
ld r26,X+


ldi  r29,$00                                                ' clear accumulator
ldi  r28,$00                                                ' clear accumulator

ldi  ZH,high (sinetable * 2)                                ' setup Z pointer hi
ldi  ZL,low (sinetable * 2)                                 ' setup Z pointer lo

$end Asm
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Fri Jul 18, 2008 1:28 am    Post subject: Reply with quote

Quote:

Loadadr Ldeltaphase , X
ld r24,X+
ld r25,X+
ld r26,X+

R26 is the low byte of the X register. I would expect this might do wierd things.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
DerWichtel

Bascom Member



Joined: 03 Jul 2008
Posts: 18

blank.gif
PostPosted: Fri Jul 18, 2008 10:06 am    Post subject: Reply with quote

I changed it now to r23-r25. It writes the correct value now into these registers but if I rejump to the loop the old values are restored.
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Fri Jul 18, 2008 2:40 pm    Post subject: Reply with quote

Hi DerWichtel,

Can you please explain what you are trying to achieve?

At page 3 of this thread there is the code that
extracts the 24-bits from a long. These bits are
then stored in three bytes which are used to pass
the values in R24, R25 and R26. (24-bit accumulator).
Note that you can do the same is you declare the three
bytes as OVERLAY variables. I did not use OVERLAY
variables because the original code for the LCD and
keypad was written by David.

Best regards,

Luciano
Back to top
View user's profile
DerWichtel

Bascom Member



Joined: 03 Jul 2008
Posts: 18

blank.gif
PostPosted: Fri Jul 18, 2008 4:23 pm    Post subject: Reply with quote

Hi, problem is solved. I forgot the nosave option of the interrupt.

I want to change the waveform by pressing a button and change the frequency by using a rotary switch. The increasing factor of the frequency should be selected be another button.
this changes should be applied on the fly so I need to use interrupts.

Problem is that I only have 2 interrupt pins on the mega8 but I need at least 3.

However I have solved the problem with the buttons by using together one int pin. ( See attachment)

Now the last problem is the rotary switch.
I connected one encoder line to the int pin as you said before.

But how can I use the encoder command in the interrupt?

it needs to be in a loop or is it enough to only use the following code

Code:

isr_enc:

frequency = Encoder(pinb.0 , Pinb.1 , left , right, 1)

....conversion from frequceny to deltaphase....

loadadr deltaphase,x
ld r24,x+
ld r25,x+
ld r26,x+
 
return


Sry but I'm new to ĩC
Back to top
View user's profile
DerWichtel

Bascom Member



Joined: 03 Jul 2008
Posts: 18

blank.gif
PostPosted: Sun Jan 04, 2009 11:25 pm    Post subject: Reply with quote

Hi,
I have another question. My DDS is running fine now thanks to your help.

However, is there any solution on making a DDS with more than 8bit?

Something like 10bit or even more ( 16bit?). It's because I want my DDS to generate some very short (variable) voltage peaks but the shortest peak I can get is only 1/256 of the cycle time.

I hope someone has a solution. I'm struggling with this problem for more than 2 months now Confused
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Mon Jan 05, 2009 1:52 am    Post subject: Reply with quote

I doubt that using more bits will help, you need a faster clock rate to generate shorter pulses. If you must go fast, and variable voltage output, consider the hardware DDS chips.
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
jenalcom

Bascom Member



Joined: 10 Apr 2004
Posts: 365
Location: Perth, Western Australia

australia.gif
PostPosted: Mon Jan 05, 2009 2:16 am    Post subject: Reply with quote

If you are putting the "pulse" value into your table then you will only ever be able to get a pulse 1/256 of the cycle time (or multiples of). If you increase the table to 1024 (10 bits) then you will only ever be able to get multiples of 1/1024 of the cycle time.

You could increase to effectively 10 bits by using the 256 bit table to represent one quadrant (that is 90 degrees) and using an external 2 bit counter to tell you which quadrant you are in. Then you use the two bit counter so that when:

0 you count up with positive output (0 - 255)
1 you count down with positive output (255 - 0)
2 you count up with negative output (0 - 255)
3 you count down with negative output (255 - 0)
then start again

You could use a word for the 2 bit counter and 8 bit table counter combined.

The problem with this is that the pulse would appear in each quadrant if it is programmed into the table.

Another suggestion (presuming you don't want to use a DDS chip as Adrian suggests) is to recognise when the DDS counter gets to a certain value and then generate the pulse using some (external to the DDS loop) code. You have to make sure your DDS code is "balanced" so that it takes the same time through the loop whether it is running the additional code or not. I made a square wave DDS using this idea to allow me to have variable On/Off ratios irresepective of the frequency being used.

Alan
Back to top
View user's profile
TyM

Bascom Member



Joined: 08 Jan 2009
Posts: 1
Location: Toledo ESPAŅA

spain.gif
PostPosted: Fri Jan 09, 2009 2:27 pm    Post subject: TyN Reply with quote

Hello Luciano, many thanks. Very Happy
Muy agradecido, gracias.


Last edited by TyM on Sat Jan 10, 2009 7:22 pm; edited 1 time in total
Back to top
View user's profile
cowboyrx

Bascom Member



Joined: 05 Feb 2009
Posts: 6

blank.gif
PostPosted: Thu Feb 05, 2009 9:30 pm    Post subject: Reply with quote

I am very new to Bascom/AVR. Is there code available to generate a variable frequency sine wave on only 1 of the pins on mega48 without using a R2R ladder and a bunch of resistors?

Atmel advertises something called a 'fast PWM' and this microcontroller's ability to generate a sine wave.

Thanks...
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 5 of 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum