Example #1
0
/*******************************************************************************
* Function Name: Counter_1_RestoreConfig
********************************************************************************
*
* Summary:
*  Restores the current user configuration.
*
* Parameters:  
*  void
*
* Return: 
*  void
*
* Global variables:
*  Counter_1_backup:  Variables of this global structure are used to 
*  restore the values of non retention registers on wakeup from sleep mode.
*
*******************************************************************************/
void Counter_1_RestoreConfig(void) 
{      
    #if (!Counter_1_UsingFixedFunction)

        #if (CY_UDB_V0)
            uint8 Counter_1_interruptState;
        #endif  /* (CY_UDB_V0) */

       Counter_1_WriteCounter(Counter_1_backup.CounterUdb);

        #if (CY_UDB_V0)
            Counter_1_WritePeriod(Counter_1_backup.CounterPeriod);
            Counter_1_WriteCompare(Counter_1_backup.CompareValue);

            Counter_1_interruptState = CyEnterCriticalSection();
            Counter_1_STATUS_AUX_CTRL |= Counter_1_STATUS_ACTL_INT_EN_MASK;
            CyExitCriticalSection(Counter_1_interruptState);

            Counter_1_STATUS_MASK = Counter_1_backup.InterruptMaskValue;
        #endif  /* (CY_UDB_V0) */

        #if(!Counter_1_ControlRegRemoved)
            Counter_1_WriteControlRegister(Counter_1_backup.CounterControlRegister);
        #endif /* (!Counter_1_ControlRegRemoved) */

    #endif /* (!Counter_1_UsingFixedFunction) */
}
Example #2
0
void setFrequency0(double freqRequired0)
{
    int writePeriod0; // clock of 12Mhz
    writePeriod0=(int)(24000000.0/(freqRequired0*100.0));//100 samples in wavdac
    Counter_1_WritePeriod(writePeriod0);
}
Example #3
0
/*******************************************************************************
* Function Name: Counter_1_Init
********************************************************************************
* Summary:
*     Initialize to the schematic state
* 
* Parameters:  
*  void  
*
* Return: 
*  void
*
*******************************************************************************/
void Counter_1_Init(void) 
{
        #if (!Counter_1_UsingFixedFunction && !Counter_1_ControlRegRemoved)
            uint8 ctrl;
        #endif /* (!Counter_1_UsingFixedFunction && !Counter_1_ControlRegRemoved) */
        
        #if(!Counter_1_UsingFixedFunction) 
            /* Interrupt State Backup for Critical Region*/
            uint8 Counter_1_interruptState;
        #endif /* (!Counter_1_UsingFixedFunction) */
        
        #if (Counter_1_UsingFixedFunction)
            /* Clear all bits but the enable bit (if it's already set for Timer operation */
            Counter_1_CONTROL &= Counter_1_CTRL_ENABLE;
            
            /* Clear the mode bits for continuous run mode */
            #if (CY_PSOC5A)
                Counter_1_CONTROL2 &= ((uint8)(~Counter_1_CTRL_MODE_MASK));
            #endif /* (CY_PSOC5A) */
            #if (CY_PSOC3 || CY_PSOC5LP)
                Counter_1_CONTROL3 &= ((uint8)(~Counter_1_CTRL_MODE_MASK));                
            #endif /* (CY_PSOC3 || CY_PSOC5LP) */
            /* Check if One Shot mode is enabled i.e. RunMode !=0*/
            #if (Counter_1_RunModeUsed != 0x0u)
                /* Set 3rd bit of Control register to enable one shot mode */
                Counter_1_CONTROL |= Counter_1_ONESHOT;
            #endif /* (Counter_1_RunModeUsed != 0x0u) */
            
            /* Set the IRQ to use the status register interrupts */
            Counter_1_CONTROL2 |= Counter_1_CTRL2_IRQ_SEL;
            
            /* Clear and Set SYNCTC and SYNCCMP bits of RT1 register */
            Counter_1_RT1 &= ((uint8)(~Counter_1_RT1_MASK));
            Counter_1_RT1 |= Counter_1_SYNC;     
                    
            /*Enable DSI Sync all all inputs of the Timer*/
            Counter_1_RT1 &= ((uint8)(~Counter_1_SYNCDSI_MASK));
            Counter_1_RT1 |= Counter_1_SYNCDSI_EN;

        #else
            #if(!Counter_1_ControlRegRemoved)
            /* Set the default compare mode defined in the parameter */
            ctrl = Counter_1_CONTROL & ((uint8)(~Counter_1_CTRL_CMPMODE_MASK));
            Counter_1_CONTROL = ctrl | Counter_1_DEFAULT_COMPARE_MODE;
            
            /* Set the default capture mode defined in the parameter */
            ctrl = Counter_1_CONTROL & ((uint8)(~Counter_1_CTRL_CAPMODE_MASK));
            
            #if( 0 != Counter_1_CAPTURE_MODE_CONF)
                Counter_1_CONTROL = ctrl | Counter_1_DEFAULT_CAPTURE_MODE;
            #else
                Counter_1_CONTROL = ctrl;
            #endif /* 0 != Counter_1_CAPTURE_MODE */ 
            
            #endif /* (!Counter_1_ControlRegRemoved) */
        #endif /* (Counter_1_UsingFixedFunction) */
        
        /* Clear all data in the FIFO's */
        #if (!Counter_1_UsingFixedFunction)
            Counter_1_ClearFIFO();
        #endif /* (!Counter_1_UsingFixedFunction) */
        
        /* Set Initial values from Configuration */
        Counter_1_WritePeriod(Counter_1_INIT_PERIOD_VALUE);
        #if (!(Counter_1_UsingFixedFunction && (CY_PSOC5A)))
            Counter_1_WriteCounter(Counter_1_INIT_COUNTER_VALUE);
        #endif /* (!(Counter_1_UsingFixedFunction && (CY_PSOC5A))) */
        Counter_1_SetInterruptMode(Counter_1_INIT_INTERRUPTS_MASK);
        
        #if (!Counter_1_UsingFixedFunction)
            /* Read the status register to clear the unwanted interrupts */
            (void)Counter_1_ReadStatusRegister();
            /* Set the compare value (only available to non-fixed function implementation */
            Counter_1_WriteCompare(Counter_1_INIT_COMPARE_VALUE);
            /* Use the interrupt output of the status register for IRQ output */
            
            /* CyEnterCriticalRegion and CyExitCriticalRegion are used to mark following region critical*/
            /* Enter Critical Region*/
            Counter_1_interruptState = CyEnterCriticalSection();
            
            Counter_1_STATUS_AUX_CTRL |= Counter_1_STATUS_ACTL_INT_EN_MASK;
            
            /* Exit Critical Region*/
            CyExitCriticalSection(Counter_1_interruptState);
            
        #endif /* (!Counter_1_UsingFixedFunction) */
}