Using the basys3 development board and the Da2 p-mod. It is the intention of these following codes to produce a sin waveform and output that on to an oscillscope.
module AHBPmod( input wire HCLK, input wire HRESETn, input wire [31:0] HADDR, input wire [1:0] HTRANS, input wire [31:0] HWDATA, input wire HWRITE, input wire HSEL, input wire HREADY, //Output output wire HREADYOUT, output wire [31:0] HRDATA. output wire [3:0] DA2 ;i reg [31:0] last_HADDR; reg [1:0] last_HTRANS; reg last_HWRITE; reg last_HSEL; assign HREADYOUT = 1'b1; // Set Registers from address phase always @(posedge HCLK) begin if (HREADY) begin last_HADDR <= HADDR; last_HTRANS cm HTRANS; last_HWRITE <= HWRITE; last_HSEL ?= HSEL; end end always @(posedge HCLK) begin I/DA2 logic //1khz SINE WAVE J/aT LEAST DOUBLE THE NUMBER OF SAMPLES //1KHZ AT LEAST 2000 I/GENERATE BY LOOK UP TABLE //bIG FAT ARRAY (in C) first element in list is sine at time =0(0) //2nd element in array is sine at itmeslice 1 //3rd Sine of timeslice =2 I/Work out timeslice IITimeslice look at clock fequency //Do some maths for sione wave frequency [/For loop through samples IITime for loop through sample
always @(posedge HCLK) begin //DA2 logic //1khz SINE WAVE //aT LEAST DOUBLE THE NUMBER OF SAMPLES //1KHZ AT LEAST 2000 //gENERATE BY LOOK UP TABLE //bIG FAT ARRAY (in C) first element in list is sine at time =0(0) //2nd element in array is sine at itmeslice 1 //3rd Sine of timeslice =2 //Work out timeslice //Timeslice look at clock fequency //Do some maths for sione wave frequency //For loop through samples //Time for loop through sample
volatile static unsigned int counter =0; volatile static int j=0; const static unsigned int sineWave[arraySize] = {128,131,134,137,140,143,147,150, 153,156,159,162,165,168,171,174,177,180,183,186,189,192,194,197, 200,202,205,208,210,212,215,217219,222,224,226,228,230,232,233235,237,238,240,241,243,244,245247,248,249,250,251,251,252,253253,254,254,255,255,255,255,255255,255,255,254,254,253,253,252251,251,250,249,248,247,245,244243,241,240,238,237,235,233,232230,228,226,224,222,219,217,215212,210,208,205,202,200,197,194192,189,186,183,180,177,174,171,168,165,162,159,156,153,150,147143,140,137,134,131,128,124,121118,115,112,108,105,102,99,96,93,90,87,84,81,78,75,72,69,66,63,61,58,55,53,50,47,45,43,40,38,36,33,31,29,27,25,23,22,20,18,17,15,14,12,11,10,8,7,6,5,4,4,3,2,2,1,1,0,0,0,0,0,0,0,0,1,1,2,2,3,4,4,5,6,7,8,10,11,12,14,15,17,18,20,22,23,25,27,29,31,33,36,38,40,43,45,47,?
50,53,55,58,61,63,66, void DAC_Write(int value)\{ static const unsigned int mask[] ={0×0001,0×0002,0×0004,0×0008,0×0010,0×0020,0×0040,0×0080 O/SYNC =1 I/SYNC =0 I/for i in 0 to 15 II clock goes high II datawire = value bit i II clock falling edge \}