|
|
View previous topic :: View next topic |
Author |
Message |
tripper269
Joined: 06 May 2013 Posts: 33 Location: Toronto
|
dsPIC33 DMA |
Posted: Fri Mar 11, 2016 6:29 pm |
|
|
Hi all,
I am working on DSC dsPIC33 starter kit DM330011. I am using CCS v5 in MplabX environment. I am trying to generate a 750 Hz tone. I tested my program with DCI write and it was working fine. Now I am trying to do the same thing with DMA. Idea is to keep CPU free for other tasks and DMA is reading slot over and over again and sending it to DCI. DCI is sending it to codec. Now if I debug my program, it works but in normal mode it doesn't. Below is the code. Please let me know if I am doing something wrong.
Code: |
#include <DSC_initialize.h>
#define FRAME_SIZE 128
#define N_FRAMES 1
#define SIGNAL_SIZE FRAME_SIZE * N_FRAMES
#bank_dma
signed int16 TxBuffer[SIGNAL_SIZE];
#bank_dma
signed int16 RxBuffer[SIGNAL_SIZE];
int main(void)
{
// Define the variables for generating the output signal.
float f = (float)12; // Number of cycles per frame.
float T = (float)1/(float)SIGNAL_SIZE;
int n;
setup_dci((MULTICHANNEL_MODE | DCI_SLAVE | DCI_CLOCK_INPUT |SAMPLE_RISING_EDGE | UNDERFLOW_SILENCE ),
(DCI_1WORD_FRAME | DCI_16BIT_WORD |DCI_1WORD_INTERRUPT),RECEIVE_SLOT0,TRANSMIT_SLOT0,8000);
setup_dma(0, DMA_OUT_DCI, DMA_WORD);
WM8510_Initialize();
dci_start();
// Generate the output waveform.
for(n=0; n < SIGNAL_SIZE; n++)
{
TxBuffer[n] = sin(2*PI*f*(float)n*T) * 0x7FFF;
}
dma_start(0, DMA_CONTINOUS,TxBuffer,127);
output_low(RED_LED);
}
.................... <DSC_initialize.h>.............................................
#include <33FJ256GP506.h>
#include <MATH.H>
#FUSES NOWDT //No Watch Dog Timer
#FUSES OSCIO //OSC2 is general purpose output
#use delay(clock = 80Mhz, internal)
#use FIXED_IO( C_outputs=PIN_C15)
#define YELLOW_LED PIN_C13
#define GREEN_LED PIN_C14
#define RED_LED PIN_C15
#define SWITCH_S1 PIN_D8
#define SWITCH_S2 PIN_D9
/* WM8510 Codec Register Defines, For DSC dsPIC KIT only */
#define WM8510_SOFTWARE_RESET 0
#define WM8510_POWER_MGMT1 2
#define WM8510_POWER_MGMT2 4
#define WM8510_POWER_MGMT3 6
#define WM8510_AUDIO_INTERFACE 8
#define WM8510_COMPANDING_CTRL 10
#define WM8510_CLOCKGEN_CTRL 12
#define WM8510_ADDITIONAL_CTRL 14
#define WM8510_GPIO_STUFF 16
#define WM8510_DAC_CTRL 20
#define WM8510_DAC_VOLUME 22
#define WM8510_ADC_CONTROL 28
#define WM8510_ADC_DIGITAL_VOL 30
#define WM8510_DAC_LIMITER1 48
#define WM8510_DAC_LIMITER2 50
#define WM8510_NOTCH_FILTER1 54
#define WM8510_NOTCH_FILTER2 56
#define WM8510_NOTCH_FILTER3 58
#define WM8510_NOTCH_FILTER4 60
#define WM8510_ALC_CONTROL1 64
#define WM8510_ALC_CONTROL2 66
#define WM8510_ALC_CONTROL3 68
#define WM8510_NOISE_GATE 70
#define WM8510_PLL_N 72
#define WM8510_PLL_K1 74
#define WM8510_PLL_K2 76
#define WM8510_PLL_K3 78
#define WM8510_ATTEN_CTRL 80
#define WM8510_INPUT_CTRL 88
#define WM8510_INP_PGA_CTRL 90
#define WM8510_ADC_BOOST_CTRL 94
#define WM8510_OUTPUT_CTRL 98
#define WM8510_SPK_MIXER_CTRL 100
#define WM8510_SPK_VOLUME_CTRL 108
#define WM8510_MONO_MIXER_CTRL 112
#use i2c(master, SDA = PIN_G3, SCL = PIN_G2)
void WM8510_Initialize(void)
{
// Codec initialization for 8K sample rates
i2c_start();
//Device Address - compiler understands real address * 2
i2c_write(0x34);
i2c_write(WM8510_SOFTWARE_RESET);
i2c_write(0x1);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_POWER_MGMT1);
i2c_write(0b001101111);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_POWER_MGMT2);
i2c_write(0b000010101);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_POWER_MGMT3);
i2c_write(0b010001001);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_AUDIO_INTERFACE);
i2c_write(0b000011000);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_CLOCKGEN_CTRL);
i2c_write(0b110101001);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_ADDITIONAL_CTRL);
i2c_write(0b000001010);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_GPIO_STUFF);
i2c_write(0b000000100);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_ADC_CONTROL);
i2c_write(0b100001000);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_NOTCH_FILTER1);
i2c_write(0b001000000);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_NOTCH_FILTER2);
i2c_write(0b000000101);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_NOTCH_FILTER3);
i2c_write(0b000111111);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_NOTCH_FILTER4);
i2c_write(0b001111101);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_NOTCH_FILTER4);
i2c_write(0b100000000);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_PLL_N);
i2c_write(0b000011000);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_PLL_K1);
i2c_write(0b000001100);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_PLL_K2);
i2c_write(0b010010011);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_PLL_K3);
i2c_write(0b011101001);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_INPUT_CTRL);
i2c_write(0b000000100);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_ADC_BOOST_CTRL);
i2c_write(0b000000000);
i2c_start();
i2c_write(0x34);
i2c_write(WM8510_MONO_MIXER_CTRL);
i2c_write(0b000000001);
i2c_stop();
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19541
|
|
Posted: Sat Mar 12, 2016 1:40 am |
|
|
Comment #1. Don't include libraries before the fuses/clock/serial setups.
Get in the habit of using the sequence:
Include processor file
Setup fuses
Setup clock
Do 'select' setups if appropriate
Setup peripherals (serial/I2C etc.)
Only then include libraries
Then your code
It won't matter in this case, but if you include (for instance) things like stdio, before you have the I/O defined, it won't work properly. Similarly if you include things that are dependant on timings, the clock defines must occur first.
It's just worth getting into the 'habit' of always doing the setups first.
Then is it stopping with the RED LED signal low?.
If so, you do realise it'll go to sleep, before you would see more than a tiny glitch on the output?.
Remember if the code 'drops off the end', the processor goes to sleep. This will stop peripherals like the DMA. In the release notes, it says you "can't use sleep modes with the debugger", hence the difference.... |
|
|
tripper269
Joined: 06 May 2013 Posts: 33 Location: Toronto
|
|
Posted: Sat Mar 12, 2016 12:26 pm |
|
|
Awesome ! Thank you so much for your guidance |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|