Author Topic: Pulse width modulation  (Read 3775 times)

0 Members and 1 Guest are viewing this topic.

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Pulse width modulation
« on: September 24, 2011, 04:34:58 am »
I want to generate custom waveforms from a wavetable so I want to know how exactly can you controll the frequency acurately since pause gives me very low frequencies.
This is the wavetable of a saw for instance:

 _    _    __   __  ____

_ ____ ____  ___  __   

I really don't know if this is going to work :P

If you like my work: why not give me an internet?








Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Pulse width modulation
« Reply #1 on: September 24, 2011, 04:37:28 am »
Maybe use a simple for loop for your delay?  For loops are pretty fast so it would give you some of the highest control of the possible delay.

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Pulse width modulation
« Reply #2 on: September 24, 2011, 04:47:59 am »
Is this okay?
Code: [Select]
Lbl WAVE
.Gbd1WV is the wavetable that consists of 1's and 0's
.r1 is the delay between
.r2 is the amount of waves
for(C,0,r2
  for(B,0,31
    {Gbd1WV+B}->port
    while 1
      A+1->A
    endif A=r1
  end
end
If you like my work: why not give me an internet?








Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Pulse width modulation
« Reply #3 on: September 24, 2011, 04:52:25 am »
Note that you will have to reset A every itteration, or else once it gets to r1, it the while loop will only execute once after that.  You could also decide to set A to r1, and decrement A instead of incrementing it, and use an End!IF A, which would make it slightly faster I believe. 

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Pulse width modulation
« Reply #4 on: September 24, 2011, 05:11:01 am »
Lolthatsstupid :) Changed it:
Code: [Select]
Lbl WAVE
.Gbd1WV is the wavetable that consists of 1's and 0's
.r1 is the delay between
.r2 is the amount of waves
for(C,0,r2
  for(B,0,31
    {Gbd1WV+B}->port
    r1->A
    while 1
      A-1->A
    end!if A
  end
end
Will this work?

If you like my work: why not give me an internet?








Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Pulse width modulation
« Reply #5 on: September 24, 2011, 10:10:47 am »
Here's a more optimized version (which will probably allow you to use more precise values for r1)
Code: [Select]
While 1
  GDB1WV
  For(32)
    {->r3}->Port
    r1
    While 1
    End!If -1
    r3+1
  End
End!If r2-1->r2

Edit: Removed an unnecessary store instruction
« Last Edit: September 24, 2011, 10:13:35 am by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Pulse width modulation
« Reply #6 on: September 25, 2011, 03:20:34 am »
Next step: Blending sound. The Idea is that the notes blend even if they're 3 "steps long" and another note from the other channel that is just one step long comes in the second step.

Like this:
|1  ||2  ||3  |

     [A-3]
[C-2__________]

|1  ||2  ||3  |


How do I tackle this problem?

I made a white noise generator too with pretty awesome results:
Code: [Select]
While 1
  rand^4->Port
  r1
  While 1
  End!If -1
End!If r2-1->r2
If you like my work: why not give me an internet?








Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Pulse width modulation
« Reply #7 on: September 26, 2011, 01:01:38 pm »
I figured that there has to be a 30% duty cycly within a duty cycle to blend the sounds from 3 channels. Can I blend the sounds acurately?
If you like my work: why not give me an internet?