Announcements

Equip yourself to optimize PSoc4 MCUs for Evs at the EV Webinar. Click here to register.

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

PSoC™ 4 Forum Discussions

YuCh_3947976
Level 3
Level 3
10 likes given 5 likes given First like received

Hi all,I want to set an output like below pic,the period of 100%(duty cycle) is 60 us another one(20%)  is 120 us

but the result on oscilloscope is not what I want,how can I do?

thanks

IMG_2169.jpg

pastedImage_0.png

pastedImage_3.png

pastedImage_1.png

IMG_2171.jpg

0 Likes
1 Solution

Hi,

May I assume that your problem is solved now?

> At the beginning I had plans to use IDAC,

> but I need a high voltage is around 3V,but the maximum  current of IDAC is 612uA,it can't output the voltage I want.

"Conceptually", if you replace 2K of my schematic to around 5K or higher, you can get 3V,

but driving capability is very low (as you know, 612uA).

moto

View solution in original post

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

Hi,

Usually PWM component generate 0 and 1 output.

If you want to have 100% and 20% output,

you can either use IDAC or DC bias PWM output.

So I tested with CY8CKIT-044

schematic

001-schematic.JPG

pins

002-pins.JPG

main.c

====================

#include "project.h"

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */  

    PWM_Init() ;

    IDAC_Start() ;

}

void ConfigPWM(uint16_t period, uint16_t compare)

{

    PWM_Stop() ;

    PWM_WritePeriod(period) ;

    PWM_WriteCompare(compare) ;

    PWM_WriteCounter(0) ;

    PWM_Start() ;

}

void ConfigIDC(uint8_t value)

{

    IDAC_SetValue(value) ;

}

int main(void)

{

    init_hardware() ;

  

    ConfigPWM(180, 60) ;

    for(;;)

    {

        IDAC_SetValue(100) ;

        CyDelayUs(60) ;

        IDAC_SetValue(20) ;

        CyDelayUs(120) ;

    }

}

====================

The result oscilloscope view was

The red signal is output of IDAC via 2k (kind of 100% and 20%)

The yellow signal is output of PWM (100% and 0%)

Since IDAC is controlled by FW, they are not synced.

IMG_4269.JPG

moto

yup,I got it wrong,PWM just adjusts pulse width

restate my questions,I want to control the time of high and low,then I adjust period and use the command(WriteCompare) to solve the problem.

At the beginning I had plans to use IDAC,but I need a high voltage is around 3V,but the maximum  current of IDAC is 612uA,it can't output the voltage I want.

0 Likes

Hi,

May I assume that your problem is solved now?

> At the beginning I had plans to use IDAC,

> but I need a high voltage is around 3V,but the maximum  current of IDAC is 612uA,it can't output the voltage I want.

"Conceptually", if you replace 2K of my schematic to around 5K or higher, you can get 3V,

but driving capability is very low (as you know, 612uA).

moto

thank you so much.

Finally, I used PWM to complete this project.

YuCh,

You can find more possible solutions in this thread

Ideas how to switch output voltage between V1 and V2 on TTL signal?

Using Opamp and PWM, it is possible to hardware switch between V1 and V2. This is simplest method if adjustment of V1 and V2 is not required at the run-time.

/odissey1

mux1.png

NiPi_4635631
Level 1
Level 1
First like received

PWM.jpg

180us

180us->0.00018s

f = 1/T =1/0.00018 = 5555,5Hz

check the formula T = 1/f = 1/5555,5 =1,8e-4(0,00018)s

calculate the period value for the frequency 5555,5Hz

12 000 000/5555,5-1 = 2159

Compare value @ 80% = (1-0.8)*(2159+1)=0,2*2160 =432

So I tested with CY8CKIT-049-41XX

Clock 12MHz

36us=20%    144us=80%

NoriakiT_91
Employee
Employee
100 likes received 50 likes received 25 likes received

This is my solution for your request using CY8CKIT-044

GS004756.png

This project consists of two PWMs.  The PWM_FAST generates 20%/100% duty waveform. The PWM_FAST is controlled by PWM_SLOW.  When the control signal is HIGH, PWM_FAST generates 100% duty sticking at HIGH.  The configuration of PWM_FAST is as follows.

GS004757.png

Please set the input mode of three input signals proper.  The carrier frequency of PWM_FAST is set to 1.2MHz (24MHz/20)

PWM_SLOW generates 60us/120us waveform with following configuration.

GS004755.png

Because I have no oscilloscope in home, I confirm the behavior with a handy DMM by decrease the control signal.

GS004752.png

GS004753.png

Please confirm the waveform with your oscilloscope.

Regards,

Noriaki

YuCh_3947976
Level 3
Level 3
10 likes given 5 likes given First like received

Thanks everyone for providing many ways.

but why is the low output of PWM result not 0?IMG_2182.jpg

0 Likes

Hi,

If you double click the Digital Output pin in your schematic,

You will see the configuration window something like below.

In the left-bottom corner, there is "Datasheet" button.

We can access the datasheet of the component from there.

010-pin-datasheet.JPG

In the datasheet, VOL is stated as 0.4 ~ 0.8 MAX.

So we may(?) see some floating value from the ground.

011-datasheet.JPG

I know that this is not ideal, but it is the way it is.

moto

0 Likes