cancel
Showing results for 
Search instead for 
Did you mean: 

DAC Module with Timer 4 trigger

SShiv
Associate

Hello,

I am working on STM8L-Discovery DAC module.

I have used Timer 4 trigger (1Khz) and DMA transfer is enabled.

But my DAC_OUT1 pin PF0 isn't giving a sine wave. 

I want to know what mistake I might have done.

Thanks in advance.

Regards,

Sandeep

Tool Used - IAR Workbench

Code-

#include "stm8l152C6.h"

uint16_t Sinus12bit[130] = {1800, 1887, 1974, 2060, 2146, 2231, 2315, 2397, 2479,

                  2559, 2637, 2713, 2786, 2858, 2927, 2994, 3057, 3118,

                  3176, 3230, 3281, 3329, 3373, 3414, 3450, 3483, 3512,

                  3537, 3558, 3574, 3587, 3595, 3599, 3599, 3595, 3587,

                  3574, 3558, 3537, 3512, 3483, 3450, 3414, 3373, 3329,

                  3281, 3230, 3176, 3118, 3057, 2994, 2927, 2858, 2786,

                  2713, 2637, 2559, 2479, 2397, 2315, 2231, 2146, 2060,

                  1974, 1887, 1800, 1713, 1626, 1540, 1454, 1369, 1285,

                  1203, 1121, 1041, 963, 887, 814, 742, 673, 606, 543, 482,

                  424, 370, 319, 271, 227, 186, 150, 117, 88, 63, 42, 26, 13,

                  5, 1, 1, 5, 13, 26, 42, 63, 88, 117, 150, 186, 227, 271, 319,

                  370, 424, 482, 543, 606, 673, 742, 814, 887, 963, 1041,

                  1121, 1203, 1285, 1369, 1454, 1540, 1626, 1713};

void SetPowerRegisters(void)

{

 PWR->CSR1=0X0B;          // PVD on, Threshold 2.85 V

 RST->SR=0xff;  

}

void SetClock(void)

{

 CLK->CKDIVR = 0x00;        // No Clock Division

 CLK->CRTCR = 0x00;        // No RTC clock selected 

 CLK->ICKCR = 0x01;        // HSI On

 CLK->PCKENR1 |= 0x84;       // DAC and TIM4 clock enabled

 CLK->PCKENR2 |= 0x20;       // DMA1 clock enabled

 //CLK->PCKENR3 |= 0x08; 

 CLK->SWR = 0x01;         // HSI as system clock

}

void SetPort(void)

 GPIOE->DDR |= 0x80; 

 GPIOE->CR1 |= 0x80;    

 GPIOE->CR2 |= 0x80;

 GPIOE->ODR = 0x80;         // LED at PE7

}

void SetTIM4(void)

{

 TIM4->IER|=0x01;           // Trigger and Update interrupt enabled

 TIM4->CR1 |= 0x81;          // Counter enable

 TIM4->CR2 |= 0x20;          // TIM4 TRGO selection 

 TIM4->SMCR|=0x00;

 TIM4->PSCR |= 0x06;//0x05;         // Set the Prescaler value 

 TIM4->DER|=0x01;           // DMA Request Enable

 TIM4->EGR|=0x00;

 TIM4->CNTR |=0x00;

 TIM4->ARR = 89;

}

void SetDAC(void)

{

 DAC->CH1CR1 |= 0x05;//0x04;//0x05; // Timer 4 Trigger and DAC Channel enabled

 DAC->CH1CR2 |= 0x10;//0x10;//0x30; // DMA enabled

 //DAC->SR |= 0x01;         // DAC underrun detection

 //DAC->SWTRIGR |=0x01;       // Enable Software Trigger

}

void SetDMA(void)

{

  

 DMA1_Channel3->CCR |= 0x38;     // channel 3 enabled, Memory to Peripheral, Memory Increment, Circular

 DMA1->GCSR = 0xFD;         // Max time out, DMA global channel 

  

 uint16_t Add;

  

 DMA1_Channel3->CPARH = 0x53;     // peripheral address

 DMA1_Channel3->CPARL = 0x88;

  

 Add = (uint16_t)&Sinus12bit[0];

  

 DMA1_Channel3->CM0ARL = Add;     // memory address

 DMA1_Channel3->CM0ARH = Add>>8;

  

 DMA1_Channel3->CNBTR = 2;     // 100 no of data transfer

 DMA1_Channel3->CSPR = 0x38;

  

}  

void main( void )

{

 SetClock();

 SetPort();

 GPIOF->DDR|=0x01;

 GPIOF->ODR|= 0x00;

 SetDMA();

 SetDAC();

 SetTIM4();

 while(1)

 {

   

 }

}

1 REPLY 1
S.Ma
Principal

To find out the bug location, try to use the TIMER real pin and maually connect to the DAC trigger pin.

This way, you will be able to manually narrow down where is the issue.