Beispiel #1
0
/*******************************************************************************
* Function Name: PWM_2_RestoreConfig
********************************************************************************
*
* Summary:
*  Restores the current user configuration of the component.
*
* Parameters:
*  None
*
* Return:
*  None
*
* Global variables:
*  PWM_2_backup:  Variables of this global structure are used to
*  restore the values of non retention registers on wakeup from sleep mode.
*
*******************************************************************************/
void PWM_2_RestoreConfig(void) 
{
        #if(!PWM_2_UsingFixedFunction)
            #if(!PWM_2_PWMModeIsCenterAligned)
                PWM_2_WritePeriod(PWM_2_backup.PWMPeriod);
            #endif /* (!PWM_2_PWMModeIsCenterAligned) */

            PWM_2_WriteCounter(PWM_2_backup.PWMUdb);

            #if (PWM_2_UseStatus)
                PWM_2_STATUS_MASK = PWM_2_backup.InterruptMaskValue;
            #endif /* (PWM_2_UseStatus) */

            #if(PWM_2_DeadBandMode == PWM_2__B_PWM__DBM_256_CLOCKS || \
                PWM_2_DeadBandMode == PWM_2__B_PWM__DBM_2_4_CLOCKS)
                PWM_2_WriteDeadTime(PWM_2_backup.PWMdeadBandValue);
            #endif /* deadband count is either 2-4 clocks or 256 clocks */

            #if(PWM_2_KillModeMinTime)
                PWM_2_WriteKillTime(PWM_2_backup.PWMKillCounterPeriod);
            #endif /* (PWM_2_KillModeMinTime) */

            #if(PWM_2_UseControl)
                PWM_2_WriteControlRegister(PWM_2_backup.PWMControlRegister);
            #endif /* (PWM_2_UseControl) */
        #endif  /* (!PWM_2_UsingFixedFunction) */
    }
Beispiel #2
0
void play_song(int* notebuf, int* accidentalsbuf, int* octavebuf, int length) {
	PWM_1_Start();
	PWM_2_Start();
	PWM_3_Start();
	PWM_4_Start();
	for (int i = 0; i < length; i+=4) {
		PWM_1_WriteCompare((note_lengths[note_lookup[notebuf[i]]+accidentalsbuf[i]]/2)>>octavebuf[i]);
		PWM_1_WritePeriod(note_lengths[note_lookup[notebuf[i]]+accidentalsbuf[i]]>>octavebuf[i]);
		PWM_1_WriteCounter(0);
		PWM_2_WriteCompare((note_lengths[note_lookup[notebuf[i+1]]+accidentalsbuf[i]]/2)>>octavebuf[i+1]);
		PWM_2_WritePeriod(note_lengths[note_lookup[notebuf[i+1]]+accidentalsbuf[i]]>>octavebuf[i+1]);
		PWM_2_WriteCounter(0);
		PWM_3_WriteCompare((note_lengths[note_lookup[notebuf[i+2]]+accidentalsbuf[i]]/2)>>octavebuf[i+2]);
		PWM_3_WritePeriod(note_lengths[note_lookup[notebuf[i+2]]+accidentalsbuf[i]]>>octavebuf[i+2]);
		PWM_3_WriteCounter(0);
		PWM_4_WriteCompare((note_lengths[note_lookup[notebuf[i+3]]+accidentalsbuf[i]]/2)>>octavebuf[i+3]);
		PWM_4_WritePeriod(note_lengths[note_lookup[notebuf[i+3]]+accidentalsbuf[i]]>>octavebuf[i+3]);
		PWM_4_WriteCounter(0);
		if (Keypad_1_Status_Reg_Read() & 0x10) break;
		CyDelay(TEMPO_MS);
	}
	PWM_1_Stop();
	PWM_2_Stop();
	PWM_3_Stop();
	PWM_4_Stop();
}
/*******************************************************************************
* Function Name: PWM_2_Init
********************************************************************************
*
* Summary:
*  Initialize component's parameters to the parameters set by user in the
*  customizer of the component placed onto schematic. Usually called in
*  PWM_2_Start().
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
void PWM_2_Init(void) 
{
    #if (PWM_2_UsingFixedFunction || PWM_2_UseControl)
        uint8 ctrl;
    #endif /* (PWM_2_UsingFixedFunction || PWM_2_UseControl) */

    #if(!PWM_2_UsingFixedFunction)
        #if(PWM_2_UseStatus)
            /* Interrupt State Backup for Critical Region*/
            uint8 PWM_2_interruptState;
        #endif /* (PWM_2_UseStatus) */
    #endif /* (!PWM_2_UsingFixedFunction) */

    #if (PWM_2_UsingFixedFunction)
        /* You are allowed to write the compare value (FF only) */
        PWM_2_CONTROL |= PWM_2_CFG0_MODE;
        #if (PWM_2_DeadBand2_4)
            PWM_2_CONTROL |= PWM_2_CFG0_DB;
        #endif /* (PWM_2_DeadBand2_4) */

        ctrl = PWM_2_CONTROL3 & ((uint8 )(~PWM_2_CTRL_CMPMODE1_MASK));
        PWM_2_CONTROL3 = ctrl | PWM_2_DEFAULT_COMPARE1_MODE;

         /* Clear and Set SYNCTC and SYNCCMP bits of RT1 register */
        PWM_2_RT1 &= ((uint8)(~PWM_2_RT1_MASK));
        PWM_2_RT1 |= PWM_2_SYNC;

        /*Enable DSI Sync all all inputs of the PWM*/
        PWM_2_RT1 &= ((uint8)(~PWM_2_SYNCDSI_MASK));
        PWM_2_RT1 |= PWM_2_SYNCDSI_EN;

    #elif (PWM_2_UseControl)
        /* Set the default compare mode defined in the parameter */
        ctrl = PWM_2_CONTROL & ((uint8)(~PWM_2_CTRL_CMPMODE2_MASK)) &
                ((uint8)(~PWM_2_CTRL_CMPMODE1_MASK));
        PWM_2_CONTROL = ctrl | PWM_2_DEFAULT_COMPARE2_MODE |
                                   PWM_2_DEFAULT_COMPARE1_MODE;
    #endif /* (PWM_2_UsingFixedFunction) */

    #if (!PWM_2_UsingFixedFunction)
        #if (PWM_2_Resolution == 8)
            /* Set FIFO 0 to 1 byte register for period*/
            PWM_2_AUX_CONTROLDP0 |= (PWM_2_AUX_CTRL_FIFO0_CLR);
        #else /* (PWM_2_Resolution == 16)*/
            /* Set FIFO 0 to 1 byte register for period */
            PWM_2_AUX_CONTROLDP0 |= (PWM_2_AUX_CTRL_FIFO0_CLR);
            PWM_2_AUX_CONTROLDP1 |= (PWM_2_AUX_CTRL_FIFO0_CLR);
        #endif /* (PWM_2_Resolution == 8) */

        PWM_2_WriteCounter(PWM_2_INIT_PERIOD_VALUE);
    #endif /* (!PWM_2_UsingFixedFunction) */

    PWM_2_WritePeriod(PWM_2_INIT_PERIOD_VALUE);

        #if (PWM_2_UseOneCompareMode)
            PWM_2_WriteCompare(PWM_2_INIT_COMPARE_VALUE1);
        #else
            PWM_2_WriteCompare1(PWM_2_INIT_COMPARE_VALUE1);
            PWM_2_WriteCompare2(PWM_2_INIT_COMPARE_VALUE2);
        #endif /* (PWM_2_UseOneCompareMode) */

        #if (PWM_2_KillModeMinTime)
            PWM_2_WriteKillTime(PWM_2_MinimumKillTime);
        #endif /* (PWM_2_KillModeMinTime) */

        #if (PWM_2_DeadBandUsed)
            PWM_2_WriteDeadTime(PWM_2_INIT_DEAD_TIME);
        #endif /* (PWM_2_DeadBandUsed) */

    #if (PWM_2_UseStatus || PWM_2_UsingFixedFunction)
        PWM_2_SetInterruptMode(PWM_2_INIT_INTERRUPTS_MODE);
    #endif /* (PWM_2_UseStatus || PWM_2_UsingFixedFunction) */

    #if (PWM_2_UsingFixedFunction)
        /* Globally Enable the Fixed Function Block chosen */
        PWM_2_GLOBAL_ENABLE |= PWM_2_BLOCK_EN_MASK;
        /* Set the Interrupt source to come from the status register */
        PWM_2_CONTROL2 |= PWM_2_CTRL2_IRQ_SEL;
    #else
        #if(PWM_2_UseStatus)

            /* CyEnterCriticalRegion and CyExitCriticalRegion are used to mark following region critical*/
            /* Enter Critical Region*/
            PWM_2_interruptState = CyEnterCriticalSection();
            /* Use the interrupt output of the status register for IRQ output */
            PWM_2_STATUS_AUX_CTRL |= PWM_2_STATUS_ACTL_INT_EN_MASK;

             /* Exit Critical Region*/
            CyExitCriticalSection(PWM_2_interruptState);

            /* Clear the FIFO to enable the PWM_2_STATUS_FIFOFULL
                   bit to be set on FIFO full. */
            PWM_2_ClearFIFO();
        #endif /* (PWM_2_UseStatus) */
    #endif /* (PWM_2_UsingFixedFunction) */
}
Beispiel #4
0
/*******************************************************************************
* Function Name: PWM_2_RestoreConfig
********************************************************************************
* 
* Summary:
*  Restores the current user configuration of the component.
*
* Parameters:  
*  None
*
* Return: 
*  None
*
* Global variables:
*  PWM_2_backup:  Variables of this global structure are used to  
*  restore the values of non retention registers on wakeup from sleep mode.
*
*******************************************************************************/
void PWM_2_RestoreConfig(void) 
{
        #if(!PWM_2_UsingFixedFunction)
            #if (CY_UDB_V0)
                /* Interrupt State Backup for Critical Region*/
                uint8 PWM_2_interruptState;
                /* Enter Critical Region*/
                PWM_2_interruptState = CyEnterCriticalSection();
                #if (PWM_2_UseStatus)
                    /* Use the interrupt output of the status register for IRQ output */
                    PWM_2_STATUS_AUX_CTRL |= PWM_2_STATUS_ACTL_INT_EN_MASK;
                    
                    PWM_2_STATUS_MASK = PWM_2_backup.InterruptMaskValue;
                #endif /* (PWM_2_UseStatus) */
                
                #if (PWM_2_Resolution == 8)
                    /* Set FIFO 0 to 1 byte register for period*/
                    PWM_2_AUX_CONTROLDP0 |= (PWM_2_AUX_CTRL_FIFO0_CLR);
                #else /* (PWM_2_Resolution == 16)*/
                    /* Set FIFO 0 to 1 byte register for period */
                    PWM_2_AUX_CONTROLDP0 |= (PWM_2_AUX_CTRL_FIFO0_CLR);
                    PWM_2_AUX_CONTROLDP1 |= (PWM_2_AUX_CTRL_FIFO0_CLR);
                #endif /* (PWM_2_Resolution == 8) */
                /* Exit Critical Region*/
                CyExitCriticalSection(PWM_2_interruptState);
                
                PWM_2_WriteCounter(PWM_2_backup.PWMUdb);
                PWM_2_WritePeriod(PWM_2_backup.PWMPeriod);
                
                #if(PWM_2_UseOneCompareMode)
                    PWM_2_WriteCompare(PWM_2_backup.PWMCompareValue);
                #else
                    PWM_2_WriteCompare1(PWM_2_backup.PWMCompareValue1);
                    PWM_2_WriteCompare2(PWM_2_backup.PWMCompareValue2);
                #endif /* (PWM_2_UseOneCompareMode) */
                
               #if(PWM_2_DeadBandMode == PWM_2__B_PWM__DBM_256_CLOCKS || \
                   PWM_2_DeadBandMode == PWM_2__B_PWM__DBM_2_4_CLOCKS)
                    PWM_2_WriteDeadTime(PWM_2_backup.PWMdeadBandValue);
                #endif /* deadband count is either 2-4 clocks or 256 clocks */
            
                #if ( PWM_2_KillModeMinTime)
                    PWM_2_WriteKillTime(PWM_2_backup.PWMKillCounterPeriod);
                #endif /* ( PWM_2_KillModeMinTime) */
            #endif /* (CY_UDB_V0) */
            
            #if (CY_UDB_V1)
                #if(!PWM_2_PWMModeIsCenterAligned)
                    PWM_2_WritePeriod(PWM_2_backup.PWMPeriod);
                #endif /* (!PWM_2_PWMModeIsCenterAligned) */
                PWM_2_WriteCounter(PWM_2_backup.PWMUdb);
                #if (PWM_2_UseStatus)
                    PWM_2_STATUS_MASK = PWM_2_backup.InterruptMaskValue;
                #endif /* (PWM_2_UseStatus) */
                
                #if(PWM_2_DeadBandMode == PWM_2__B_PWM__DBM_256_CLOCKS || \
                    PWM_2_DeadBandMode == PWM_2__B_PWM__DBM_2_4_CLOCKS)
                    PWM_2_WriteDeadTime(PWM_2_backup.PWMdeadBandValue);
                #endif /* deadband count is either 2-4 clocks or 256 clocks */
                
                #if(PWM_2_KillModeMinTime)
                    PWM_2_WriteKillTime(PWM_2_backup.PWMKillCounterPeriod);
                #endif /* (PWM_2_KillModeMinTime) */
            #endif /* (CY_UDB_V1) */
            
            #if(PWM_2_UseControl)
                PWM_2_WriteControlRegister(PWM_2_backup.PWMControlRegister); 
            #endif /* (PWM_2_UseControl) */
        #endif  /* (!PWM_2_UsingFixedFunction) */
    }