Jump to content

Tommy 777

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by Tommy 777

  1. I tried to use Eclypse Z7 and ADC 1410 to collect the Sin wave signal which is between -5V to 5V, but I found something strange. The channel 1 just gets -4.6V to 5V and the channel 2 just gets -5V to 4.6V. They all cannot get the whole signal from -5V to 5V. Is that the problem about the hardware or the programming? Thanks for any suggestion.
  2. Hi: @artvvb Thanks for your answers. it works!!!!, that is really helpful. And I have understood your explanation about length, I really learn much. Thanks for your patient and help, hope there is another chance to discuss with you in the future.
  3. Hi @artvvb Thanks for your answer. I have tried to change the code as you posted, but unfortunately it cannot solve the problem. I am a beginner so I hope to discusses this problem more and share my ideas with you. First of all, in your answer, you think the length may count past the end of the allocated buffer, but the demo limits the length when data get overflow like: if (length > ((1<<14) - 1)) { // limit the length to maximum buffer size (1<<14 - 1) length = ((1<<14) - 1); // adjust step step = amplitude/(length>>2); } I think this code could make sure the length will not over the limitation of buffer (14 bit ), because of that, I don't need to calculate the length to make sure it is not over the maximum buffer size when the amplitude and step are modified. So I think it is not the key point of this problem. Next I want to share some of my findings about the problem. I think the problem may happen in the DMA but not the DAC buffer. (I think they are two different things, if I am wrong please tell me). Here are some evidence. First, assume the problem happens in the DAC buffer, when I just call the DAC function, there should be a same problem and the DAC could not generate the correct waveform. But in fact, the DAC could work perfectly when I just call it. Secondly, assume the problem happens in the DAC buffer, the problem will have no relationship with the order in which DAC and ADC are called. In the other word, whatever I call ADC first or DAC first, the problem will always happen in DAC and ADC will work perfectly. But in fact, when I call the ADC first, the DAC could not work; while I call the DAC first, the ADC could not work. thirdly, according to the feedback of SDK 'Can't allocate DMAEnv for 40410000', I found the source code in dam.c document, which is in 'zmodlib>Zmod' folder. The code is as follow: /** * Initialize the DMA. * * @param dmaBaseAddr the base address of the DMA device * @param direction the direction of the DMA transfers * @param dma_interrupt_id the interrupt number of the DMA device * * @return a pointer to an instance of DMAEnv */ uint32_t fnInitDMA(uintptr_t dmaBaseAddr, enum dma_direction direction, int dma_interrupt_id) { DMAEnv *dmaEnv = (DMAEnv *)malloc(sizeof(DMAEnv)); ivt_t ivt[] = { { dma_interrupt_id, (XInterruptHandler)fnDMAInterruptHandler, dmaEnv }, }; if (!dmaEnv) { xil_printf("Can't allocate DMAEnv for %X\n", dmaBaseAddr); return 0; } // Init interrupt controller if (!fIntCInit) { fnInitInterruptController(&sIntc); fIntCInit = true; } dmaEnv->xAxiDma = (XAxiDma *)malloc(sizeof(XAxiDma)); if (!dmaEnv->xAxiDma) { xil_printf("Can't allocate XAxiDma for %X\n", dmaBaseAddr); return 0; } dmaEnv->base_addr = fnConfigDma(dmaEnv->xAxiDma, dmaBaseAddr); if (dmaEnv->base_addr < 0) { xil_printf("DMA configuration failure for %X\n", dmaBaseAddr); fnDestroyDMA((uint32_t)dmaEnv); return 0; } // Enable all interrupts in the interrupt vector table fnEnableInterrupts(&sIntc, &ivt[0], sizeof(ivt)/sizeof(ivt[0])); dmaEnv->direction = direction; if (dmaEnv->direction == DMA_DIRECTION_RX) { // enable AXIDMA S2MM IOC interrupt writeDMARegFld(dmaEnv->base_addr, AXIDMA_REGFLD_S2MM_DMACR_IOC_IRQ, 1); } else{ // DMA_DIRECTION_TX // enable AXIDMA MM2S IOC interrupt writeDMARegFld(dmaEnv->base_addr, AXIDMA_REGFLD_MM2S_DMACR_IOC_IRQ, 1); } return (uint32_t)dmaEnv; } According to this, I think the problem is DMA initialisation failed. Back to my code, the programme stops at: ZMODDAC1411 dacZmod(ZMOD_DAC_BASE_ADDR, DMA_DAC_BASE_ADDR, IIC_DAC_BASE_ADDR, FLASH_ADDR_DAC, DMA_DAC_IRQ); This code is the initialisation of DAC and the address of the second parameter 'DMA_DAC_BASE_ADDR' is '40410000'. (Here I choose the DAC as the example just because I call the ADC first in my code and the DAC initialisation failed. I have tried to call DAC first and in that situation, the ADC initialisation will failed and the SDK shows 'Can't allocate DMAEnv for 40400000' which is the DMA base address for ADC). More over, I found the DDR cannot allocate addresses for ADC initialisation and DAC initialisation at the same time. I have tried the one shot test of my code, like: void dacRampDemo(float offset, float amplitude, float step, uint8_t channel, uint8_t frequencyDivider, uint8_t gain, uint8_t checkpoint) { ZMODDAC1411 dacZmod(ZMOD_DAC_BASE_ADDR, DMA_DAC_BASE_ADDR, IIC_DAC_BASE_ADDR, FLASH_ADDR_DAC, DMA_DAC_IRQ); } void ADCBaremetalDemo(uint8_t channel,uint8_t gain) { ZMODADC1410 adcZmod(ZMOD_ADC_BASE_ADDR, DMA_ADC_BASE_ADDR, IIC_ADC_BASE_ADDR, FLASH_ADDR_ADC, ZMOD_ADC_IRQ, DMA_ADC_IRQ) } int main() { ADCBaremetalDemo(0,0); dacRampDemo(0, 5, 2, 0, 8, 1,checkpoint); return 0; } I just post the struct here for reading convenience. In one shot test, there is not loop and the processing is start > call ADC > ADC initialisation > realise ADC function > return void(free the ADC initialisation at same time) > call DAC > DAC initialisation > realise DAC function > return void(free the DAC initialisation at the same time)> return 0. So I assume that because the ADC function and the DAC function will free the initialisation, in one shot test, the DAC and the ADC initialisation will not affect each other and they both work by order. In order to prove my guess, I use 'static' to fixed the ADC initialisation like: static ZMODADC1410 adcZmod(ZMOD_ADC_BASE_ADDR, DMA_ADC_BASE_ADDR, IIC_ADC_BASE_ADDR, FLASH_ADDR_ADC, ZMOD_ADC_IRQ, DMA_ADC_IRQ) In this situation, the DMA of DAC cannot be initialised. It proves my guess that when ADC has been initialised, ADC DMA will occupy something and the DAC DMA cannot be allocated. In summary, I think the problem is the initialisation of DAC. More specifically, it is the initialisation of DMA failed when the DAC and the ADC are initialised at the same time. Next are some possible reasons I guess: As I stated before, the problem is the DMA initialisation failed when the DAC and the ADC are initialised together, so I focus my eyes on the function of DMA initialisation. There are two possibilities, one is the parameter has problem and another is the code gets problem. In the aspect of code, I don't find any obvious bug. I also tried the 'new' function to replace the 'malloc' function but nothing improved. In the aspect of parameter, the only one I am not sure is the direction of DMA transform. In my opinion, the direction of DMA transform in ADC is from device to DMA and that is from DMA to device in DAC. If it is true, is there any possible when ADC has been initialised, the direction of DMA has been set and it is not suitable for DAC, that cause the DAC DMA initialisation failed? Looking forward to your further answer, thank you.
  4. Hi: When I try to initialize the ADC and DAC in a same void function, the SDK shows me that 'Can't allocate DMAEnv for 40410000'. '40410000' is the address of DMA_DAC_BASE_ADDR. Because of that, DAC cannot generate the correct waveform when ADC works perfect. By the way, it works perfectly when I just use DAC or ADC. Thanks for any suggestion. Update 26th January My project is using the ADC collect the data and compare the data with the threshold, DAC will generate the different waveform according to the result of comparative. Update 27th January The problem has been solved!!!! Tanks to @artvvb I will share some experience here to help others. First, just like what @artvvb said you need change the size of heap and the default value is just 2000, if you hope to initialise the ADC and DAC at the same time. Secondly, don't forget to use static to avoid the duplicate initialisation in loop, or the heap will overflow again. By the way, in my code, I enable two I2C, so the I2C base address of ADC and ADC are different. If you use the default demo from the GitHub, please follow the answer from @artvvb.
×
×
  • Create New...