Beruflich Dokumente
Kultur Dokumente
*****************************************************************************
**
* File Name: main.c
*
* Version: 1.1
*
* Tested with:
* PSoC Creator: PSoC Creator 2.1
* Device tested with: CY8C3866AXI-040
* Compiler: DP8051 Keil 8.16
*****************************************************************************
***
* Copyright (2012), Cypress Semiconductor Corporation.
*****************************************************************************
***
* This software is owned by Cypress Semiconductor Corporation (Cypress)
* and is protected by and subject to worldwide patent protection (United
* States and foreign), United States copyright laws and international treaty
* provisions. Cypress hereby grants to licensee a personal, non-exclusive,
* non-transferable license to copy, use, modify, create derivative works of,
* and compile the Cypress Source Code and derivative works for the sole
* purpose of creating custom software in support of licensee product to be
* used only in conjunction with a Cypress integrated circuit as specified in
* the applicable agreement. Any reproduction, modification, translation,
* compilation, or representation of this software except as specified above
* is prohibited without the express written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising
out
* of the application or use of any product or circuit described herein.
Cypress
* does not authorize its products for use as critical components in lifesupport
* systems where a malfunction or failure may reasonably be expected to result
in
* significant injury to the user. The inclusion of Cypress' product in a life* support systems application implies that the manufacturer assumes all risk
of
* such use and in doing so indemnifies Cypress against all charges. Use may
be
* limited by and subject to the applicable Cypress software license
agreement.
*****************************************************************************
**/
/
*****************************************************************************
**
*
THEORY OF OPERATION
* This file provides source code for the ADC to LCD with DAC example
* project. The firmware takes a voltage output from a potentiometer and
* displays the ADC raw count on an LCD. The raw count also determines the
* clock divider value of the clock driving the DMA controller.
* A table of voltage values are sent to the DAC via DMA. Then the output of
* the DAC goes through an analog buffer and to an LED. This will give a
* dimming/brightening affect on the LED at a really slow rate or a really
fast
* rate depending on the raw count coming from the ADC.
*****************************************************************************
**/
#include <device.h>
/* LCD specific */
#define ROW_0
#define COLUMN_0
#define COLUMN_9
#define COLUMN_10
#define COLUMN_11
0
0
9
10
11
"
1
1
(CYDEV_SRAM_BASE)
(CYDEV_PERIPH_BASE)
0x53, 0x55, 0x57, 0x59, 0x5B, 0x5D, 0x5F, 0x61, 0x63, 0x65, 0x67, 0x69,
0x6B
};
void main()
{
int16 voltageRawCount;
ADC_Start();
LCD_Start();
VDAC_Start();
Opamp_Start();
/* Move the LCD cursor to Row 0, Column 0 */
LCD_Position(ROW_0, COLUMN_0);
/* Print Label for the pot voltage raw count */
LCD_PrintString("V Count: ");
/* Configure DMA */
DMA_Chan = DMA_DmaInitialize(DMA_BYTES_PER_BURST, DMA_REQUEST_PER_BURST,
HI16(DMA_SRC_BASE), HI16(DMA_DST_BASE));
DMA_TD[0] = CyDmaTdAllocate();
CyDmaTdSetConfiguration(DMA_TD[0], 116, DMA_INVALID_TD, TD_INC_SRC_ADR);
CyDmaTdSetAddress(DMA_TD[0], LO16((uint32)voltageWave),
LO16((uint32)VDAC_Data_PTR));
CyDmaChSetInitialTd(DMA_Chan, DMA_TD[0]);
CyDmaChEnable(DMA_Chan, 1);
/* Clock will make burst requests to the DMAC */
Clock_Start();
ADC_StartConvert();
while(1)
{
/* Wait for end of conversion */
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
voltageRawCount = ADC_GetResult16();
*/
/* This removes any -ve count which we may get when pot is at 0 volt
if (voltageRawCount < MIN_COUNT)
{
voltageRawCount = MIN_COUNT;
}
/* Used to remove the count beyond 8 bit value, see resolution section
* in DelSig ADC datasheet */
else if(voltageRawCount > MAX_COUNT)
{
voltageRawCount = MAX_COUNT;
}
else
{
/* Continue */
}
/*
* The LED blinking frequency is dependent on the Voltage raw count.
* With a 3MHz clock, the lowest divider (for raw count of 0) should
be
*
*
*
adjusted
* clock frequency (with the updated divider) linear with the ADC
* output.
*/
Clock_SetDivider(((uint32)999*260+voltageRawCount)/ (260voltageRawCount));
/* Move the cursor to Row 0, Column 9 */
LCD_Position(ROW_0, COLUMN_9);
LCD_PrintNumber(voltageRawCount);
if (voltageRawCount < 10)
{
/* Move the cursor to Row 0, Column 10 */
LCD_Position(ROW_0,COLUMN_10);
/* Clear last characters */
LCD_PrintString(CLEAR_TENS_HUNDREDS);
}
else if (voltageRawCount < 100)
{
/* Move the cursor to Row 0, Column 11 */
LCD_Position(ROW_0,COLUMN_11);
LCD_PrintString(CLEAR_HUNDREDS);
}
else
{
/* Continue on */
}
}
/* [] END OF FILE */