📄 main.c
字号:
//***********************************************************************************************
//***********************************************************************************************
// FILENAME: main.C
//
// Version: 1.0, Updated on 27th July 2004
//
// DESCRIPTION: Main file of Example_ADCINC12_28pin example project
//-----------------------------------------------------------------------------
// Copyright (c) Cypress MicroSystems 2000-2003. All Rights Reserved.
//*****************************************************************************
//*****************************************************************************
/***********************************************************************************************
Example_ADCINC12_28pin, a CY3210-PSoCEVAL1 and CY3210-MiniEval1 board project
Project Objective:
To demonstrate the operation of the 12-Bit Incremental Analog-to-Digital Converter user
module of the PSoC microcontroller.Also this example demonstrates the clock generation
using a counter and routing.A Programmable Gain Amplifier (PGA) with unity gain,
a 8-bit counter and a LCD user module are also incorporated.
Overview:
The following changes were made to the default settings in the device editor.
Select user modules
Select an ADCINC12_1 module from the ADCs category
Select a PGA_1 module from the Amplifiers category
Select a Counter8_1 module from the Counters category
Select a LCD_1 from Misc Digital category
in this example these UMs are renamed as ADCINC12,PGA,Counter8,LCD respectively.
Place user modules
1) select ADCINC12, and then select the analog block (digital blocks
are fine with the default placement) and move it to block ASC10 to place it.
2) select PGA and move it to block ACB00 to place it
3) select Counter8 and move it to block DCB03 to place it
4) Select LCD and select port_2 for LCD port.
Set the global resources and UM resources in the device editor window as shown in the project
settings below.
Upon program execution all hardware settings from the device configuration are loaded
into the device and main.c is executed.
For this example the 8-bit counter is used to provide a clock for A/D converter.
this approach provides an example of clock generation and routing. The clock
output from the counter is used as a source for the Analog Column clocks (AnalogClock_0_Select).
This clock is then selected as the clock input for AnalogColumn_Clock_0, which supplies
it as input to all blocks in that column.This counter clock is also selected as the input to
the timer and counter components of the ADC(DBB01 and DCB02 respectively) using the row
broadcast (BC0). The 8-bit counter, DCB03 is set to run at 1.5MHz by the setting
the counter value to 15.This amounts to dividing the 24MHz(Use SysClk Direct) input clock by 16.
Each time the counter reaches 0 it is automatically reloaded. A compare value
for the counter is set to 7 which sets up a duty cycle at the output of approximately 50%.
The 12-bit ADC is a single user module that consists of 3 PSoC blocks.Each PSoC
block can be individually placed.Once they are placed each block must be clocked
with the same clock source.The clock signal to each of the digital sections of the
ADC can be configured in the user module menu or device editor.
Analog values are sampled at pin P0[1] at:
Sample Rate = 1.5MHz(counter output)/(65*256)= 90 samples/sec.
Further information is supplied in the data sheet included for the user module.
Clock Routing. Using the device editor click on the AnalogClock_0_Select mux icon. Select
the block ID of the block containing the 8-bit counter. In this example it is DCB03. Click
on the clock mux icon associated with the analog column where the ADC analog block is
placed. In the example this is the column 0. Select the appropriate source. For the example
this is AnalogClock_0_Select.This demonstrates using a digital PSoC block to supply a specific
clock to an analog section of the chip.The ADC timer and counter blocks must have a clock
source specified that is identical to the one just selected on ACLK0 and the analog column.
Circuit Connections
This example project runs on the CY3210-PSoCEVAL1 and CY3210-MiniEval1 boards or compatible
hardware.An analog input voltage is required on port_0_1, and varying this voltage will cause
value in the LCD to change. The voltage must not exceed Vcc by more than 0.5 volts as per the
device specification.A PGA with unity gain is used just to route the analog input to ADC from
port pin.
The table below shows the translation of input analog voltage to digital for a signed output
DC voltage Decimal value Hexadecimal equivalent
0 -2048 F800
1 -1229 FB33
2 -410 FE66
2.5(AGND) -1 FFFF
3 409 199
4 1228 4CC
5 2047 07FF
(while verifying the negative values displayed using calculator,prefix the hexadecimal value
with F.for example,if the displayed value in the LCD is ECCC,in a 10 digit calculator enter
FFFFFFECCC and then convert to decimal to get -4916)
Project Settings:
Global resources
VC1 = 1 // Divide sysclock by 1
RefMux = Vdd/2 +/- Vdd/2 // This sets the ADC to use 2.5 volts for its
zero reference (AGND) and measures signals
in a range that is 2.5 volts above and below AGND
Analog Power = SC on/Ref High // This turns on the clock to the SC blocks
and sets the internal references for their best
performance. The power level can be reduced
once a project has been successfully developed.
ADCINC12
CNT Clock = Row_0_Broadcast // Clock from conuter
TMR Clock = Row_0_Broadcast
Input = ACB00 // Route input through PGA
ClockPhase = Normal
ClockSync = Sys to Sync Clock
AnalogColumn_Clock_0 = AnalogClock_0_select
AnalogClock_0_select = DCB03 // Select the output of counter
Counter8
Clock = Disable // Since Use SysClk Direct is used
Enable = High // Enable continous count
Compare Out = None
Terminal Count = None
Period = 15
Compare Value = 7 // Set to half of the period to get 50% duty cycle
Compare Type = Less Than or Equal to
Interrupt Type = Compare True
Clock Sync = Use SysClk Direct // Provides low-skew access to system clock
InvertEnable = Normal
PGA
Gain = 1.000 // Set for unity gain
Input = AnalogColumn_Input_MUX_0 // Input is from column mux
Reference = AGND
AnalogBus = Disable // The output will not go to the analog output bus
AnalogColumn_InputMUX_0 = PORT_0_1
LCD
LCDPort = Port_2
BarGraph = Disable
Input:
Pin Select Drive
P0[1] AnalogInput High Z analog
Output:
Port[2]-LCd port.For pins Default settings are made when LCD is connected to a port.
How to use this with the Proto board:
For input Connect a Variable end of pot(R11) which is terminated at J5 in CY3210-PSoCEVAL1 board to
port_0_1 through a jumper wire.Connect LCD at J9 for output.
For CY3210-MiniEval1 board variable end of a pot is readily connected to port_0_1.
Note:
For CY3210-MiniEval1 board LCD connections are to be made on the Bread board.The following table
shows LCD connection for CY3210-MiniEval1 board:(dont forget to connect Vcc and ground to LCD and
for nominal contrast,ground contrast control pin of LCD through 1.5K resistor)
port pins LCD Pin
P2[0] Connect to LCD_D4
P2[1] Connect to LCD_D5
P2[2] Connect to LCD_D6
P2[3] Connect to LCD_D7
P2[4] Connect to LCD_E
P2[5] Connect to LCD_RS
P2[6] Connect to LCD_RW
*/
//----------------------------------------------------------------------------
// 'C' Main line
//-----------------------------------------------------------------------------
//-------------------------------------------------------------------
// Include Files
//-------------------------------------------------------------------
#include "m8c.h"
#include "psocapi.h"
//----------------------------------------------------------------------------
// FUNCTION NAME: Main
//
// DESCRIPTION:
// Main function. Performs system initialization,gets the data for display and loops infinitely.
//
//----------------------------------------------------------------------------
//
// ARGUMENTS: None
// RETURNS: Nothing.
// SIDE EFFECTS: None.
//
// THEORY of OPERATION or PROCEDURE:
// 1) Enable Global Interrupt
// 2) Start the user modules
// 3) Gets the data from ADC and displays the same on LCD
// 4) Loop Infinitely
void main()
{
Counter8_Start();
// Start PGA with High power
PGA_Start(PGA_HIGHPOWER);
// Initialize LCD
LCD_Start();
//ADC power level set to highest power.
ADCINC12_Start(ADCINC12_HIGHPOWER);
//The zero argument sets the ADC to sample continuously.
ADCINC12_GetSamples(0);
//Enable global interrupts
M8C_EnableGInt;
for(;;)
{
// Wait for data to be ready
while(ADCINC12_fIsDataAvailable() == 0);
// Place LCD cursor at row 0, col 1.
LCD_Position(0,1);
// print the hex value to LCD
LCD_PrHexInt(ADCINC12_iGetData());
// Clear data ready flag
ADCINC12_ClearFlag();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -