Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 4 Forum Discussions

Ivan-Liao
Level 1
First like given First reply posted First question asked
Level 1

I used the GPIO & Delay to create simple square waveform in main code.

And I can't  measure waveform point by ADC module at the same time.

My goal is creating square waveform while measure waveform point by ADC module.

thx~~

0 Likes
1 Solution
MotooTanaka
Level 9
First comment on KBA 1000 replies posted 750 replies posted
Level 9

Hi,

I tried with CY8CKIT-044 (CY8C4247AZI-M485).

The schematic was

001-schematic.JPG

I used

TCPWM to generate the waveform

Timer to generate (about) 1.5us trigger ADC

Pins

002-pIns.JPG

Timer Config

003-Timer_config.JPG

TCPWM Config

004-pwm_config.JPG

main.c

Since ADC is triggered every 1.5us, we don't have much time to do with the result of ADC,

so I just get mV value of the ADC and if it's over 2.5V (2500mV), Turn LED on

otherwise turned LED off in the ADC done ISR.

#include "project.h"
#include "stdio.h"

#define LED_ON (0u)
#define LED_OFF (1u)
#define ADC_THD 2500

CY_ISR(adc_isr)
{
    uint16_t raw_value ;
    int16_t adc_mV ;
    
    adc_done_ClearPending() ;
    raw_value = ADC_GetResult16(0) ;
    adc_mV = ADC_CountsTo_mVolts(0, raw_value) ;
    if (adc_mV >= ADC_THD) {
        LED_Write(LED_ON) ;
    } else {
        LED_Write(LED_OFF) ;
    }
}

void init_hardware(void)
{    
    CyGlobalIntEnable; /* Enable global interrupts. */    
    
    UART_Start() ;
    
    TCPWM_Start() ; /* output wave start */
    
    adc_done_ClearPending() ;
    adc_done_StartEx(adc_isr) ;
    
    ADC_Start() ;
}

int main(void)
{    
    init_hardware() ;
    
    UART_UartPutString("\x1b[2J\x1b[;H") ;
    UART_UartPutString("ADC Test\n\r") ;
    
    Timer_Start() ; /* ADC sampling start */
        
    for(;;)
    {
    }
}

When Ran

Yellow: the output waveform

Blue: ADC Trigger

Magenta: LED output depending on the value of ADC (May be I should have made it opposite)

IMG_5211.JPG

moto

 

View solution in original post

3 Replies
MotooTanaka
Level 9
First comment on KBA 1000 replies posted 750 replies posted
Level 9

Hi,

It would be nice if you can provide us information about

(1) Which PSoC device are you planning to use?

(2) What is the frequency/period of the square wave?

(3) How often do you want to sample ADC or what is the sample frequency/period of ADC?

moto

0 Likes
Ivan-Liao
Level 1
First like given First reply posted First question asked
Level 1

Hi,

It would be nice if you can provide us information about

(1) Which PSoC device are you planning to use?

A:I want to use the PSoC 4200M.

(2) What is the frequency/period of the square wave?

A:The waveform is below.

IvanLiao_0-1656054147491.png

(3) How often do you want to sample ADC or what is the sample frequency/period of ADC?

A:I set acquisition time 1.5us.

 

0 Likes
MotooTanaka
Level 9
First comment on KBA 1000 replies posted 750 replies posted
Level 9

Hi,

I tried with CY8CKIT-044 (CY8C4247AZI-M485).

The schematic was

001-schematic.JPG

I used

TCPWM to generate the waveform

Timer to generate (about) 1.5us trigger ADC

Pins

002-pIns.JPG

Timer Config

003-Timer_config.JPG

TCPWM Config

004-pwm_config.JPG

main.c

Since ADC is triggered every 1.5us, we don't have much time to do with the result of ADC,

so I just get mV value of the ADC and if it's over 2.5V (2500mV), Turn LED on

otherwise turned LED off in the ADC done ISR.

#include "project.h"
#include "stdio.h"

#define LED_ON (0u)
#define LED_OFF (1u)
#define ADC_THD 2500

CY_ISR(adc_isr)
{
    uint16_t raw_value ;
    int16_t adc_mV ;
    
    adc_done_ClearPending() ;
    raw_value = ADC_GetResult16(0) ;
    adc_mV = ADC_CountsTo_mVolts(0, raw_value) ;
    if (adc_mV >= ADC_THD) {
        LED_Write(LED_ON) ;
    } else {
        LED_Write(LED_OFF) ;
    }
}

void init_hardware(void)
{    
    CyGlobalIntEnable; /* Enable global interrupts. */    
    
    UART_Start() ;
    
    TCPWM_Start() ; /* output wave start */
    
    adc_done_ClearPending() ;
    adc_done_StartEx(adc_isr) ;
    
    ADC_Start() ;
}

int main(void)
{    
    init_hardware() ;
    
    UART_UartPutString("\x1b[2J\x1b[;H") ;
    UART_UartPutString("ADC Test\n\r") ;
    
    Timer_Start() ; /* ADC sampling start */
        
    for(;;)
    {
    }
}

When Ran

Yellow: the output waveform

Blue: ADC Trigger

Magenta: LED output depending on the value of ADC (May be I should have made it opposite)

IMG_5211.JPG

moto