Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
/******************************************************************************
* File Name: main.c
*
* Description: This is the source code for the HRPWM-CSG Example
* for ModusToolbox.
*
* Related Document: See README.md
*
*
*******************************************************************************
*
* $ Copyright (c) 2015-YEAR, Infineon Technologies AG $
* All rights reserved.
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer,
* must be included in all copies of the Software, in whole or in part, and
* all derivative works of the Software, unless such copies or derivative
* works are solely in the form of machine-executable object code generated by
* a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************/
#include "cybsp.h"
#include "cy_utils.h"
/*******************************************************************************
* Macros
********************************************************************************/
#define CCU8_SLICE CCU80_CC80
#define DSVI_INITIAL_VALUE 512
#define DSV1_LOW_VALUE 140
#define DSV1_HIGH_VALUE 240
#define DELAY_VALUE 0xFFFF
#define CSG_DAC_STEP 20
/*******************************************************************************
* Global Variables
********************************************************************************/
const uint8_t pattern[] = {0U, 4U, 8U, 12U, 16U, 19U, 23U, 27U, 31U};
/*******************************************************************************
* Function Prototypes
********************************************************************************/
/*******************************************************************************
* Function Name: main
*******************************************************************************
* Summary:
* A triangle waveform is generated with DAC0. The DAC output is connected to the
* comparator input(user must connect). The comparator output signal is used as
* start and stop signal for a CCU8 timer that generates PWM.
*
* Parameters:
* void
*
* Return:
* int
*
*******************************************************************************/
int main(void)
{
cy_rslt_t result;
/* Initialize the device and board peripherals */
result = cybsp_init();
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
/*place holder for initial value of DAC in csg block*/
uint32_t dsv1_value;
uint32_t mask=1;
/*start ccu8 slice 0 to generate pwm*/
XMC_CCU8_SLICE_StartTimer(CCU8_SLICE);
/*start DAC0 to generate triangular wave*/
XMC_HRPWM_StartDac(HRPWM0, XMC_HRPWM_CSG_RUN_BIT_DAC0);
/*start comparator in CSG block*/
XMC_HRPWM_StartComparator(HRPWM0, XMC_HRPWM_CSG_RUN_BIT_CMP0);
/*load the dsv1 variable with initial value of DAC*/
dsv1_value = DSVI_INITIAL_VALUE;
for (;;)
{
/*give delay before updating DAC reference value*/
for(uint32_t i = 0; i < 0xFFFF; ++i);
/*update CSG DAC DSV1 register.*/
dsv1_value += CSG_DAC_STEP;
if(dsv1_value > DSV1_HIGH_VALUE)
{
dsv1_value = DSV1_LOW_VALUE;
}
/*update DAC reference value*/
XMC_HRPWM_CSG_UpdateDACRefDSV1(HRPWM0_CSG0,dsv1_value);
/*enable comparator shadow transfer*/
XMC_HRPWM_EnableComparatorShadowTransfer(HRPWM0, mask);
}
}
/* [] END OF FILE */