Académique Documents
Professionnel Documents
Culture Documents
c
#include <device.h>
#include <stdio.h>
uint16 flag=1;
uint16 results[2], channel_1_result, channel_2_result;
extern float avr_1_result, avr_2_result;
char tmpStr[20];
void init();
void init()
{
/* Place your initialization/startup code here (e.g. MyInst_Start())
*/
CYGlobalIntEnable;//enable global interrupts
// channel = CHANNEL_1;
//Clock_PWM_Start();
PWM_Start();
AMuxSeq_Start();
AMuxSeq_Next();
LCD_Start();
LCD_Position(0,0);
LCD_PrintString("V1:");
LCD_Position(1,0);
LCD_PrintString("V2:");
TrackHold_1_Start();
TrackHold_2_Start();
ADC_IRQ_Enable(); //start ADC_isr interrupt
ADC_Start();
}
void main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
init();
for(;;)
{
if (flag==1)
//
{
flag=0;
//Clear flag
/* Flag is reset in the ADC interrupt when the two channels are
converted */
if(avr_1_result > 0xFFFF){
avr_1_result= 0;
}
string */
*/
LCD_PrintString(tmpStr);
if(avr_2_result > 0xFFFF)
{
avr_2_result= 0;
}
sprintf(tmpStr,"%1.1f ", avr_2_result);
LCD_Position(1,4);
LCD_PrintString(tmpStr);
}
/* Create a formatted
/* Display on LCD
#include "cytypes.h"
#include "ADC.h"
/****************************************************************************
***
* Custom Declarations and Variables
* - add user inlcude files, prototypes and variables between the following
*
#START and #END tags
*****************************************************************************
**/
/* `#START ADC_SYS_VAR` */
extern uint16 flag;
extern uint16 results[2], channel_1_result, channel_2_result;
float avr_1_result, avr_2_result;
void AMuxSeq_Next(void);
/* `#END` */
/****************************************************************************
***
* Function Name: ADC_ISR
*****************************************************************************
***
* Summary:
* Handle Interrupt Service Routine.
*
* Parameters:
* void
*
* Return:
* void
*
* Theory:
*
* Side Effects:
*
*****************************************************************************
**/
CY_ISR( ADC_ISR )
{
/***************************************************************************
* Custom Code
* - add user ISR code between the following #START and #END tags
**************************************************************************/
/* `#START MAIN_ADC_ISR` */
static uint16 channel_index=0;
static uint16 sample_Count=0;
AMuxSeq_Next();
results[channel_index]= ADC_GetResult32();
channel_index= channel_index ^ 0x0001;
if (channel_index==0)
{
channel_1_result+= results[0];
channel_2_result+= results[1];
}
sample_Count++;
else if (channel_index==1)
{
ADC_StartConvert();
}
if (ADC_StopConvert == 1)
{
ADC_StopConvert();
}
if (sample_Count==100)
{
//avr_1_result= 3.3* channel_1_result/65535;
//avr_2_result= 3.3* channel_2_result/65535;
avr_1_result= channel_1_result/100;
avr_2_result= channel_2_result/100;
flag = 1;
sample_Count = 0;
}
/* `#END`
*/