View previous topic :: View next topic |
Author |
Message |
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Tue Jun 24, 2008 7:00 am Post subject: |
|
|
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 |
|
|
DerWichtel
Joined: 03 Jul 2008 Posts: 18
|
Posted: Fri Jul 04, 2008 12:51 pm Post subject: |
|
|
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 |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Fri Jul 04, 2008 2:37 pm Post subject: |
|
|
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 |
|
|
DerWichtel
Joined: 03 Jul 2008 Posts: 18
|
Posted: Sun Jul 06, 2008 11:41 am Post subject: |
|
|
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 |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Sun Jul 06, 2008 4:21 pm Post subject: |
|
|
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 |
|
|
DerWichtel
Joined: 03 Jul 2008 Posts: 18
|
Posted: Thu Jul 17, 2008 11:09 pm Post subject: |
|
|
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 |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Fri Jul 18, 2008 1:28 am Post subject: |
|
|
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 |
|
|
DerWichtel
Joined: 03 Jul 2008 Posts: 18
|
Posted: Fri Jul 18, 2008 10:06 am Post subject: |
|
|
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 |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Fri Jul 18, 2008 2:40 pm Post subject: |
|
|
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 |
|
|
DerWichtel
Joined: 03 Jul 2008 Posts: 18
|
Posted: Fri Jul 18, 2008 4:23 pm Post subject: |
|
|
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 |
|
|
DerWichtel
Joined: 03 Jul 2008 Posts: 18
|
Posted: Sun Jan 04, 2009 11:25 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Jan 05, 2009 1:52 am Post subject: |
|
|
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 |
|
|
jenalcom
Joined: 10 Apr 2004 Posts: 365 Location: Perth, Western Australia
|
Posted: Mon Jan 05, 2009 2:16 am Post subject: |
|
|
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 |
|
|
TyM
Joined: 08 Jan 2009 Posts: 1 Location: Toledo ESPAŅA
|
Posted: Fri Jan 09, 2009 2:27 pm Post subject: TyN |
|
|
Hello Luciano, many thanks.
Muy agradecido, gracias.
Last edited by TyM on Sat Jan 10, 2009 7:22 pm; edited 1 time in total |
|
Back to top |
|
|
cowboyrx
Joined: 05 Feb 2009 Posts: 6
|
Posted: Thu Feb 05, 2009 9:30 pm Post subject: |
|
|
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 |
|
|
|