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

cross mob
Anonymous
Not applicable

 Hi, basically i'm designing a capsense button and slider by using CY8C20424. i need to generate a PWM to drive a buzzer, does the psoc designer 5.1 have the PWM generator module? or any other way i can do?

   

thanks in advance.

0 Likes
1 Reply
Anonymous
Not applicable

Hmm, no answers so far. 😞

   

I'm not familiar with the part but it looks like it has interrupts and a timer module. You can generate a PWM with a timer interrupt, an I/O pin and some simple logic. If you're already using the timer you might have to fiddle a bit to make it work at two different rates.

   

Here's a bit of code, it's derived from an LED driver but the principle is the same. It has a period of 256 interrupts, you adjust the duty cycle by setting 'brightness'. You could, for example, make it cycle more quickly by replacing the INC with an ADD and adjusting the value you add. Of course if the timer is otherwise unused you can simply adjust its rate. There are other things you can do but this code should provide a starting point.

   

brightness_counter doesn't need to be initialized. 🙂

   

brightness::                blk    1
brightness_counter:            blk    1


    push    a
    inc        [brightness_counter]                ; Increment the counter for the next cycle.
    mov        a,[brightness]                    ; Get the MSB brightness value.
    add        a,[brightness_counter]                ; Add to the counter and see if we overflow.
    mov        a,reg[MY_PORT]
    and        a,~MY_BIT                    ; Pre-load A with the port bit off.
    jnc        .ok_2
    or        a,MY_BIT                    ; Oh, it's on! Turn on the correct bit.
.ok_2:
    mov        reg[MY_PORT],a
    pop        a
    reti
 

   

One more caveat: it will never reach 100% duty cycle. If you ever need to you can test for 0 after the INC and do another increment, but that will also shorten the period to 255. Everything is a compromise. 🙂

   

I hope that's useful. It makes a lot of assumptions about the resources you have available. Good luck!

0 Likes