10kHz Sine Wave Generator on DAC / PIT using FRDM K64F

cancel
Showing results for 
Search instead for 
Did you mean: 

10kHz Sine Wave Generator on DAC / PIT using FRDM K64F

Jump to solution
591 Views
farhanfarooq93
Contributor II

Hello,

I want to generate 10khz sine wave and read it back on ADC0 to perturb Battery source. But i am only getting 33 Hz frequency on DAC_out. I am new with the Freedom Boards. I studied some examples in MCUXpresso IDE (SDK 2.6) .Below is the code i am using

Thanks

Tags (3)
1 Solution
353 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Farhan Farooq ,

   Do you use the PIT to trigger the DAC output?

   If yes, what's the PIT frequency you are using? If you want to get the 10khz sine wave, you need to configure the DAC sine data table, then use the PIT to trigger and output it to the DAC, your PIT must more quick than 10Khz, take an example, if one sine wave is divided to 10 points, then your PIT trigger frequency should be 100Khz, so I suggest you test your PIT trigger time is correct or not, then add the DAC code again.


Have a great day,
Kerry

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

3 Replies
353 Views
kerryzhou
NXP TechSupport
NXP TechSupport

BTW, next time, please create your kinetis question to the kinetis forum, this is the RT community, the kinetis forum is :

Kinetis Microcontrollers 

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
353 Views
farhanfarooq93
Contributor II

Thank you for your Reply. i will follow on Kinetis Microcontrollers  next time.

I am getting 10.4 khz after i decreases number of samples to 18 per cycle as per following  your instruction. my timer value is 5us. 

further i will read data through ADC at the same time. so what is your suggestion about that. DAC will send, ADC will  Read and processing at the in real time.

Clock Waveform 100khz

pastedImage_4.jpg

DAC output 10khz

pastedImage_3.jpg

this is my code

#define PIT_LED_HANDLER PIT0_IRQHandler
#define PIT_IRQ_ID PIT0_IRQn
/* Get source clock for PIT driver */
#define PIT_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)

void PIT_LED_HANDLER(void)
{
sample = SinusOutputData[is];

is=is+14;
if (is >= SINUS_LENGTH)
{
is = 0;
}

GPIO_PortToggle(BOARD_INITPINS_PTA01_GPIO, 1U << BOARD_INITPINS_PTA01_PIN);
GPIO_PortToggle(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN);
DAC_SetBufferValue(DEMO_DAC_BASEADDR, 0U, (sample));
pitIsrFlag = false;

/* Clear interrupt flag.*/
PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, kPIT_TimerFlag);

mycount++;
__DSB();
}

/*!
* @brief Main function
*/
int main(void)
{
/* Define the init structure for the output LED pin*/
gpio_pin_config_t led_config = {
kGPIO_DigitalOutput,
0,
};
/*
/* Board pin, clock, debug console init */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
BOARD_InitBootPins();

/* Structure of initialize PIT */
pit_config_t pitConfig;
/*
* pitConfig.enableRunInDebug = false;
*/
PIT_GetDefaultConfig(&pitConfig);

/* Init pit module */
PIT_Init(PIT, &pitConfig);

/* Set timer period for channel 0 */
PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(5U, PIT_SOURCE_CLOCK));
//PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, 500200080);

countValue = USEC_TO_COUNT(5U, PIT_SOURCE_CLOCK);
PRINTF("pit scource clock : %d\r\n", PIT_SOURCE_CLOCK);

PRINTF("total count : %f\r\n", countValue);
/* Enable timer interrupts for channel 0 */
PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);

/* Enable at the NVIC */
EnableIRQ(PIT_IRQ_ID);

/* Start channel 0 */
PRINTF("\r\nStarting channel No.0 ...");
PIT_StartTimer(PIT, kPIT_Chnl_0);

dac_config_t dacConfigStruct;

/* Init output LED GPIO. */
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &led_config);

DAC_GetDefaultConfig(&dacConfigStruct);
DAC_Init(DEMO_DAC_BASEADDR, &dacConfigStruct);
DAC_Enable(DEMO_DAC_BASEADDR, true); /* Enable output. */


while (1)
{
}
}

0 Kudos
354 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Farhan Farooq ,

   Do you use the PIT to trigger the DAC output?

   If yes, what's the PIT frequency you are using? If you want to get the 10khz sine wave, you need to configure the DAC sine data table, then use the PIT to trigger and output it to the DAC, your PIT must more quick than 10Khz, take an example, if one sine wave is divided to 10 points, then your PIT trigger frequency should be 100Khz, so I suggest you test your PIT trigger time is correct or not, then add the DAC code again.


Have a great day,
Kerry

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post