/******************************************************************************* * DISCLAIMER * This software is supplied by Renesas Electronics Corporation and is only * intended for use with Renesas products. No other uses are authorized. This * software is owned by Renesas Electronics Corporation and is protected under * all applicable laws, including copyright laws. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * Renesas reserves the right, without notice, to make changes to this software * and to discontinue the availability of this software. By using this software, * you agree to the additional terms and conditions found by accessing the * following link: * http://www.renesas.com/disclaimer * (c) 2014 Renesas Electronics Corporation All rights reserved. *******************************************************************************/ /****************************************************************************** * File Name : r_adc.c * Version : 1.0 * Device(s) : R7F701007 RH850/F1L * Tool-Chain : IAR Embedded Workbench 1.30.1 * Description : This file is a sample of the ADC. * Operation : - ******************************************************************************* ******************************************************************************* * History : DD.MM.YYYY Version Description * : 20.03.2014 1.00 First Release ******************************************************************************/ /****************************************************************************** Includes ******************************************************************************/ #include "r_typedefs.h" #include "iodefine.h" #ifdef __ghs__ #include "device.h" #endif #ifdef __IAR_SYSTEMS_ICC__ #include #endif /****************************************************************************** Imported global variables and functions (from other files) ******************************************************************************/ /****************************************************************************** Macro definitions ******************************************************************************/ /****************************************************************************** Exported global variables and functions (to be accessed by other files) ******************************************************************************/ void R_ADC_Init( void ); /****************************************************************************** Private global variables and functions ******************************************************************************/ /****************************************************************************** * Function Name : void R_ADC_Init( void ) * Description : This function initialize ADCA0. * Argument : none * Return Value : none ******************************************************************************/ void R_ADC_Init( void ) { /* Set interrupt flags */ MKADCA0ERR = 1U; RFADCA0ERR = 0U; TBADCA0ERR = 0U; /* Common control the ADCAn ADCAnADCR - A/D Control Register b31:b 8 - Reserved set to 0 b 7 DGON - Self-Diagnostic Voltage Standby Control - The self-diagnostic voltage circuit is turned off. Set to 0'b. b 6 - Reserved set to 0 b 5 CRAC - Alignment Control - The results of conversion to WDDR and ADCAnDRj are stored rightaligned. Set to 0'b. b 4 CTYP - 12/10 Bit Select Mode - 12-bit mode. Set to 0'b. b 3:b 2 - Reserved set to 0 b 1:b 0 SUSMTD - Suspend Mode Select - Synchronous suspend when a higher-priority SG or SVSTOP interrupt. Set to 0'b. */ ADCA0.ADCR.UINT32 = 0x00000000UL; /* Controls the sampling time for SG4 (PWM-Diag) and SG1 to SG3. ADCAnSMPCR - Sampling Control Register b31:b 8 - Reserved set to 0 b 7:b 0 SMPT - These bits are used to set the sampling time (the number of cycles). - 18 cycles (ADCACLK = 8 MHz to 32 MHz) */ ADCA0.SMPCR.UINT32 = 0x00000012UL; /* Set safety control. ADCAnSFTCR - Safety Control Register b31:b 5 - Reserved set to 0 b 4 RDCLRE - Read & Clear Enable - ADCAnPWDDR/ADCAnDRj and ADCAnPWDDIR / ADCAnDIRj are not cleared when ADCAnPWDDR/ADCAnDRj or ADCAnPWDDIR / ADCAnDIRj is read. Set to 0'b. b 3 ULEIE - A/D Error Interrupt (INT_ADE) Enable on Upper/Lower Limit Error Detection - Enabled. Set to 1'b. b 2 OWEIE - A/D Error Interrupt (INT_ADE) Enable on Overwrite Error Detection - Enabled. Set to 0'b. b 1:b 0 - Reserved set to 0 */ ADCA0.SFTCR.UINT32 = 0x00000008UL; /* Set the upper limit / lower limit error detection threshold. ADCAnULLMTBR0 - Upper Limit/Lower Limit Table Registers 0 b31:b20 ULMTB - Upper Limit Table - Upper limit = 0FFFH b19:b16 - Reserved set to 0 b15:b 4 LLMTB - Lower Limit Table - Lower limit = 0800H b 3:b 0 - Reserved set to 0 */ ADCA0.ULLMTBR0.UINT32 = 0xFFF08000UL; /* Select the PVCR_TRG for the trigger input to the PWM-Diag scan group. ADCAnPWDSGCR - PWM-Diag Scan Group Control Register b31:b 1 - Reserved set to 0 b 0 PWDTRGMD - PWM-Diag Trigger Mode Select - PVCR_TRG is selected for the trigger input to the PWM-Diag scan group. set to 1'b */ ADCA0.PWDSGCR.UINT32 = 0x00000001UL; MKADCA0ERR = 0U; /* Enable INTADCA0ERR interrupt */ }