NIOS II 15:AD7606共享SDRAM

1、首先登陆analog官网下载此文件

 

下载此文档如下

2、解压后一会这个文件复制到我们工程内

 

 

3、把之前SDRAM工程复制一份,在ip文件夹内复制第2步里边的AD7606文件夹。

4、打开qsys,左侧能看到如下,如果看不到。点击tools--options,里边加入路径就能看到了

5、qsys加入ad7606IP核,连线。注意avalon master 一定要连接到sdram的S1,因为我们AD数据要存在sdram内。

正常下载的ad7606ip核他的输出端口是一个conduit,但是我把每个都变成了一个conduit,原因是因为我的quartus18版本不这样改会报错,对于低版本的是没问题的,不需要改成这样

6、生成。之后修改verilog顶层文件如下,有些多余的忽略,是我测试用的。由于我没有使用AD7606很多range、os什么之类的,所以这里没有给出io,这个无所谓的。

module SDRAMTEST
(
    CLK_50M,
    RST_N,
    LEDOUT,    
    sdram_clk,
    sdram_addr,
    sdram_ba,
    sdram_cas_n,
    sdram_cke,
    sdram_cs_n,
    sdram_dq,
    sdram_dqm,
    sdram_ras_n,
    sdram_we_n,
    uart_0_rxd,
    uart_0_txd,
    
    ad7606_busy,
    ad7606_convst,
    ad7606_cs,
    ad7606_rd,
    ad7606_reset,
    ad7606_data,
    
    ad7606_busy1,
    ad7606_convst1,
    ad7606_cs1,
    ad7606_rd1,
    ad7606_reset1
    

);

    input             CLK_50M;
    input                    RST_N;
    output    [7:0]       LEDOUT;
    output                sdram_clk;
    output    [12:0]    sdram_addr;
    output    [1:0]        sdram_ba;
    output                sdram_cas_n;
    output                sdram_cke;
    output                sdram_cs_n;
    inout        [15:0]    sdram_dq;
    output    [1:0]        sdram_dqm;
    output                sdram_ras_n;
    output                sdram_we_n;
    input                    uart_0_rxd;
    output                uart_0_txd;

    input                    ad7606_busy;
    output                ad7606_convst;
    output                ad7606_cs;
    output                ad7606_rd;
    output                ad7606_reset;
    input        [15:0]    ad7606_data;

    
    output                ad7606_busy1;
    output                ad7606_convst1;
    output                ad7606_cs1;
    output                ad7606_rd1;
    output                ad7606_reset1;

    
assign     ad7606_busy1=ad7606_busy;
assign     ad7606_convst1=ad7606_convst;
assign     ad7606_cs1=ad7606_cs;
assign     ad7606_rd1=ad7606_rd;
assign     ad7606_reset1=ad7606_reset;
    
    

mysys u0 (
    .clk_clk                                 (CLK_50M),
    .pio_led_export                          (LEDOUT),
    .reset_reset_n                           (RST_N),
    .sdram_clk_clk                           (sdram_clk),
    .sdram_addr                              (sdram_addr),
    .sdram_ba                                (sdram_ba),
    .sdram_cas_n                             (sdram_cas_n),
    .sdram_cke                              (sdram_cke),
    .sdram_cs_n                              (sdram_cs_n),
    .sdram_dq                                (sdram_dq),
    .sdram_dqm                               (sdram_dqm),
    .sdram_ras_n                             (sdram_ras_n),
    .sdram_we_n                              (sdram_we_n),
    .uart_0_rxd                              (uart_0_rxd),
    .uart_0_txd                              (uart_0_txd),
    
    .ad7606_0_busy_beginbursttransfer            (ad7606_busy), 
    .ad7606_0_convst_writeresponsevalid_n        (ad7606_convst),
    .ad7606_0_cs_n_export                         (ad7606_cs),
    .ad7606_0_os_readdata                            (ad7606_os),
    .ad7606_0_range_writeresponsevalid_n        (ad7606_range),
    .ad7606_0_rd_writeresponsevalid_n            (ad7606_rd),
    .ad7606_0_adreset_writeresponsevalid_n        (ad7606_reset),
    .ad7606_0_stdby_writeresponsevalid_n        (ad7606_stdby),
    .ad7606_0_data_writebyteenable_n                (ad7606_data),
    );


endmodule

 

7、例化管脚之后全编译。

8、打开elipse。在这里我使用的方法比较笨,我不知道怎么把那个ad7606.c还有.h文件调用不报错,总是报错,所以我自己重新新建了文件。

9、右键1处新建文件夹AD7606,之后右键AD7606在里边分别建两个文件夹inc和src如下

10、之后在这两个文件夹内分别生成如下文件。这个文件不是我写的,而是从analog官网第1步下载的文件里边就有,我都复制过来了。

11、之后主程序如下写,这是从小梅哥的程序里边拷贝的

/*
 * "Hello World" example.
 *
 * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
 * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
 * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
 * device in your system's hardware.
 * The memory footprint of this hosted application is ~69 kbytes by default
 * using the standard reference design.
 *
 * For a reduced footprint version of this template, and an explanation of how
 * to reduce the memory footprint for a given application, see the
 * "small_hello_world" template.
 *
 */

#include <stdio.h>
#include <unistd.h>
#include <alt_types.h>
#include <io.h>
#include <system.h>
#include <ad7606.h>

void send_voltage(alt_16 *data, alt_u8 size, alt_u8 channel){
    int i = 0,j=0;
    volatile float Voltage;

    printf("\n\n");
    for(j=0;j<size/channel;j++)
    {
        printf("voltage :");
        for(i=0;i<channel;i++)
        {
            Voltage = *data * (10.0/65536);

            if(Voltage < 0)
                printf("%2.4f,%4x;",Voltage,(alt_u16) *data);
            else
                printf("+%2.4f,%4x;",Voltage,(alt_u16) *data);
            data ++;
        }
        printf("\n");

    }
}

int main()
{

    alt_u32 data_base = (SDRAM_BASE | 0x80000000) + 65536 * 8;

    alt_u32 size;

    alt_16 *data;
    AD7606_Reset();    //复位AD7606控制器


unsigned i=0;
 while(1)
 {
        //采样8个通道
        AD7606_WriteRegister(CHAN8 | OS16 | NO_STAND_BY);
        //采样size个数据,存储到SDRAM中
        size = 16;
        AD7606_StartAcquisition(size, data_base);
        usleep(1000000);
        //等待采样完成
        while (!(AD7606_ReadStatus() & 0x00000001));
        data = data_base;

        send_voltage(data,size,8);
        usleep(1000000);

 //printf("Hello from Nios II!,i is %d\n",i);
  i++;
//  usleep(1000000);
 }
  return 0;
}
 

12、下载后运行如下,运行发现貌似不太对,因为貌似一个数占了32位,不是16位呢。

13、于是乎这个地方每次地址+2

14、这样便对了,究竟是哪里位宽没对上,暂时不知道

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值