Go Down

Topic: Arduino DDS Sinewave Generator (Read 28828 times) previous topic - next topic

dc42

You need to rename file ad9835_forum_arduino.ino to AD9835.h, and inside that file change #include "WProgram.h" to #include "Arduino.h".
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

haydensmart

Hi all,
Long time reader, first time seeker.

I am trying to create a Pure Sine Wave, Fixed Frequency Inverter utilizing a H-Bridge output circuit feeding a Transformer. This way I can use half the DC Voltage to produce the same Final Output. The issue I have is that whilst utilizing one output, the the Transformer is always live as I swap the polarity of the winding when I turn off. This creates Noise and reduces efficiency.

My Aim is to utilize two PWM outputs and achieve the following.

Positive Wave Cycle Output A Utilises PWM Signal from Sin of the Angle Output B Remains Low.
    This Pulses DC+ on the 48V Terminal of Transformer Input and Maintains DC- on The 0V Terminal
    This will eliminate the Reversing of the Input Winding when the Output is low.
Negative Wave Cycle Output B Remains Low and Output B Utilizes PWM signal from Sin of the Angle.
    This Maintains DC- on the 48V Terminal of the Transformer Input and Pulsed DC+ on the 0V Terminal

Could anyone please help me with code or any further suggestions?

haydensmart

Just a Quick update that people may be interested in.

What I have done to work my previous post is to create a second wave 180 deg out, then use the sin of the angle to set the pwm rate.

To do this I use an actual sin table as opposed to the amplitude sin map, then to create an inverse wave i simply use inv of sin = (1-(Sin of angle))-1

if sin of the angle =< 0 set the pwm to 0
if sin of the angle > 0 set the pwm to (sin of angle * 100%)

100% is 254 on 8bit PWM

I will post code soon.

_eric_

Hi,

dfreq and refclk are double and pow return a double.

the result of this calcul should be a double:
Code: [Select]
tword_m=pow(2,32)*dfreq/refclk;  // calulate DDS new tuning word


But tword_m is declared as volatile unsigned long.

Can you explain ?

_eric_

#34
Mar 19, 2014, 07:20 pm Last Edit: Mar 19, 2014, 09:01 pm by _eric_ Reason: 1
I don't understand the use of tword_m and phaccu.
Why multiply by 2^32 and then divide by 2^24  with icnt=phaccu >> 24?

directly in main  :

Code: [Select]
icnt = 256 * defreq / refclk; // 256 = sizeof (sine256)

with defreq, refclk and icnt unsigned int long.

_eric_

I have tested with in the Interrupt :
 
Code: [Select]
offset += icnt;
  if (offset > 255) offset = 0; 
  OCR2A=pgm_read_byte_near(sine256 + offset);


It's OK but poor resolution...

I have now understand the effect Of 2^32 multiplication for the high resolution.
Very interesting concept !

pito

#36
Mar 19, 2014, 09:43 pm Last Edit: Mar 19, 2014, 09:56 pm by pito Reason: 1
When working with AD98xx dds chips you have to work with 64bit (long long) as otherwise the calculated tuning word will be not precise..
For example:
Code: [Select]
volatile long long unsigned int tword_m = (4294967296LL * dfreq) / refclk;  // calulate DDS new tuning word

AdaZus

#37
Jul 02, 2014, 01:06 pm Last Edit: Jul 02, 2014, 01:09 pm by AdaZus Reason: 1
Hello,
firstly many thanks at Martin for your useful and interesting work about sine wave generation on Arduino!
I build it in the same way and amplified the sinevawe with the TDA7052. It works fine.
But now I need also to regulate the volume with a digital potentiometer.
I found this example:
http://www.instructables.com/id/Digital-Potentiometer-MCP41100-and-Arduino/all/?lang=de
Unfortunately the ISP communication needs PIN 11 for MOSI.
http://arduino.cc/de/Reference/SPI
To solve this problem, I tried to change the frequency output pin11 to pin3,
pinMode(11, OUTPUT);     // pin11= PWM  output / frequency output now
pinMode(3, OUTPUT);     // pin3= PWM  output / frequency output

Timer 2 is assigned to pin11 and pin3
http://www.micha.st/?Arduino-Notizbuch:Erfahrungen:Never_touch_timer0, but it didn't work.  

Are there also other changes to make? Maybe anyone knows what to do?


rbarr80

Is there a wiring diagram for this function generator?

badoumba

#39
Mar 16, 2015, 05:21 pm Last Edit: Mar 16, 2015, 05:30 pm by badoumba
Hello experts.

I tried this code which is obviously working very well, but must be adapted for a specific need I have: on the full range of audio frequencies (20Hz - 20KHz), I would need some waveform with the lesser possible distortion rate and an almost constant volume.

- I will add a class 2 Butterworth low-pass filter instead so to have a flat output from my active band.

- I was wondering if upgrading for a 512 resolution and 2ms instead of 4 would be possible with my Arduino Uno board? I don't have any scope, so I can't figure out what the code would produce. This will reject the distorsion frequencies much higher I imagine and reduce their volume at the same time (20log512 > 20log256). What would be the best possible output with this Arduino board (and should I upgrade it as well)?

Thanks for any thought!


PS: I am not visiting so often in this forum. I apologize if I omit to thank some of you for their replies on previous posts, this might have happened!


germancorrea

has anyone tryed to run this code on a Arduino Due using same PWM

Can you supply code modifications

alexandr_st

Hello guys,
Please can you help me to run code of sinewave generator on Arduino Nano   atMega328 IC?  I'm new user of Arduino and haven't any knowleges of programming. Compiller write next message "Arduino: 1.6.3 (Windows XP), board Arduino Nano, ATmega328"

DDS_generator.ino:16:10: error: 'prog_uchar' does not name a type

In file included from DDS_generator.ino:13:0:

DDS_generator.ino: In function 'void __vector_9()':

DDS_generator.ino:118:28: error: 'sine256' was not declared in this scope

I need to generate sinewave signal for servomotor resolver for output signal reading. My big thanks for any answers!



alexandr_st

Problem solved. My best wishes to guys from russian cyberforum!

PROGMEM  prog_uchar sine256[]

replaced to

const PROGMEM  unsigned char sine256[]

board generate signal  excellent

Virtualan

Hello,
firstly many thanks at Martin for your useful and interesting work about sine wave generation on Arduino!
I build it in the same way and amplified the sinevawe with the TDA7052. It works fine.
But now I need also to regulate the volume with a digital potentiometer.
I found this example:
http://www.instructables.com/id/Digital-Potentiometer-MCP41100-and-Arduino/all/?lang=de
Unfortunately the ISP communication needs PIN 11 for MOSI.
http://arduino.cc/de/Reference/SPI
To solve this problem, I tried to change the frequency output pin11 to pin3,
pinMode(11, OUTPUT);     // pin11= PWM  output / frequency output now
pinMode(3, OUTPUT);     // pin3= PWM  output / frequency output

Timer 2 is assigned to pin11 and pin3
http://www.micha.st/?Arduino-Notizbuch:Erfahrungen:Never_touch_timer0, but it didn't work. 

Are there also other changes to make? Maybe anyone knows what to do?


I had similar issue using a UNO. I had to make the following changes to get it on pin 3.

pinMode(6, OUTPUT);      // sets the digital pin as output
pinMode(7, OUTPUT);      // sets the digital pin as output
pinMode(3, OUTPUT);     // pin11= PWM  output / frequency output

then change the PWM timer...

// Timer2 Clock Prescaler to : 1
  sbi (TCCR2B, CS20);
  cbi (TCCR2B, CS21);
  cbi (TCCR2B, CS22);

  // Timer2 PWM Mode set to Phase Correct PWM
  cbi (TCCR2A, COM2B0);//  <<<<<<<    Change these // clear Compare Match
  sbi (TCCR2A, COM2B1);//  <<<<<<<

  sbi (TCCR2A, WGM20);  // Mode 1  / Phase Correct PWM
  cbi (TCCR2A, WGM21);
  cbi (TCCR2B, WGM22);

then change the read line to..

OCR2B=pgm_read_byte_near(sine256 + icnt);

Hope it works for you.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy