how can i generate frequency using Atmega 2560

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmega 2560
F_CPU=16 Mhz
CodeVisionAvr
sine Table = 256
DAC0832

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A. What range of frequencies?

B. What frequency step size can you tolerate (granularity)?

The obvious answer is "DDS" but you will have to provide more information (the questions above) before any useful answer can be provided.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

He didn't actually say what frequency or that it should be variable. Presumably a for() loop stuffing the sin[] table values out to the DAC would produce some frequency ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, you don't even need a DAC to generate a frequency. PWM out will do that, just fine.

By including "sine table = 256" in the spec, that tells us that a simple square wave is probably mot enough. "DAC" suggests the same, especially in combination with "sine .... "

No, the OP did not say that the frequency is to be variable. So, maybe lets back up slightly.

A. What frequency or range of frequencies?

B. If a single frequency, how accurate? If a range of frequencies, what frequency step size can you tolerate (granularity)?

C. Do you want all 256 steps of the sine table to be present in every cycle of the generated signal?

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe he wants to play 3 or 4 of the sine waves to get a pleasing waveform?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I peeked at the info for that chip. Very suitable for 8080 apps. ;) Memory-mapped would work best? If so, then it would seem to be a simple adjustment of jesper's miniDDS after getting the external memory interface going.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is true.

BUT, the solution will be very different if the OP wants 200KHz sine with 256 samples per cycle (256 samples in 80 clocks), vs 62.5KHz at 256 samples (1 sample per clock) vs 50Hz at 256 samples.

That is why frequency or frequency range is so important.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much. For helping me.
I am new to AVR MCU.
Please help me find a solution.
I want to create a sine signal at best.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At http://www.myplace.nu/avr/minidd...
I do not understand.
Resolution = fCPU/150994944 and
fOut = Accumulator * Resolution

150994944=?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

w.panupong wrote:
At http://www.myplace.nu/avr/minidd...
I do not understand.
Resolution = fCPU/150994944 and
fOut = Accumulator * Resolution
150994944=?
You can generate different frequencies with the "Mini DDS", and the frequency resolution (i.e. how large "steps" the frequency can be adjusted with) is calculated with that formula. In your case 16 MHz/150994944 = 0.106 Hz.

The "Mini DDS" looks like a perfect shortcut for your project. Only problem is you need to understand some assembler, but since the code is fairly well-documented you should be able to manage that.

/Jakob Selbing

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The value can also be calculated from 150994944.
why=150994944

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

150994944 = 0x9000000 if it helps?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

150994944 = 0x9000000 Where it came from.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

w.panupong wrote:
150994944 = 0x9000000 Where it came from.
Read the assembler source code and you will find out.

/Jakob Selbing

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

the assembler source code

This comment in particular:

; Output frequency (using 24 bit accumulator) :
;
;	f = deltaPhase * fClock/2^24
;
;   fClock is in this case the CPU clock divided by the
;	number of cycles to output the data ( 9 cycles )
;
;	f = r24/r25/r26 * (11059200/9)/16777216
;
;	f = r24/r25/r26 * 0.073242188
;
;	fMax (theoretical) = 0.5 * fClock

Oh and 2^24 = 0x1000000 = 16777216

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
Actually, you don't even need a DAC to generate a frequency. PWM out will do that, just fine.

By including "sine table = 256" in the spec, that tells us that a simple square wave is probably mot enough. "DAC" suggests the same, especially in combination with "sine .... "

No, the OP did not say that the frequency is to be variable. So, maybe lets back up slightly.

A. What frequency or range of frequencies?

B. If a single frequency, how accurate? If a range of frequencies, what frequency step size can you tolerate (granularity)?

C. Do you want all 256 steps of the sine table to be present in every cycle of the generated signal?

Jim

A. 1Hz - 1Khz
B. range of frequencies (How to accurate frequency)
C. yes i want 256 steps every cycle

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How will you be able to tell if there are 256 steps? It will still look like a 1KHz sine wave with 16 steps per cycle.

Imagecraft compiler user