psoc designer manual

Upload: vijaygurumani

Post on 14-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 PSoC Designer Manual

    1/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    PSoC Designer Flow

    Following are the steps in using PSoC Designer

    Step 1: Create a New ProjectIn PSoC Designer 5.1, you create a new project for your new design before you begin to design.

    1. Click the File menu and select New Project.

    2. Choose any desired name for the project and click OK.

  • 7/30/2019 PSoC Designer Manual

    2/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    Step 2: Choose a Base Device

    The device editor that powers the Chip-Level view shows you the resources available

    on your chosen PSoC device. It allows you to configure and route those resources. After you

    have created a project, step two is to choose a device.

    1. Click the View Catalog button.

    2. In the Select Base Part dialog, choose the part used in your kit. The CY3210-PSoCEval1

    uses the CY8C29466-24PXI. Consult your kit document for the proper device for your kit.

    Click Select.

    3. Under Generate Main file using, select C.

    4. Click OK.

    Your project opens in the Device Editor Chip-Level view. The default view has secondary

    windows that show all kinds of information about your project. You can move, resize, close,

    and arrange all of these secondary windows to suit your preferences. The View menucontains the available windows

  • 7/30/2019 PSoC Designer Manual

    3/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    Step 3: Choose and Configure User ModulesThis project divides the output of a potentiometer into three regions. An LED will be off,

    on, or blinking depending on the voltage range read from the potentiometer. The user

    modules required for this project are:

    PGA. A programmable gain amplifier is used to buffer the input from the

    potentiometer.

    ADCINC. An incremental ADC is used to convert the analog input from the

    potentiometer to a digital value that you can use for the program logic.

    Timer8. An 8-bit timer is used to blink the LED periodically.

    Global Resources

    Global Resources are those shared by all user modules in a particular configuration.

    The IDE Guide (Help >Documentation) contains a complete reference on the effect of

    each of the Global Resources.

  • 7/30/2019 PSoC Designer Manual

    4/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    1. Set the CPU Clock to SysClk/1.Since the Power Setting is at the default of 5.0 V

    operation and a SysClk of 24 MHz, the CPU will also run at 24 MHz.

    2. Set the VC1 clock to SysClk/3.

    3. Set the VC2 clock to VC1/16.

    4. Set the VC3 Source to VC2 and the VC3 Divider to 250.

    PGA

    1. In the User Module Catalog (View > User Module Catalog), double click to expand the

    Amplifiers folder.

    2. Right-click PGA and select Place.

    The PGA is placed in the first available analog block. The default placement of the user

    module is sufficient.

    3. Select the PGA user module in the Workspace Explorer.

    4. In the Workspace Explorer window, right click on PGA_1 > Properties.

    The Parameters window for PGA_1 opens. Change the name of the user module to VR_PGA.

    area of the Interconnect view and select Zoom In to get a close up view of the resources.

    Press [Alt] and click the mouse to pan the window. Right click again and select Original View

    to restore the original view.

    5. Set the Gain for VR_PGA to 1.000.The PGA is used to buffer the input of the

    potentiometer, so the Gain is 1.

    6. Set the Input to AnalogColumn_InputMUX_0.

    The input for the PGA will come from the potentiometer routed from a pin to the

    AnalogColumn_InputMUX_0. By default, the AnalogColumn_InputMUX_0 is routed from

    P0[1]. You can click the mux and select one of four pins, but the default is works for this

    purpose.

  • 7/30/2019 PSoC Designer Manual

    5/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    7. For the VR_PGA Reference, select analog ground, AGND.

    8. For Analog Bus, choose Disable.

    9. On the diagram, click Port_0_1.

    10. Change the name to VR_IN and click OK.

    ADCINCThere are many ADCs available. When choosing an ADC for your application, consult

    the ADC Selection Guide (there is a link to it at the beginning of each of the ADCdatasheets). This project will use the ADCINC.

    In User Modules, select the ADCs folder. Right click to place the ADCINC.

    2. Select the Single Stage Modulator and select OK.

    3. In the Parameters Window, change the Name of the user module to VR_ADC.

  • 7/30/2019 PSoC Designer Manual

    6/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    4. Select Unsigned for the DataFormat.

    5. For Resolution, select 8 Bit.

    6. For Data Clock, select VC1.

    7. For PosInput, select ACB00.

    This connects the output of the VR_PGA GAIN block to the PosInput of the VR_ADC. Check

    the diagram to make sure that there is a line connecting them. If you are using a chip that

    has a different configuration of analog blocks than the CY8C29466-24PXI used in the

    example, choose the block that contains the VR_PGA GAIN block in place of ACB00.

    8. Set the NegInput to ACB00 and the NegInput Gain to Disconnected.

    This sets the ADC to use a single-ended input.

    9. For PWM Output select None.

  • 7/30/2019 PSoC Designer Manual

    7/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    Timer8

    The 8-bit timer is used to flash the LED periodically. It uses the interrupt generated

    by the timer to toggle the LED.

    1.In User Modules, select the Timers folder, and place a Timer8 user module.

    2.In the Parameters Window, rename the user module to LEDFlashTimer.

    3. Set the Clock to VC3.

    4. Set Capture to Low.

    5. Set TerminalCountOut to Row_0_Output_2.

    You will route the Terminal Count output to a pin so you can get some practice routing

    resources in PSoC

    Designer. You will connect the pin to an LED and set the Drive mode on the pin so that it

    will flash the LED

    for a single clock cycle every time the timer reaches terminal count.

    6. Set CompareOut to None.

    7. Set the Period to 250.

    The flash rate of the LED will be 1/4 second:

    (24 MHz 3 (VC1) 16 (VC2) 250 (VC3 Divider) 250 (Period))

  • 7/30/2019 PSoC Designer Manual

    8/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    The timer will hit terminal count 8 times per second and each of these terminal counts

    toggles the LED.

    The other example project uses the SleepTimer user module rather than the Timer8. The

    SleepTimer is

    configurable down to 1 Hz without using the clock dividers. The Timer8 was used in this

    example to show

    routing of a user module output to a pin. The same technique can be used to route the

    output of one user

    module to the input of another.

    8. Set the CompareValue to 0.

    9. Set the CompareType to Less Than.

    10. Set the InterruptType to Terminal Count.

    11. Set ClockSync to Sync to SysClk.

    Step 4: Connect the User ModulesEach user module has inputs and outputs that can be routed to other user modules

    and to pins. The output of the VR_PGA user module was routed to the VR_ADC user module

    in the parameter selection. So to practice routing, you will route the output of the

    LEDFlashTimer TerminalCountOut to a pin to flash an LED when the counter reaches

    terminal count.

    The main LED from the project will be attached to P0[0] (port 0, bit 0), and the

    potentiometer input is on P0[1], so you, will route this signal to P0[2]. Youve already

    routed the TerminalCountOut to row 0 output 2 in the LEDFlashTimer properties.

    1. Locate the RO0[2] (Row_0_Output_2) line in the Interconnect view. It is the blue

    horizontal line that your LEDFlashTimer is attached to.

    2. Click the digital interconnect box on the right end of the Row_0_Output_2 line.

    3. In the Digital Interconnect dialog, click the top triangle (Row_0_Output_2_Drive_0)

    and select GlobalOutEven_2.

  • 7/30/2019 PSoC Designer Manual

    9/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    4. Click Close.

    5. In the Pinout window (View > Pinout) click to expand P0[2].

    6. Change the Name to LED2.

    7. Set the Select to GlobalOutEven_2.

    8. Set the Drive to Strong.

    9. Click OK.

    10. Click to expand P0[0] (the other pin that will have an LED attached).

    11. Change the Name to LED1.

    12. Set the Drive to Strong.

    13. Click OK.

    14. Click to expand P0[1] and verify that it is set to accept AnalogInput and is named

    VR_IN.In the Interconnect view, there is now a line from the TerminalCountOut of the

    LEDFlashTimer to RO0[2], then to GlobalOutEven_2, and finally to Port_0_2. You have

    successfully routed the terminal count of your timer user module to a pin and configured the

    pins for the inputs and outputs attached to them.

  • 7/30/2019 PSoC Designer Manual

    10/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    Step 5: Write Firmware

    The first step in writing the firmware is generating the application. Generating the

    application creates all of the source files, library files, and headers that are needed to begin

    writing the firmware. The APIs generated for each of the user modules you have selected

    are detailed in the user module data sheets associated with each of the user modules.

    1. From the Build menu, select Generate/Build Project.

    2. In the Workspace Explorer, double click to expand your project folder.

    3. Under the Source Files folder, double click main.c.

    4. Copy and paste the following code into main.c. Replace the entire contents of main.c with

    the text below.The code is fully commented, so you may want to look through the program

    logic. It starts all three user modules. The ADC begins sampling before the program goes

    into an infinite loop that samples the ADC and performs some simple logic on the results.

    After the main program, there is an interrupt service routinewritten in C.

    //----------------------------------------------------------------------------

    // C main line

    //----------------------------------------------------------------------------

    #include // part specific constants and macros

    #include "PSoCAPI.h" // PSoC API definitions for all User Modules

    #pragma interrupt_handler LEDFlashTimer_ISR_C

    // Write the interrupt handler for the Flash Timer in C.

    #define LED1_PORT PRT0DR

    //Constant definition for the data port (Port 0) where the LED (LED1) resides.

    #define LED1_ON 0x01

    //Constant definition to OR with the LED1_PORT to turn on the LED (LED1).

    #define LED1_OFF 0xFE

    //Constant definition to AND with the LED1_PORT to turn off the LED (LED1).

    unsigned char ucVR_ADCResult;

    //This global variable holds the converted output of the potentiometer (VR).

    void main(void)

    {

    M8C_EnableGInt; //Enables the Global Interrupt

    LEDFlashTimer_Start(); //Start the Timer UM

    VR_PGA_Start(VR_PGA_HIGHPOWER);

    //Performs all required initialization for the PGA User Module and sets the power

  • 7/30/2019 PSoC Designer Manual

    11/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    //level for the PGA to high power (VR_PGA_HIGHPOWER).

    VR_ADC_Start(VR_ADC_HIGHPOWER);

    //Performs all required initialization for the VR_ADC User Module

    //and sets the power level to high power.

    VR_ADC_GetSamples(0);

    //Sets the VR_ADC to run continuously by providing a 0 in the paramater list.

    while(1) //infinte loop.

    {

    if (VR_ADC_fIsDataAvailable() != 0)

    //This function checks the availability of sampled data. The function returns

    //a non-zero value if data has been converted and is ready to read.

    {

    ucVR_ADCResult = VR_ADC_bClearFlagGetData();

    //This function clears the data ready flag and gets converted data as an

    // unsigned char and stores it in the variable ucVR_ADCResult.

    //This function also checks to see that data-flag is still reset.

    //If not the data is retrieved again. This makes sure that the ADC interrupt

    //routine did not update the answer while it was being collected.

    if (ucVR_ADCResult

  • 7/30/2019 PSoC Designer Manual

    12/12

    Trident Techlabs Pvt Ltd S7 Mamanji Center, Thiru Vi Ka Industrial Estate, Guindy, Chennai - 32Phone No: 044 43358483/84, www.tridenttechlabs.com

    // Don't need to test the top third.

    {

    LEDFlashTimer_DisableInt();

    //Disabling the Interrupt for the Timer stops the blinking

    LED1_PORT |= LED1_ON;

    //Turn on LED1 by setting Bit 0 of Port 0 to high.

    } //end else

    } //end (VR_ADC_fIsDataAvailable() != 0)

    }

    }

    void LEDFlashTimer_ISR_C(void)

    {

    //Read Port0 and XOR it with 0x01 to change the status from On to Off and vice-versa.

    PRT0DR ^= 0x01;

    }

    5. Save main.c.

    6. Open the lib folder and then the Library Source Files folder.

    7. Open the interrupt routine for the LEDFlashTimer user module, LedFlashTimerINT.asm.

    8. Insert the following line after the @PSoC_UserCode_BODY@ banner in the

    _LEDFlashTimer_ISR section.

    ljmp _LEDFlashTimer_ISR_C ; jump to the ISR written in C in main.c

    9. Save and close the LEDFlashTimerINT.asm file.

    10. From the Build menu, select Generate/Build Project.