Hallo Zusammen, auch wenn ich Gefahr laufe in Ungnade zu fallen frage ich es einfach. Kennt jemand ein Brauchbares Beispiel für DAC für STM32F100? ich will einfach an einem Ausgang ein Pegel mit bestimmter Höher einstellen können. 0..bis (max was das Ding her gibt) mfg Denis
Hi
1 | #define DAC1_VOLT 1.2f
|
2 | #define DAC2_VOLT 1.58f
|
3 | #define REF_VOLT 3.3f
|
4 | #define DAC_ACC 4096.0f
|
5 | const uint16_t _DAC1_DATA = (uint16_t)(((DAC1_VOLT / REF_VOLT) * DAC_ACC) + 0.5f); |
6 | const uint16_t _DAC2_DATA = (uint16_t)(((DAC2_VOLT / REF_VOLT) * DAC_ACC) + 0.5f); |
7 | |
8 | void DacOn(void) |
9 | {
|
10 | GPIO_InitTypeDef GPIO_InitStructure; |
11 | DAC_InitTypeDef DAC_InitStructure; |
12 | |
13 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); |
14 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); |
15 | |
16 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
17 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
18 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_DAC1 | GPIO_Pin_DAC2; |
19 | GPIO_Init(GPIOA, &GPIO_InitStructure); |
20 | |
21 | DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; |
22 | DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; |
23 | DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; |
24 | DAC_Init(DAC_Channel_1, &DAC_InitStructure); |
25 | DAC_Init(DAC_Channel_2, &DAC_InitStructure); |
26 | |
27 | DAC_Cmd(DAC_Channel_1, ENABLE); |
28 | DAC_Cmd(DAC_Channel_2, ENABLE); |
29 | |
30 | DAC_SetChannel1Data(DAC_Align_12b_R, _DAC1_DATA); |
31 | DAC_SetChannel2Data(DAC_Align_12b_R, _DAC2_DATA); |
32 | |
33 | DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE); |
34 | DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE); |
35 | }
|
Vielen dank für die Rückmeldung! auch wenn ich den Quellcode noch nicht hundert Prozent verstanden habe, werde ich es bei nächster Gelegenheit ausprobieren mfg Denis
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.