Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analog Comparator Controller (ACC) #43

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
finalizando codigo comentado
felipebpl committed Jun 6, 2022
commit d56ef01b02b6d8a006a27224f98e2915314e5a94
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Atmel Studio Solution File, Format Version 11.00
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ACC_EXAMPLE1", "ACC_EXAMPLE1\ACC_EXAMPLE1.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "ACC_EXAMPLE", "ACC_EXAMPLE\ACC_EXAMPLE.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,92 +1,3 @@
/**
* \file
*
* \brief Analog Comparator Controller (ACC) example for SAMV71/SAME70.
*
* Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/

/**
* \mainpage acc_irq ACC IRQ Example
*
* \section Purpose
*
* The acc_irq example demonstrates how to use the ACC peripheral to
* detect comparison event on the input pair.
*
* \section Requirements
*
* This example can be used on the following boards:<br>
* - SAMV71-Xplained-Ultra<br>
* - SAME70-Xplained-Pro<br>
*
* \section Description
*
* The acc_irq is aimed to demonstrate the usage of ACC peripheral with
* interrupt support. The DAC0 and AD0 are selected as two inputs.
* The user can change the output voltage of DAC0 and change the voltage
* on AD0.
*
* The output voltage of DAC0 is ranged from (1/6)*ADVREF to (5/6)*ADVREF,and
* the input voltage of AD0 is ranged from 0 to ADVREF.
*
* The comparison event would be generated if the voltage of one input is
* changed across the voltage of the other input. Both bigger and less events
* could be triggered by default.
*
* \section Usage
*
* -# Build the program and download it inside the evaluation board.
* -# On the computer, open and configure a terminal application
* (e.g. HyperTerminal on Microsoft Windows) with these settings:
* - 115200 bauds
* - 8 bits of data
* - No parity
* - 1 stop bit
* - No flow control
* -# In the terminal window, the
* following text should appear (values depend on the board and chip used):
* \code
* -- ACC IRQ Example xxx --
* -- xxxxxx-xx
* -- Compiled: xxx xx xxxx xx:xx:xx --
* -- Menu Choices for this example--
* -- s: Set new DAC0 output voltage.--
* -- v: Get voltage on potentiometer.--
* -- m: Display this menu again.--
* \endcode
* -# Input command according to the menu.
* -# Change voltage on AD0 to see what comparison event happen.
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/

#include "asf.h"
#include "stdio_serial.h"
@@ -118,11 +29,12 @@ void ACC_Handler(void)
{
uint32_t ul_status;

/* Leitura do status do perif�rico */
ul_status = acc_get_interrupt_status(ACC);

/* Compare Output Interrupt */
/* Compara��o da interrup��o de sa�da*/
if ((ul_status & ACC_ISR_CE) == ACC_ISR_CE) {
if (acc_get_comparison_result(ACC)) {
if (acc_get_comparison_result(ACC)) {
puts("-ISR- Voltage Comparison Result: AD0 > DAC0\r");
} else {
puts("-ISR- Voltage Comparison Result: AD0 < DAC0\r");
@@ -191,11 +103,11 @@ static int16_t get_input_voltage(void)
}

ac_str_temp[i] = '\0';
/* Input string length */
/* Tamanho da string de entrada*/
c_length = i;
us_value = 0;

/* Convert string to integer */
/* Converte de string para int */
for (i = 0; i < 4; i++) {
if (ac_str_temp[i] != '0') {
switch (c_length - i - 1) {
@@ -222,63 +134,25 @@ static int16_t get_input_voltage(void)
return us_value;
}

/**
* \brief ACC example application entry point.
*
* \return Unused (ANSI-C compatibility).
*/
int main(void)
{
uint32_t uc_key;
int16_t s_volt = 0;
uint32_t ul_value = 0;
volatile uint32_t ul_status = 0x0;
int32_t l_volt_dac0 = 0;

void init(void){
/* Initialize the system */
sysclk_init();
board_init();

/* Initialize debug console */
configure_console();

/* Output example information */
puts(STRING_HEADER);

/* Initialize DACC */
/* Enable clock for DACC */
pmc_enable_periph_clk(ID_DACC);
/* Reset DACC registers */
dacc_reset(DACC);
/* External trigger mode disabled. DACC in free running mode. */
dacc_disable_trigger(DACC, DACC_CHANNEL_0);
/* Half word transfer mode */
dacc_set_transfer_mode(DACC, 0);
#if (SAM3S) || (SAM3XA)
/* Power save:
* sleep mode - 0 (disabled)
* fast wakeup - 0 (disabled)
*/
dacc_set_power_save(DACC, 0, 0);
#endif


/* Enable output channel DACC_CHANNEL */
dacc_enable_channel(DACC, DACC_CHANNEL_0);
/* Setup analog current */
dacc_set_analog_control(DACC, DACC_ANALOG_CONTROL);

/* Set DAC0 output at ADVREF/2. The DAC formula is:
*
* (5/6 * VOLT_REF) - (1/6 * VOLT_REF) volt - (1/6 * VOLT_REF)
* ----------------------------------- = --------------------------
* MAX_DIGITAL digit
*
* Here, digit = MAX_DIGITAL/2
*/
dacc_write_conversion_data(DACC, MAX_DIGITAL / 2, DACC_CHANNEL_0);
l_volt_dac0 = (MAX_DIGITAL / 2) * (2 * VOLT_REF / 3) / MAX_DIGITAL +
VOLT_REF / 6;

dacc_set_analog_control(DACC, DACC_ANALOG_CONTROL); /* Setup analog current */

/* Enable clock for AFEC */
afec_enable(AFEC0);

@@ -302,21 +176,51 @@ int main(void)

/* Enable channel for potentiometer. */
afec_channel_enable(AFEC0, AFEC_CHANNEL_POTENTIOMETER);

/* Set DAC0 output at ADVREF/2. The DAC formula is:
*
* (5/6 * VOLT_REF) - (1/6 * VOLT_REF) volt - (1/6 * VOLT_REF)
* ----------------------------------- = --------------------------
* MAX_DIGITAL digit
*
* Here, digit = MAX_DIGITAL/2
*/

}

/**
* \brief ACC example application entry point.
*
* \return Unused (ANSI-C compatibility).
*/
int main(void)
{
uint32_t uc_key;
int16_t s_volt = 0;
uint32_t ul_value = 0;
volatile uint32_t ul_status = 0x0;
int32_t l_volt_dac0 = 0;

/* Fun��o para ini�ializa��o do sistema, clocks, DACC e AFEC */
init();

/* Iniciando a entrada DAC0 em ADVREF/2 */
dacc_write_conversion_data(DACC, MAX_DIGITAL / 2, DACC_CHANNEL_0);
l_volt_dac0 = (MAX_DIGITAL / 2) * (2 * VOLT_REF / 3) / MAX_DIGITAL +VOLT_REF / 6;

/* Enable clock for ACC */
pmc_enable_periph_clk(ID_ACC);

/* Initialize ACC */
acc_init(ACC, ACC_MR_SELPLUS_AFE0_AD0, ACC_MR_SELMINUS_DAC0,
ACC_MR_EDGETYP_ANY, ACC_MR_INV_DIS);
/* Inicializa o ACC*/
acc_init(ACC, ACC_MR_SELPLUS_AFE0_AD0, ACC_MR_SELMINUS_DAC0, ACC_MR_EDGETYP_ANY, ACC_MR_INV_DIS);

/* Enable ACC interrupt */
NVIC_EnableIRQ(ACC_IRQn);

/* Enable */
acc_enable_interrupt(ACC);

dsplay_menu();
dsplay_menu(); /* Fun��o para colocar na Terminal Window as op��es do menu */

while (1) {
while (usart_read(CONSOLE_UART, &uc_key)) {
@@ -325,51 +229,40 @@ int main(void)
printf("input: %c\r\n", uc_key);

switch (uc_key) {
case 's':
case 'S':
printf("Input DAC0 output voltage (%d~%d mv): ",
(VOLT_REF / 6), (VOLT_REF * 5 / 6));
s_volt = get_input_voltage();
case 's': /*s: Definir nova tens�o de sa�da DAC0 */
case 'S':
printf("Input DAC0 output voltage (%d~%d mv): ",(VOLT_REF / 6), (VOLT_REF * 5 / 6));
s_volt = get_input_voltage(); /*Pega o valor de tens�o da entrada inserida pelo usu�rio*/
puts("\r");

if (s_volt > 0) {
l_volt_dac0 = s_volt;
/* The DAC formula is:
*
* (5/6 * VOLT_REF) - (1/6 * VOLT_REF) volt - (1/6 * VOLT_REF)
* ----------------------------------- = --------------------------
* MAX_DIGITAL digit
*
*/
ul_value = ((s_volt - (VOLT_REF / 6))
* (MAX_DIGITAL * 6) / 4) / VOLT_REF;
dacc_write_conversion_data(DACC, ul_value, DACC_CHANNEL_0);
/*Coloca novo valor de tens�o*/
ul_value = ((s_volt - (VOLT_REF / 6))* (MAX_DIGITAL * 6) / 4) / VOLT_REF;
dacc_write_conversion_data(DACC, ul_value, DACC_CHANNEL_0);
puts("-I- Set ok\r");
} else {
puts("-I- Input voltage is invalid\r");
}
break;
case 'v':
case 'V':
/* Start conversion */
case 'v': /*v: Pega a voltagem do potenciometro*/
case 'V':
/* Come�a convers�o */
afec_start_software_conversion(AFEC0);
ul_status = afec_get_interrupt_status(AFEC0);
ul_status = afec_get_interrupt_status(AFEC0); /* Leitura do status do perif�rico */
while ((ul_status & AFEC_ISR_EOC0) != AFEC_ISR_EOC0) {
ul_status = afec_get_interrupt_status(AFEC0);
}
/* Conversion is done */
/* Fim da convers�o */
ul_value = afec_channel_get_value(AFEC0, AFEC_CHANNEL_POTENTIOMETER);

/*
* Convert AFEC sample data to voltage value:
* voltage value = (sample data / max. resolution) * reference voltage
*/

/* Converte de AFEC data para valor em voltagem*/
s_volt = (ul_value * VOLT_REF) / MAX_DIGITAL;
printf("-I- Voltage on potentiometer(AD0) is %d mv\n\r", s_volt);
printf("-I- Voltage on DAC0 is %ld mv \n\r", (long)l_volt_dac0);
break;

case 'm':
case 'm': /* m: Exibir este menu novamente */
case 'M':
dsplay_menu();
break;
File renamed without changes.
Binary file not shown.