Design Con 2015
Breaking News
Comments
Max The Magnificent
User Rank
Blogger
Being prodded into action
Max The Magnificent   6/27/2014 3:12:00 PM
NO RATINGS
Hi Aubrey -- I have one each of the PSoC 4100 and 4200 prototyping kits sitting on my desk -- and also a PSoC 4 Pioneer Kit -- your blogs are prodding me into action with regard to using them in one of my hobby projects.

betajet
User Rank
CEO
"volatile"
betajet   6/27/2014 3:48:48 PM
NO RATINGS
Aubrey wrote: ... the compiler had optimized away the dummy memory accesses like cDummy++; ...

Most C compilers let you declare a variable to be "volatile", e.g.,

    volatile int cDummy;

which tells the compiler not to optimize loads and stores to that variable.  "volatile" is mostly used to identify a variable as memory-mapped I/O, which means it could change value any time, e.g., if it's the current value of GPIO pins.  Writes to a volatile variable may have side-effects like shifting data out though a UART pin.  "volatile" is also used for variables that are shared with interrupt service routines or other tasks.

antedeluvian
User Rank
Blogger
Re: "volatile"
antedeluvian   6/27/2014 4:04:56 PM
NO RATINGS
betajet

Most C compilers let you declare a variable to be "volatile", e.g.,

    volatile int cDummy;

which tells the compiler not to optimize loads and stores to that variable.  "volatile" is mostly used to identify a variable as memory-mapped I/O, which means it could change value any time, e.g., if it's the current value of GPIO pins.  Writes to a volatile variable may have side-effects like shifting data out though a UART pin.  "volatile" is also used for variables that are shared with interrupt service routines or other tasks


Thanks for pointing this out. However, it seems to me that I adopted a rather poor and even inelegant method of creating code usage. It would have been better of me to adopt the use of assembly instructions like asm ("nop");

 

Garcia-Lasheras
User Rank
Blogger
Re: "volatile"
Garcia-Lasheras   6/29/2014 5:12:22 PM
NO RATINGS
@Antedeluvian: The idea has been bouncing around in my head for some time now, but after reading your blogs, I'm completely sure I want to try one of these PSoC devices ;-)

About the ARM code, you have mentioned Keil compiler. Do I need to buy a Keil license in order to work with the PSoC 4 device or everything I need is included in the Cypress toolchain?

 

KB3001
User Rank
CEO
Re: "volatile"
KB3001   6/29/2014 6:42:49 PM
NO RATINGS
@Garcia-Lasheras, there is a free Keil download (from www.keil.com) although it's 32k code size limited. I believe PSoC creator uses keil MDK in the background.

antedeluvian
User Rank
Blogger
Re: "volatile"
antedeluvian   6/29/2014 8:49:28 PM
NO RATINGS
Javi

Do I need to buy a Keil license in order to work with the PSoC 4 device or everything I need is included in the Cypress toolchain?

No you don't have to buy anything. I think there is an option which will improve code density or something like that, but so far I haven't bumped into any limitations (and I have used it on the PSoC5 as well). However you do have to register with Keil.

KB3001
User Rank
CEO
Debugging
KB3001   6/29/2014 11:49:20 AM
NO RATINGS
Did you consider using Keil MDK for software development especially debugging?

antedeluvian
User Rank
Blogger
Re: Debugging
antedeluvian   6/29/2014 8:46:20 PM
NO RATINGS
KB3001

Did you consider using Keil MDK for software development especially debugging?

No. I stayed within PSoC Creator.

mithrandir
User Rank
Rookie
That annoying debug issue
mithrandir   6/30/2014 12:14:18 AM
NO RATINGS
Yeah the interrupt bug can be quite annoying, I ran into it several times.

If the interrupt isn't quite as critical for what you want to debug, you can disable breakpoints while debugging in Creator(I remember a little lightning symbol which can disable all global interrupts). Not an elegant solution but can work sometimes.

Moving some of my hobby stuff from PSoC5 to PSoC4 felt like quite a step back for me though. You get so used to any pin anywhere you forget that PSoC4 has a quite a few fixed function pins as well. For the sweet price point though, its well worth the sacrifice.

mithrandir
User Rank
Rookie
Re: That annoying debug issue
mithrandir   6/30/2014 1:11:35 AM
NO RATINGS
Oh and in case anyone is interested(note my shameless promotion here),

http://www.embedded.com/design/real-world-applications/4428811/Building-an-electronic-guitar-digital-sound-synthesizer-using-a-programmable-SoC

It uses PSoC5.

Wilton.Helm
User Rank
Rookie
PSoC 4 comments
Wilton.Helm   7/1/2014 5:52:24 PM
NO RATINGS
I expect changing from debug to release to change optimizations, although it should be overridable (some compilers are weak here).  Debugging optimized code is almost impossible, as some variables exist only in registers, common code elements are re-used and the physical ordering of instructions may not resemble the source code ordering.  The bottom line is that debugging optimized code involves at a minimum frequent unexpected bouncing around in the source.

As previously stated, volatile is a useful keyword.  It is also used for variables that may be changed by an interrupt. 

However, the clean way to do timed stuff is with a timer.  In its simplest form, set a hardware timer to some useful rate (generally between 1 us and 1 ms) and read it repeatedly until sufficent counts elapse.  A software tick timer updating a volatile variable is another (and more common) way to do the same thing, particulalry if the time interval required is in the ms range rather than us.  The more elegant approach for ms scale delays is to capture a start value and then go do something else, while checking back periodically to see if the interval has elapsed.  If precision is required, when the interval is nearly over it can hang in a loop for the last few counts.  Of course with the rich timer resources of the PSoc, a dedicated hardware timer and some logic is an even better alternative.  (BTW the major league part in this game is the Zynq, which has two A9 cores and about 100,000 gates of logic.)

I just found out about the $4 4200 proto kit a week or so and order half a dozen, four of which will soon be part of a project I have been meaning to do for several years.  I haven't plugged one in, yet, but am looking forward to it.  If I understand it right, the 4200 can implement six UARTS in hardware (two fixed and four as digital blocks--one is required for downloading and debugging).  Twelve bit ADC is a luxury for this type of chip, too, not to mention 32 bit RISC core, even if it is only M0.



Flash Poll
Top Comments of the Week
Like Us on Facebook
EE Times on Twitter
EE Times Twitter Feed

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Life
Frankenstein's Fix, Teardowns, Sideshows, Design Contests, Reader Content & More
Max Maxfield

Are Today's Designs Bound by the Constraints of Yesteryear?
Max Maxfield
25 comments
As part of my ongoing Pedagogical and Phantasmagorical Inamorata Prognostication Engine project (try saying that 10 times quickly), I'm working with Jason Dueck from Instrument Meter ...

Jolt Judges and Andrew Binstock

Jolt Awards: The Best Books
Jolt Judges and Andrew Binstock
1 Comment
As we do every year, Dr. Dobb's recognizes the best books of the last 12 months via the Jolt Awards -- our cycle of product awards given out every two months in each of six categories. No ...

Engineering Investigations

Air Conditioner Falls From Window, Still Works
Engineering Investigations
2 comments
It's autumn in New England. The leaves are turning to red, orange, and gold, my roses are in their second bloom, and it's time to remove the air conditioner from the window. On September ...

David Blaza

The Other Tesla
David Blaza
5 comments
I find myself going to Kickstarter and Indiegogo on a regular basis these days because they have become real innovation marketplaces. As far as I'm concerned, this is where a lot of cool ...