Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > Setting up PWM on a CY8C9560A

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Setting up PWM on a CY8C9560A
Moderator:
ARVI

Post Reply
Follow this topic



Setting up PWM on a CY8C9560A

ianlee74 posted on 01 May 2012 7:35 AM PST
Senior Member
11 Forum Posts

 Hi, I'm helping to develop a device driver for a module that uses the CY8C9560A.  I'm having a problem getting PWM to send a signal.  The data sheet isn't very clear to me regarding the exact steps or sequence that needs to be taken to activate PWM for a pin.  The code I'm using is below but all I am getting is a solid 1.63V output from PWM8.  Can you help point out what I might be missing?  

From some of the other posts, I gathered that it might be necessary to reset the device before the PWM settings take effect.  Is this the case?  Is there a way to soft reset this device?  If this is necessary then is there a way to reset just the one pin so that others are not interrupted?  Thanks!

io60p16.SetPwm(7, 0, 0x5e, 0x2f);  // Port 7, pin 0 = PWM8

        public void SetPwm(byte port, byte pin, byte period, byte pulseWidth)
        {
            WriteRegister(0x18, port);          // Select port
 
            var b = ReadRegister(0x1a);         
            b &= (byte)(~(1 << pin));           
            WriteRegister(0x1a, b);             // select PWM for port output
 
            b = ReadRegister(0x1C);             
            b &= (byte)(~(1 << pin));           
            WriteRegister(0x1C, b);             // Set pin for output.
 
            WriteRegister(0x28, (byte)(0x08 + pin));          // Select the PWM pin to configure.
            WriteRegister(0x29, 0x00);          // Config PWM (select 32kHz clock source)
            WriteRegister(0x2a, period);        // set the period (0-256)
            WriteRegister(0x2b, pulseWidth);    // set the pulse width (0-(period-1))
        }
 




Re: Setting up PWM on a CY8C9560A

Bob Marlowe posted on 01 May 2012 08:52 AM PST
Top Contributor
1768 Forum Posts

Can it be that you write a 0 (zero) into the PWM-Register 0x1a instead of a 1 (one) as the datasheet tells?

 

Bob



Re: Setting up PWM on a CY8C9560A

ianlee74 posted on 01 May 2012 09:18 AM PST
Senior Member
11 Forum Posts

 I think you're right, Bob.  Copy & paste error.  I'll give that a try tonight.  Thanks!



Re: Setting up PWM on a CY8C9560A

Bob Marlowe posted on 01 May 2012 09:26 AM PST
Top Contributor
1768 Forum Posts

Ian,

if it's that easy to help, you're always welcome!

 

Bob



Re: Setting up PWM on a CY8C9560A

Eilrem posted on 01 May 2012 05:46 PM PST
Cypress Employee
17 Forum Posts

If you're intending to write a 1 bit, then

 b &= (byte)(~(1 << pin));  

is certainly wrong. It writes a 0 on the selected pin. Try this code if you want to set the selected bit to 1:

b |= (byte)(1 << pin);  


Re: Setting up PWM on a CY8C9560A

Bob Marlowe posted on 02 May 2012 01:30 AM PST
Top Contributor
1768 Forum Posts

This is another case where I would strongly suggest to use macros for such simple (but easy targets for typos) jobs.

#define BitMask(BitNumber) (0x01 << BitNumber)

#define SetBit(Variable,BitNumber) (Variable |= BitMask(BitNumber)) 

#define ClearBit(Variable,BitNumber) (Variable &= ~BitMask(BitNumber))

#define GetBit(Variable,BitNumber) (Variable & BitMask(BitNumber))

 

The original line

b &= (byte)(~(1 << pin));  

would then read

ClearBit(b,pin);

and the line

b |= (byte)(1 << pin);

would become

SetBit(b,pin);

which (in my opinion) is far more readable than the original and thus (even if you cut & paste) would have avoided an error like this inherently.

 

Bob

(hope I made no Typos)






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20