-1

Here I need to output a waveform on oscilloscope in C which should in a rising sawtooth waveform.I am not sure if my code is correct. Any help or suggestions?

while(1)
{
    for (i = 1; i < 360; i++);

    // Check to see if status.TRDY is 1
    while(*(base+2) & 0x40 != 1);

    // while shift register is not empty
    // Make the sawtooth pattern
    if (saw == 0x1fff){
        saw = 0x1000;
    }
    else {
        saw = saw+1; 
    }
    // transmit sawtooth to the oscilloscope
    *(base+1) = saw;
}
4

1 回答 1

0

这只会整理 OP 发布的代码。它没有回答如何对 DAC 进行编程。OP 使用 16 位幅度值,但他的寄存器寻址建议使用 8 位寄存器 - 可能需要两次写入。

我建议您还需要定义锯齿波周期和步数的函数参数。您还需要一个退出条件。我把这些点留给你。

@Chris Stratton 还评论说 I/O 端口应该是正确的语言类型。

#define MINSAW  0x1000
#define MAXSAW  0x1FFF

unsigned *base = (unsigned *)0xD000;  // "insert your value"

int main()  {
    unsigned saw, i;
    while(1) {
        for (i = 0; i < 360; i++) {
            // ratio the waveform amplitude
            saw = MINSAW + i * (MAXSAW - MINSAW) / 359;

            // Check to see if status.TRDY is 1
            while((*(base+2) & 0x40) != 0x40);

            // transmit sawtooth to the oscilloscope
            *(base+1) = saw;
        }
    }
    return 1;
}
于 2014-11-17T18:15:29.927 回答