Skip to content
Permalink
07930abda3
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
158 lines (136 sloc) 5.31 KB
/******************************************************************************
* File Name: main.c
*
* Description: This is the source code for the HRPWM-HRC 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_MODULE CCU80
#define CCU8_SLICE CCU80_CC80
#define MAX_CR1_VALUE_80MHZ 82
#define DELAY_VALUE 100000
/*******************************************************************************
* Global Variables
********************************************************************************/
/*******************************************************************************
* Function Prototypes
********************************************************************************/
/**********************************************************************************
* Funtion Name: main
***********************************************************************************
* summary:
* PWM is generated by CCU8 timer slice 0. The output of CCU8 slice 0 is fed as
* input to the HRC to place the signal in high resolution by writing the needed
* decimal value to the HRCyCR1 register using the XMC_HRPWM_HRC_SetCompare1 API.
* Placement value = CR1* 150ps
* The maximum value for this field should be set accordingly with the used module
* clock frequency: 82 for 80 MHZ, 54 for 150 MHZ, 36 for 180 MHZ
*
* 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);
}
/* Enable compare match event */
XMC_CCU8_SLICE_SetEvent(CCU8_SLICE, XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_UP_CH_1);
/* Connect compare match event to SR1 */
XMC_CCU8_SLICE_SetInterruptNode(CCU8_SLICE, XMC_CCU8_SLICE_IRQ_ID_COMPARE_MATCH_UP_CH_1, XMC_CCU8_SLICE_SR_ID_1);
/* Enable IRQ */
NVIC_SetPriority(CCU80_1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 63, 0));
NVIC_EnableIRQ(CCU80_1_IRQn);
for (;;)
{
}
}
/*******************************************************************************
* Function Name: ccu80_1_IRQHandler
********************************************************************************
* Summary:
* The interrupt is generated when the compare match event happens in ccu8
* timer. The interrupt handler is used to place the PWM generated by ccu8
* timer in high resolution.
* placement value = CR1* 150ps
*
*Parameters:
* void
*
* Return:
* int
*
*******************************************************************************/
void CCU80_1_IRQHandler(void)
{
/* HRC CR1 value */
static uint32_t cr1_value = 0U;
static uint32_t counter = 0U;
counter++;
/*give a delay before updating cr1 value : signal placement= cr1 value*150ps*/
if(counter > DELAY_VALUE)
{
counter = 0;
cr1_value = cr1_value + 1;
if (cr1_value > MAX_CR1_VALUE_80MHZ)
{
cr1_value = MAX_CR1_VALUE_80MHZ;
/*set HRC0CR1 register with cr1_value*/
XMC_HRPWM_HRC_SetCompare1(HRPWM0_HRC0, cr1_value);
cr1_value = 0;
}
else
{
/*set HRC0CR1 register with cr1_value*/
XMC_HRPWM_HRC_SetCompare1(HRPWM0_HRC0, cr1_value);
}
/* Trigger shadow transfer */
XMC_CCU8_EnableShadowTransfer(CCU8_MODULE, 1U);
}
}
/* [] END OF FILE */