function generator

Joined
Mar 15, 2008
Messages
17
Reaction score
0
Hello all,
Iam new to this community.i am doing my final year engg proj on fpga.Sythesizable function generator. i have written the codes for sine wave generation,wat must be included to vary the frequency. can someone help me in generating square and triangular wave with variable frequency.
plz mail me at

(e-mail address removed)


Thanks in advance.
sahana
 
Joined
Mar 10, 2008
Messages
348
Reaction score
0
Should be the easy part

Hi
You properly use a counter to generate the sinus?

If you take the most significant bit of this counter will you have a "square wave".

The counter itself could be a sawtooth wave.

lets say the counter 8 bits. b7..b0
then take <b6..b0> directly if b7=0
if b7=1 then calculate output as 128-<b6..b0>
and voula - you got a triangle wave.

Jeppe
---------------------------------------------------------------------------------------------------------------
Hi again
In general can you only get multipla of the max frequency like:

50MHz/2 = 25 MHz
50MHz/3 = 16.67 MHz
...
50MHZ/1000 = 50 kHz
etc

But if you could include an external variable frequency could you get a "true" variable frq.

As for the scale -
Check this example
http://www.jjmk.dk/MMMI/Exercises/05_Counters_Shreg/No7_PWM_vs_SigmaDelta/index.htm

Best regards
Jeppe
 
Last edited:
Joined
Mar 15, 2008
Messages
17
Reaction score
0
hi,

i got the idea of square wave generation, m thankful to jeppe who gave me the idea..
I would lik to know , how to vary the frequency of the generated waves.
like from one range to other.
code is to be dumped on fpga.

my sine wave codes are

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.sine_package.all;

entity sine_wave is
port( clock, reset, enable: in std_logic;
wave_out: out sine_vector_type);
end;

architecture arch1 of sine_wave is
type state_type is ( counting_up, change_down, counting_down, change_up );
signal state, next_state: state_type;
signal table_index: table_index_type;
signal positive_cycle: boolean;
begin

process( clock, reset )
begin
if reset = '1' then
state <= counting_up;
elsif rising_edge( clock ) then
if enable = '1' then
state <= next_state;
end if;
end if;
end process;

process( state, table_index )
begin
next_state <= state;
case state is
when counting_up =>
if table_index = max_table_index then
next_state <= change_down;
end if;
when change_down =>
next_state <= counting_down;
when counting_down =>
if table_index = 0 then
next_state <= change_up;
end if;
when others => -- change_up
next_state <= counting_up;
end case;
end process;

process( clock, reset )
begin
if reset = '1' then
table_index <= 0;
positive_cycle <= true;
elsif rising_edge( clock ) then
if enable = '1' then
case next_state is
when counting_up =>
table_index <= table_index + 1;
when counting_down =>
table_index <= table_index - 1;
when change_up =>
positive_cycle <= not positive_cycle;
when others =>
-- nothing to do
end case;
end if;
end if;
end process;

process( table_index, positive_cycle )
variable table_value: table_value_type;
begin
table_value := get_table_value( table_index );
if positive_cycle then
wave_out <= std_logic_vector(to_signed(table_value,sine_vector_type'length));
else
wave_out <= std_logic_vector(to_signed(-table_value,sine_vector_type'length));
end if;
end process;

end;


PLz could anyone help me in including the code of variable frequency
square and triangular wave.

Thanks in advance:question: :question: :question: :question:

sahana:question:
 
Joined
Mar 15, 2008
Messages
17
Reaction score
0
hi,


the sinewave package is as follows..for the sine wave generator on fpga

library ieee;
use ieee.std_logic_1164.all;

package sine_package is

constant max_table_value: integer := 127;
subtype table_value_type is integer range 0 to max_table_value;

constant max_table_index: integer := 127;
subtype table_index_type is integer range 0 to max_table_index;

subtype sine_vector_type is std_logic_vector( 7 downto 0 );

function get_table_value (table_index: table_index_type) return table_value_type;

end;

package body sine_package is

function get_table_value (table_index: table_index_type) return table_value_type is
variable table_value: table_value_type;
begin
case table_index is
when 0 =>
table_value := 1;
when 1 =>
table_value := 2;
when 2 =>
table_value := 4;
when 3 =>
table_value := 5;
when 4 =>
table_value := 7;
when 5 =>
table_value := 9;
when 6 =>
table_value := 10;
when 7 =>
table_value := 12;
when 8 =>
table_value := 13;
when 9 =>
table_value := 15;
when 10 =>
table_value := 16;
when 11 =>
table_value := 18;
when 12 =>
table_value := 19;
when 13 =>
table_value := 21;
when 14 =>
table_value := 22;
when 15 =>
table_value := 24;
when 16 =>
table_value := 26;
when 17 =>
table_value := 27;
when 18 =>
table_value := 29;
when 19 =>
table_value := 30;
when 20 =>
table_value := 32;
when 21 =>
table_value := 33;
when 22 =>
table_value := 35;
when 23 =>
table_value := 36;
when 24 =>
table_value := 38;
when 25 =>
table_value := 39;
when 26 =>
table_value := 41;
when 27 =>
table_value := 42;
when 28 =>
table_value := 44;
when 29 =>
table_value := 45;
when 30 =>
table_value := 46;
when 31 =>
table_value := 48;
when 32 =>
table_value := 49;
when 33 =>
table_value := 51;
when 34 =>
table_value := 52;
when 35 =>
table_value := 54;
when 36 =>
table_value := 55;
when 37 =>
table_value := 56;
when 38 =>
table_value := 58;
when 39 =>
table_value := 59;
when 40 =>
table_value := 61;
when 41 =>
table_value := 62;
when 42 =>
table_value := 63;
when 43 =>
table_value := 65;
when 44 =>
table_value := 66;
when 45 =>
table_value := 67;
when 46 =>
table_value := 69;
when 47 =>
table_value := 70;
when 48 =>
table_value := 71;
when 49 =>
table_value := 72;
when 50 =>
table_value := 74;
when 51 =>
table_value := 75;
when 52 =>
table_value := 76;
when 53 =>
table_value := 78;
when 54 =>
table_value := 79;
when 55 =>
table_value := 80;
when 56 =>
table_value := 81;
when 57 =>
table_value := 82;
when 58 =>
table_value := 84;
when 59 =>
table_value := 85;
when 60 =>
table_value := 86;
when 61 =>
table_value := 87;
when 62 =>
table_value := 88;
when 63 =>
table_value := 89;
when 64 =>
table_value := 90;
when 65 =>
table_value := 91;
when 66 =>
table_value := 93;
when 67 =>
table_value := 94;
when 68 =>
table_value := 95;
when 69 =>
table_value := 96;
when 70 =>
table_value := 97;
when 71 =>
table_value := 98;
when 72 =>
table_value := 99;
when 73 =>
table_value := 100;
when 74 =>
table_value := 101;
when 75 =>
table_value := 102;
when 76 =>
table_value := 102;
when 77 =>
table_value := 103;
when 78 =>
table_value := 104;
when 79 =>
table_value := 105;
when 80 =>
table_value := 106;
when 81 =>
table_value := 107;
when 82 =>
table_value := 108;
when 83 =>
table_value := 109;
when 84 =>
table_value := 109;
when 85 =>
table_value := 110;
when 86 =>
table_value := 111;
when 87 =>
table_value := 112;
when 88 =>
table_value := 112;
when 89 =>
table_value := 113;
when 90 =>
table_value := 114;
when 91 =>
table_value := 114;
when 92 =>
table_value := 115;
when 93 =>
table_value := 116;
when 94 =>
table_value := 116;
when 95 =>
table_value := 117;
when 96 =>
table_value := 118;
when 97 =>
table_value := 118;
when 98 =>
table_value := 119;
when 99 =>
table_value := 119;
when 100 =>
table_value := 120;
when 101 =>
table_value := 120;
when 102 =>
table_value := 121;
when 103 =>
table_value := 121;
when 104 =>
table_value := 122;
when 105 =>
table_value := 122;
when 106 =>
table_value := 123;
when 107 =>
table_value := 123;
when 108 =>
table_value := 123;
when 109 =>
table_value := 124;
when 110 =>
table_value := 124;
when 111 =>
table_value := 124;
when 112 =>
table_value := 125;
when 113 =>
table_value := 125;
when 114 =>
table_value := 125;
when 115 =>
table_value := 126;
when 116 =>
table_value := 126;
when 117 =>
table_value := 126;
when 118 =>
table_value := 126;
when 119 =>
table_value := 126;
when 120 =>
table_value := 126;
when 121 =>
table_value := 127;
when 122 =>
table_value := 127;
when 123 =>
table_value := 127;
when 124 =>
table_value := 127;
when 125 =>
table_value := 127;
when 126 =>
table_value := 127;
when 127 =>
table_value := 127;
end case;
return table_value;
end;

end;



how to genarate variable frequency signal.

plz if anyone knows , kindly post it..

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top