Commit 33cd64c4 authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Adicionar funções preparativas para o uso do DAC (semana passada)

parent 98295398
Subproject commit e81bcef2be8483242e8dd88ed87210cca693ae5f
Subproject commit 03fbf0a16afa011896e7c8e62bdb5d04484175eb
......@@ -10,7 +10,7 @@ endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT =
USE_COPT =
endif
# C++ specific options here (added to USE_OPT).
......@@ -66,7 +66,7 @@ endif
# Enables the use of FPU (no, softfp, hard).
ifeq ($(USE_FPU),)
USE_FPU = no
USE_FPU = hard
endif
# FPU-related options.
......@@ -170,7 +170,7 @@ UINCDIR =
ULIBDIR =
# List all user libraries here
ULIBS =
ULIBS = -lm
#
# End of user section
......
......@@ -365,7 +365,7 @@
PIN_PUPDR_FLOATING(GPIOA_ARD_A1) | \
PIN_PUPDR_FLOATING(GPIOA_ARD_D1) | \
PIN_PUPDR_FLOATING(GPIOA_ARD_D0) | \
PIN_PUPDR_PULLUP(GPIOA_ARD_A2) | \
PIN_PUPDR_FLOATING(GPIOA_ARD_A2) | \
PIN_PUPDR_FLOATING(GPIOA_LED_GREEN) | \
PIN_PUPDR_PULLUP(GPIOA_ARD_D12) | \
PIN_PUPDR_PULLUP(GPIOA_ARD_D11) | \
......
......@@ -29,7 +29,7 @@
#define CHCONF_H
#define _CHIBIOS_RT_CONF_
#define _CHIBIOS_RT_CONF_VER_6_0_
#define _CHIBIOS_RT_CONF_VER_6_1_
/*===========================================================================*/
/**
......
......@@ -65,7 +65,7 @@
* @brief Enables the DAC subsystem.
*/
#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
#define HAL_USE_DAC FALSE
#define HAL_USE_DAC TRUE
#endif
/**
......@@ -79,7 +79,7 @@
* @brief Enables the GPT subsystem.
*/
#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
#define HAL_USE_GPT FALSE
#define HAL_USE_GPT TRUE
#endif
/**
......@@ -427,7 +427,7 @@
* buffers.
*/
#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_USB_BUFFERS_SIZE 2048
#define SERIAL_USB_BUFFERS_SIZE 256
#endif
/**
......
......@@ -126,8 +126,8 @@
/*
* DAC driver system settings.
*/
#define STM32_DAC_DUAL_MODE FALSE
#define STM32_DAC_USE_DAC1_CH1 FALSE
#define STM32_DAC_DUAL_MODE TRUE
#define STM32_DAC_USE_DAC1_CH1 TRUE
#define STM32_DAC_USE_DAC1_CH2 FALSE
#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 10
#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 10
......@@ -141,7 +141,7 @@
#define STM32_GPT_USE_TIM2 FALSE
#define STM32_GPT_USE_TIM3 FALSE
#define STM32_GPT_USE_TIM4 FALSE
#define STM32_GPT_USE_TIM6 FALSE
#define STM32_GPT_USE_TIM6 TRUE
#define STM32_GPT_USE_TIM7 FALSE
#define STM32_GPT_USE_TIM8 FALSE
#define STM32_GPT_USE_TIM15 FALSE
......
......@@ -6,6 +6,7 @@
#include "./threads/status.h"
#include "./threads/sensors.h"
#include "./threads/display.h"
#include "./threads/dac.h"
#include "./threads/comm.h"
#include "./usb/usbcfg.h"
......@@ -42,6 +43,8 @@ int main(void) {
palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(14)); // USB
palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG); // ADC1_IN2
palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_ANALOG); // ADC3_IN5
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); // Reduce power consumption as we're using the DAC here
palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); // Reduce power consumption as we're using the DAC here
/*
* Initializes USB serial interfaces
......@@ -73,6 +76,7 @@ int main(void) {
chThdCreateStatic(waStatus, sizeof(waStatus), NORMALPRIO, Status, NULL);
// chThdCreateStatic(waDisplay, sizeof(waDisplay), NORMALPRIO, Display, NULL);
chThdCreateStatic(waSensors, sizeof(waSensors), NORMALPRIO, Sensors, NULL);
chThdCreateStatic(waDAC, sizeof(waDAC), NORMALPRIO, DACt, NULL);
chThdCreateStatic(waComm, sizeof(waComm), NORMALPRIO, Comm, NULL);
/*
......
#include "ch.h"
#include "hal.h"
#include "board.h"
#include "dac.h"
#include <math.h>
static const DACConfig dac1cfg1 = {
.init = 2047U,
.datamode = DAC_DHRM_12BIT_RIGHT,
};
static const DACConversionGroup dacgrpcfg1 = {
.num_channels = 1U,
.trigger = DAC_TRG(0)
};
/*
* GPT6 configuration.
*/
static const GPTConfig gpt6cfg1 = {
.frequency = DAC_RATE,
.callback = NULL,
.cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */
.dier = 0U
};
void generate_waveform(float amplitude, waveform_t type, dacsample_t *buf) {
switch(type) {
case SINE:
for (uint32_t i = 0; i < DAC_BUFFER_SIZE; ++i) {
buf[i] = (amplitude * 2047.0f * sinf((2.0f*PI*i)/DAC_BUFFER_SIZE)) + 2047;
}; break;
}
}
THD_WORKING_AREA(waDAC, 512);
THD_FUNCTION(DACt, arg) {
(void)arg;
chRegSetThreadName("dac");
dacStart(&DACD1, &dac1cfg1);
gptStart(&GPTD6, &gpt6cfg1);
generate_waveform(0.8, SINE, dac_buffer);
dacStartConversion(&DACD1, &dacgrpcfg1,
(dacsample_t *)dac_buffer, DAC_BUFFER_SIZE);
gptStartContinuous(&GPTD6, 2U);
while (true) {
//thread_t *tp = chMsgWait();
gptChangeInterval(&GPTD6, 2U);
chThdSleepMilliseconds(5000);
gptChangeInterval(&GPTD6, 10U);
chThdSleepMilliseconds(5000);
gptChangeInterval(&GPTD6, 100U);
chThdSleepMilliseconds(5000);
gptChangeInterval(&GPTD6, 1000U);
chThdSleepMilliseconds(5000);
gptChangeInterval(&GPTD6, 10000U);
chThdSleepMilliseconds(5000);
}
}
#ifndef DAC_H
#define DAC_H
extern THD_WORKING_AREA(waDAC, 512);
THD_FUNCTION(DACt, arg);
/*
* DAC buffer.
*/
#define DAC_RATE 1000000U
#define DAC_BUFFER_SIZE 360
static dacsample_t dac_buffer[DAC_BUFFER_SIZE] = {0};
typedef enum {
SINE = 0,
TRIANGULAR,
SAWTOOTH,
} waveform_t;
#define PI 3.14159
#endif /* DAC_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment