View previous topic :: View next topic |
Author |
Message |
Robert_Pre
Joined: 04 Mar 2010 Posts: 53
|
Posted: Thu Jan 23, 2014 9:17 pm Post subject: PWM for Sinus generator too low in frequency |
|
|
hello
how can i make a sinus osc with the PWM with a frequency about 10khz?
my prog here is good but only 1000hz!
thanks for help
' Oscillateur Sinus en PWM
'================================
$regfile = "m328pdef.dat"
$crystal = 20000000 '11059200
$hwstack = 32
$swstack = 10
$framesize = 40
'Variables
Dim N As Word
Dim M As Byte
Dim A As Byte
Ddrb = &B000111 'pour les pull up
'----------------------------------------------------------
Config Timer1 = Pwm , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down ', Pwm = 8 ,
Start Timer1
Do
Restore Datasinus ' replace les pointeurs sur le début du tableau
For N = 1 To 256 ' 128 '64
Read M 'lit la table
Pwm1b = M ' la valeur dans PWM1B détermine la valeur du PWM
' Waitus 0.4 'la valeur de l'attente permet de changer la fréquence
Next N
Loop
'---------------------------------------------------------------------------------------------------------------------------
Datasinus: 'tableau des valeurs sinusoidales
Data 127 , 130 , 133 , 136 , 139 , 142 , 145 , 148 , 151 , 154 , 157 , 160 , 163 , 166 , 169 , 172,
Data 175 , 178 , 181 , 184 , 187 , 189 , 192 , 195 , 197 , 200 , 202 , 205 , 207 , 210 , 212 , 214,
Data 217 , 219 , 221 , 223 , 225 , 227 , 229 , 231 , 232 , 234 , 236 , 237 , 239 , 240 , 242 , 243,
Data 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 251 , 252 , 252 , 253 , 253 , 253 , 253 , 253,
Data 253 , 253 , 253 , 253 , 253 , 252 , 252 , 251 , 251 , 250 , 250 , 249 , 248 , 247 , 246 , 245,
Data 244 , 242 , 241 , 240 , 238 , 237 , 235 , 233 , 232 , 230 , 228 , 226 , 224 , 222 , 220 , 218,
Data 216 , 213 , 211 , 209 , 206 , 204 , 201 , 199 , 196 , 193 , 191 , 188 , 185 , 183 , 180 , 177,
Data 174 , 171 , 168 , 165 , 162 , 159 , 156 , 153 , 150 , 147 , 144 , 141 , 138 , 135 , 131 , 128,
Data 125 , 122 , 119 , 116 , 113 , 110 , 106 , 103 , 100 , 97 , 94 , 91 , 88 , 85 , 82 , 79,
Data 76 , 74 , 71 , 68 , 65 , 63 , 60 , 57 , 55 , 52 , 50 , 47 , 45 , 42 , 40 , 38,
Data 36 , 33 , 31 , 29 , 27 , 25 , 23 , 22 , 20 , 18 , 17 , 15 , 14 , 12 , 11 , 10,
Data 8 , 7 , 6 , 5 , 4 , 4 , 3 , 2 , 2 , 1 , 1 , 0 , 0 , 0 , 0 , 0,
Data 0 , 0 , 0 , 0 , 0 , 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9,
Data 10 , 11 , 13 , 14 , 16 , 17 , 19 , 20 , 22 , 24 , 26 , 28 , 30 , 32 , 34 , 36,
Data 38 , 41 , 43 , 45 , 48 , 50 , 53 , 55 , 58 , 61 , 63 , 66 , 69 , 72 , 74 , 77,
Data 80 , 83 , 86 , 89 , 92 , 95 , 98 , 101 , 104 , 107 , 110 , 114 , 117 , 120 , 123 , 126,
(BASCOM-AVR version : 2.0.7.6 ) _________________ F1GHO |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Jan 23, 2014 10:34 pm Post subject: Re: PWM for Sinus generator too low in frequency |
|
|
Robert_Pre wrote: | how can i make a sinus osc with the PWM with a frequency about 10khz? |
Use less support points. Assumed the ideal condition that after each 8bit PWM cycle a new sine point is loaded, one complete sine takes 20000000 / 256 pwm / 256 sine points = 305Hz
If you use a R2R resistor network, you can speed it up by the PWM factor.
Quote: | my prog here is good but only 1000hz! |
You only reach a higher frequency as said 305Hz, as sine support points are omitted then, because they are loaded faster than one PWM cycle takes. |
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 584 Location: Cleveland, OH
|
Posted: Fri Jan 24, 2014 4:17 am Post subject: |
|
|
Two more thoughts:
You can switch to an Xmega, which can run at 32 MHz, giving you more clock cycles to work with.
You can switch techniques on how you generate the sin wave.
Right now you have a fixed loop rate, and each pass you take the next sample from the data table.
Read the samples faster for a higher frequency.
If you switch techniques, and use a DDS approach, you can easily get 50 KHz sin, and if you are very good, even higher.
In the DDS approach one still has a data table. One uses interrupts to read from the table. One always uses the same interrupt rate regardless of the output frequency. One changes which sample is read from the table to change frequency. The program skips over samples in the table, and doesn't read them out one by one.
Jesper's Mini DDS is one good example of this technique.
Wiki DDS, (Direct Digital Synthesis), and the data sheets for chips which do this, (Analog Devices), have good explanations of how the method works.
JC |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Fri Jan 24, 2014 11:51 am Post subject: |
|
|
You might use ATtiny25/45/85 (different memory capacity) with fuses set to PLL Clock. No Quartz. Then you will get PWM frequency of 256kHz.
Regards, meister |
|
Back to top |
|
|
benoit
Joined: 24 Jul 2007 Posts: 177
|
Posted: Fri Jan 24, 2014 5:39 pm Post subject: |
|
|
HELLO
You can speed up the m328 clock with external oscillator at 32mhz it works fine , quartz dont work.
|
|
Back to top |
|
|
benoit
Joined: 24 Jul 2007 Posts: 177
|
Posted: Fri Jan 24, 2014 5:40 pm Post subject: |
|
|
HELLO
and of course limit the numbers of sinus samples. |
|
Back to top |
|
|
Robert_Pre
Joined: 04 Mar 2010 Posts: 53
|
Posted: Sun Jan 26, 2014 9:14 am Post subject: |
|
|
OK merci je vais suivre ces pistes _________________ F1GHO |
|
Back to top |
|
|
|
|
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
|
|