cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ 5, 3 & 1

Anonymous
Not applicable

Just started using the psoc 5 and learning C programming a few days ago.

   

Figured I would share my frist project with everyone.

   

I know the coding is crude, but it was done just as a way to start using the psoc 5.

   

I have a few projects in mind for using it, and need to learn so much,

   

as there really is a lot going on in this chip.

   

any pointers as to using pwm for DDS in the 300KHz range and at 1Hz steps.

   

Also need to know how to get at the SC/CT blocks directly so I can make my own part.

   

So much to learn, so little time. 🙂

   

Anyways, I will post more as I learn more abot this chip and hope that other will find it useful.

1 Solution
ETRO_SSN583
Esteemed Contributor

The project at the Cypress web site compiles but does not seem to

   

work, for the indexed DDS. I have filed a CASE and will post results

   

when I get them.

   

 

   

Also you might file a CASE requesting contact with author to see if he

   

can confirm your target spped goals.

   

 

   

Regards, Dana.

View solution in original post

0 Likes
40 Replies
ETRO_SSN583
Esteemed Contributor

Your code needs some assistance.

   

 

   

This construct,          ADC_VoltsData[1] = '0' + (ADC_Volts/100000) % 10;   // Format results for display

   

is trying to add an ordinal value, '0', to a long integer, ADC_Volts, to create a string in effect.

   

 

   

The easy way to do this is to use sprintf() [ printf(), but to a buffer ]  to create a single formatted string,

   

then UART_1_PutString( ) to send it all in one command.

   

 

   

Attached is info for setting up format statement of sprintf().

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

Correction to last post, I see you are trying to extract a single digit and

   

save its ascii value, which is one way of doing it, except you are trying

   

to combine a float + a char into a char, you need some cast operators.

   

If you stay with this method use ftoa() to convert float A/.D result to string,

   

then operate on that for formatting.

   

 

   

But sprintf() still the easy straightforward way.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

Regarding SC/ST blocks -

   

 

   

www.cypress.com/

   

 

   

You can consult TRM for register control of blocks.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Expert II

There are 24 UDBs in a PSoC5 (Univesal Digital Blocks) from which many of the usermodules are built. These UDBs can be used to make up own modules by programming them using VeriLog as language. There are some videos (search there and take the time to watch) showing how that works and some examples are in detail described at the PSoC Sensei Blog.

   

You have set the conversion mode of your ADC to Multi-Sample which is not completely wrong. This mode is used when continually switching with an analog multiplexor between different inputs. Better would be to use the "Continuous" mode. With the higher sample rate I would suggest you to average some measures (10 to 100) to reduce some noise.

   

 

   

As a hint for programming (folks here know me to have a strong relationship to "Readable Code") I would suggest you to

   

Use separate functions for separate jobs ie. void InitializeHardware(void) or (void DisplayAnalogValue(int32 Voltage)

   

Your commenting is excellent, I like to see that

   

Keep the indentation of the lines more consistent

   

Use highlighting different areas of interest like variable declaration and function code

   

 

   

Bob

0 Likes
Anonymous
Not applicable

First I would like to thank youtwo for even replying to this post.

   

Danaaknight,

   

There is a little more going on with my convertion than you may see untel you dig a little deeper.

   

I'll try and give more details as to what I did and why.

   

I am doing this because this is the way I learn.

   

Fisrt off, the D/A results and for in floating point, it is a signed number, that is a count from the converter.

   

This count can be a negative number, as the D/A can go 100mv below ground.

   

(Yes, Bob, I did not put comments about this in the code 🙂 )

   

So, I just guessed at what the count offset would be for this 100mv and wipe out any negative number from the count.

   

Next is my conversion form the count to a long 32 interger.

   

This is really just multiplying the count by the weight of what one count is equal to in voltage.

   

BTW there is an API to convert the results into Volts, millIvolts and microvolts, just cound not seem to get it to work.

   

The problem with with any results held in a interger or any variable for that matter, is that leading 0's are surpressed.

   

String's do not have this problem, so I have to convert my leading 0 surpressed number into a string.

   

This is done by checking the weight of each digit "(result/weight) % 10;",  if that weights position is 'empty',

   

then an ascii '0' and placed in the string, if the weights position has in value, that is just passed to the string.

   

To use ftoa() I would have to look at how efficient that code is, and if it's is, then sure.

   

now on to sprintf(), I am assuming this is a serial version of printf() you provided a PDF on.

   

If so, I don't think I can use it, as this would not allow for flow control of the serial data to the display.

   

However, printf() does have formatting commands in it. BTW thank you for that fine doc on a C function.

   

As I had said, very new to C programming and the biggest problem I have with it is syntax and knowing whats

   

availabale for a function.

   

The link you had posted is abut the differences between products of the SC blocks.

   

how about a link to the TRM for register control of blocks.

   

 

   

Now to reply to Bob,

   

Bob, I know of VeriLog, but know nothing about it, some thing else I have to learn.

   

This is what I meant by so much to learn, so little time :).

   

To fully use this chip, there is a lot of things to learn, and that takes time.

   

I have watched the video/classes, some 20 of them so far, and a lot of it is over my head,

   

as I am not even close to knowing a thing about the subject.

   

Anyways, gevin time, I will get there.

   

As far as my programming, Like I said, this was crude, just wanted results displayed.

   

I wanted to see some thing out of the chip and my time invested into it.

   

Yes, I know I should have broken it into more callable loops :), but was being lazy.

   

But you brought up highlighting, not sure what you mean by this, as I do thing the file gets saved

   

as a basic text file, no real formatting.

   

 

   

Again, really thank you for your insights, and will be playing more and hopefully I improve as time goes on.

0 Likes
ETRO_SSN583
Esteemed Contributor

printf() prints to the system stdout, see this book, attached. Normally

   

one thinks of a console or printer. Can also be a file system.

   

 

   

sprintf() prints to a buffer you set up.  Uses same formatting control as

   

printf().

   

 

   

So normally using sprintf() it converts the numeric, and formats it all in one

   

call and places results in a buffer. Then you use string UART command to

   

xmit to whatever.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

"This count can be a negative number, as the D/A can go 100mv below ground."

   


You are referring to the offset spec, which can be +/- .9 LSB. The VDAC value

   

you write is a uint8, unsigned. 1 LSB, in an 8 bit DAC, with a reference of 1.024 V,

   

equals ( 1 / 256 ) x 1.024V = 4 mV.

   

 

   

One way of handling offset is to write 0 to VDAC, and measure offset with A/D.

   

Then subtract from further DAC readings. Of course this is a crude approach

   

as T effects, noise, long term drift not handled.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

danaaknight,

   

 

   

Thank you so much for clearing up sprintf() in my mind, I had looked at it and just did not see how to apply it.

   

You have creally shown me what it can do and how it relates. I guess there will be a ver 3 of this little project. lol

   

As in ver 2, I did a lot of clean up from the advive you two had given me, but I did not add in more loops,

   

but it is more clearly written for doing so.

   

 

   

as far as the offest goes, I used a 7 1/2 digit volt meter and a secondary 7 digit voltage standard as the source to the adc.

   

yep, I did look at how well the adc did over temp, conversion speed and number of bits. 

   

I have to say, not bad for a cheap little chip!

   

 

   

I see that I said D/A, sorry about that, this whole project is using the delta sigma a/d.

   

 

   

BTW, thank you for the C programming book!

0 Likes
Anonymous
Not applicable
        OK I made some improvements to this little voltmeter. Now using calls to functions and snprintf However, I really don't think using snprintf over the way I was doing it is better. snprintf used 20k of flash, come on now, 20k compared to like 30 bytes doing it my way. I hate to see what snprintf does to cpu cycles. If you read the comments, you'll note that I want to pass variables to and from my function calls, just can't seem to get how that works, until I firure it out, most variables are global.   
0 Likes
Bob_Marlowe
Expert II

Concerning the use of local vs global variables

   

http://www.cypress.com/?app=forum&id=2492&rID=73967

   

 

   

Bob

0 Likes
Bob_Marlowe
Expert II

Going to your sources:

   

Indentation is not the same all over. There is an editor-setting that uses tabs instead of spaces to indent making corrections a lot easier. Stick to a scheme, for instance

   

Functions and and local var declarations start at column 0 after a compound statement indent, befor a "}" de-indent

   

Your keeping comments in the same line and starting at a common column is excellent, it improves readability a great lot!

   

 

   

The definition of avgcount as a float is a wrong type and does not need to be a variable, a #define would be enough

   

You do not calculate an avarage, you simply get 8 ADC-values and discard 7 of them. You ought to add them and divide the result by (avgcount -1). Here you can see that it would be better to declare avgcount as 8 (and compare in the loop with "<=")

   

 

   

Do not care (Yet) for the overhead some of the library routines take. When you really run out of flash there are some methods to save lots of kByte.

   

A function not returning a value does not need an explicit "return" statement, it always returns at the last closing "}" of the function. (although you may return from any point within if you want to)

   

I append a link to my favourite C-Manual where you may have a look at functions and returning values from a function that might help you further. http://publications.gbdirect.co.uk/c_book/

   

 

   

Bob

0 Likes
ETRO_SSN583
Esteemed Contributor

Yes, GCC pulls in a lot of capability when you use sprintf(), along with other library

   

f()'s. You can always code a subset of a library function into lower FLASH usage,

   

just as you have done. stdio.h

   

 

   

Take a look at a reduced sprintf() that some have used www.cypress.com/

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

The discussion Global vs Local. Like everytjhing in HW and SW design there rarely

   

is one "right" answer, just a painting with many shades.

   

 

   

I am completing a design where I used ~ 99.5% of FLASH. I found that with most

   

variables global, and using pointers to long globals especially , I saved a lot of space

   

and performance. Especially not passing longs onto stack.. Pointers for longs

   

especially productive on code size. Stated another way pointer usage on a machine

   

for any variable > native integer size of machine.

   

 

   

Keep in mind techniques are compiler and architecture dependent, what works in

   

on one compiler may not in another, same goes for core.

   

 

   

My code does not suffer from various routines modifying the global unexpectqadly as the

   

code is pretty much serial, so the considerations Bob and others express, not applicable.

   

 

   

Shades of grey 🙂 The beauty of todays tools easy to create a simple test and try to establish

   

a result.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

Code size reduction techniques -

   

 

   

    

   

          

   

These helped me in a similar experience -

   

 

   

1 - If any float math minimize the number of lines you do divides, if possible convert

   

to multiplies. Convert float to integer math where possible. Pay attention to factoring

   

of expressions, possible operation reduction, hence code reduction may result.

   

 

   

2 - Lines with function calls, minimize f(g()) compound typed expressions.

   

 

   

3 - Make sure you only use a variable type no larger than needed.

   

 

   

4 - Use unsigned variables wherever possible.

   

 

   

5 - Watchout for structures with mixed const and ram pointers within them,

   

some compilers choke on this.

   

 

   

6 - If you are heavy on Flash, light on RAM use, convert routines to RAM based

   

wherever possible.

   

 

   

7 - Try test cases of looping structures, to see what affects code size generation.

   

 

   

8 - Examine .lst file for code that looks wacky in bytes used, understand what

   

compiler did, and consider rewrite.

   

 

   

9 - Use inline ASM where .lst file C generation looks excessive.

   

 

   

10 - Look at module reuse, sharing, dual purpose, to eliminate # modules 

   

needed, like counters/timers....Also look at data sheets of modules that could

   

serve function needed, and compare ROM/RAM requirements needed. Optimize

   

global HW, like clocks VC1/2/3/Sleep, to eliminate need for other timer/counters.

   

Use register routing control to "share" module from one task to another, one pin

   

to another.

   

 

   

11 - Extended library, functions within them are written to be perfectly general,

   

hence larger code size, you may be able to write one with less code needed for

   

your specific requirements that result in smaller code size.

   

 

   

12 – Look for approximations to compute transcendental functions if used.

   

 

   

13 - Although no longer supported by HiTech or Cypress, the HiTech Pro compiler

   

yielded on first try ~ 40% code reduction in my design when I first converted

   

to it. Then the prior comments yielded another 4 K later in design as I was up

   

against 32 K Flash limitation.

   

 

   

14 - Some compilers have a setting to optimize code size or speed, the latter

   

prone to larger code size. Also look at compiler vendors web site for ap notes

   

and suggestions on optimization, compilers from different vendors behave and

   

optimize  differently.

   

 

   

15 - const data, strings, etc.., look for ability to reuse common string mnemonics,

   

text.

   

 

   

16 - Pointer usage can lessen code size, see url's below. Look for function calls

   

passing longs as value vs pointer, convert to latter. Compiler has to copy all these,

   

if not referenced. Do not pass longs or floats as values, keep always in mind native machine size.

   

 

   

17 - Most compilers will optimize when indexes, pointers, a power of 2, or divides,

   

divide becomes a shift.

   

 

   

18 - Look at how linker distributed code and data segments, sometimes you can discover

   

a poor decision by linker and force code/data into certain psects using pragma constructs,

   

thereby minimizing wasted ROM space.

   

 

   

19 – When you debug generally you want to turn off optimization, as compiler/linker will

   

remove code and make jumps that do not make “sense” but are the result of optimization.

   

When you are up to Flash boundary you may not be able to turn it off, otherwise

   

application will not load. Keep this in mind, that  your debug strategy may have to change.

   

I also found if using ICE Cube that debugger may no longer report “watch” variables, this

   

occurred at ~ 31.5K bytes. In either case you may want to comment out large code sections

   

to effectively debug.

   

 

   

20 – f() calls take overhead, if you only call a f() once you might eliminate it as a f() call and

   

place code inline.

   

 

   

21 – Look for f() opportunities, wherever you are coding and repeating similar  operations.

   

This is obvious, but sometimes missed.

   

 

   

22 – Check compiler on macros, to see if they are being optimized or just being used inline

   

using more code space vs a f() call solution.

   

 

   

23 – Examine compiler/linker parameter control. For example in HiTech there is the AUTOBANK

   

setting that controls where local variables are stored, in my case setting to 1 lowered code size by

   

~ 250 bytes. READ the MANUAL !

   

 

   

24 – Use inline variable declarations, vs pre declaration (compiler dependent) -

   

 

   

                This                        void dosomething ( void  ) {

   

 

   

                                                                for (  unsigned char I = 0;…..

   

                                                }

   

 

   

                Not This               void dosomething ( void  ) {

   

 

   

                                                Unsigned char I = 0;

   

 

   

                                                                for (  I = 0;…..

   

                                                }

   

 

   

Some help -

   

 

   

http://www.codeproject.com/Articles/6154/Writing-Efficient-C-and-C-Code-Optimization

   

 

   

http://www.eventhelix.com/realtimemantra/basics/optimizingcandcppcode.htm

   

 

   

http://www.azillionmonkeys.com/qed/optimize.html

   

 

   

By using these techniques I was able to regain ~ 4K Bytes of code space in a 32K design, which

   

I promptly then used up again 😞

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Expert II

Dogma's project now uses 11% flash, so there's not yet any need for calling for the fire-brigade, in particular the optimization-level is set to "None" (which should be kept at this level during debugging).

   

A solution to reduce code-size used by sprintf() would be to use a different library which you can find after a short search at Mrs. google. Adaptation is easy to make, I did it for a PSoC4 which will get flash-busted when using sprintf().

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I want to start by thinking you to again, the help you have offered here has gone way beyond the support level that this forum was intented for.

   

Being new to C and programming in general, I have noting but questions, and the insights and resoures you two have gevin me have been immensely helpful.

   

Just remember, this is so much to take in and absorb, so please continue to be as patient with me as you have been.

   

 

   

First off, attacted is just the main C file of the project, as I really don't think there is any reason to put the whole thing up any more.

   

As this project had just been about learning C and what this chip can do, nothing more.

   

My planned use of this chip is so much more envoled, but until I get the basics down, there is no reason to move on with that project, so well continue on with this one as a learning endeavor.

   

 

   

The only reason I complained about flash size usage is that I will be wanting you use the lowest cost part to fulfill my system needs. Flash, Ram and CPU cycles are in my view at a premium and not to be wasted.

   

If I had my way this would all be done by opcode, but that is just way to hard for whats involved.

   

Ok, jumping tracks here while I have this on my mind, I need information on whats really inside the SC Blocks,

   

as I will be needing to get to the resistors, capacitors, and switches directly.

   

For example, I want to modify the way the PGA is set up, or use parts from the TIA, like a switch that connects directly to the outside world of the chip.

   

Any real info on this would be greatly helpful.

   

Ok, back to programming, Bob, attached in a new file, tried to clean up my indenting/de-indenting, and fixed var being all over the place in spacing.

   

Still not sure what to do with intenting, as no matter what I try, it always looks funny, but this last way of doing it looks better to me.

   

Using float with var's that really did not need to be floats, YES, I was doing that, I did it to play with all the diff. formatting types of sprintf, I was really using it as floating point with my results, tho, I did not have too, but I did, that has all been cleaned out now.

   

Now for the avg loop, I had set it up at first as you point out,but what I did not like was on exit of the loop, avg var was +1, as any loop will do, but this meant I had to -1 every were it was used, (cpu cycles and space), or use a new var.

   

Really what I had on my mind was that the number of avg should be comming from a user, and the user would be saying he wanted 8 avg or 12 or 99, and I did not want to do any math from the users input, so I think this code is a good choice to that end. I've checked and recheck, looks to be doing avg and not dumping any thing, but mabe i've missed some thing.

   

When I set of all the loop functions, I laid them all out with returns, as some need to return data and some don't, but come to find out that C can only return one var on exit, and as you can see, ADC exits with four var, so i'm working on understanding pointers for this data to be passed. So far, I am LOST. LOL

   

 

   

But I did get passing var to the loops. Now from what you guys showed that local and global var are really no diff on the psoc 5, there is no point to it, as it is only 4 global var used in my case, but I still want to figure it out and use it.

   

 

   

Please feel free to tear my coding apart and let me know how badly Iam doing, you really will not hurt my feelings 🙂

   

 

   

I am going to try and add a call function to get some of the offsets out, but again, this needs vars passed back to main.

   

Anyways guys, I do want to thank you again for your time and help, you two have gone way beyond the support level of this forum and I do thank you.

   

OK off to do some reading, I think you two have given me a few days homework. LOL

0 Likes
Bob_Marlowe
Expert II

I am now involved in µCs since 1980 and I've learnt so far a few things which make up my personal point of view:

   

Do not count execution cycles, the next CPU generation will be quite different.

   

When a program is too slow, wait one and a half year. The new CPU is twice as fast.

   

Do not use tricks to get out more of a chip than what is supported by its makers.

   

What we do is "Electronic Data Processing". Electronic is the chip you have got. Processing is the program. So when you have written down and structured your data the program works on, one big part is solved.

   

 

   

 

   

There are (nearly) no SC-blocks in a PSoC5, you may find those in a PSoC1. The building blocks of a PSoC5 are named UDBs and fixed function blocks with a dedicated function as ADC, SAR or DAC. The hardware definitions and connections you make on your sheet are processed by the "Fitter" which uses verilog to transform your given requirements into a datastream that is used to program the appropiate registers (all listed in one of the PSoC5 TRMs). There is no need to fumble around with those, you will rarely get better performance out of them, better leave it all to Creator.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Below is a reference as an example, and by no means what I am going to do.

   

There is so much in this little chip and it jusy may fulfill my needs over having a costum chip made.

   

I'll not know until I am able to test the the parts out to see if they will need my needs.

   

I look at things a little differently, I don't look at the way some one else did it, or what something designed to do.

   

I look at it as, what can I make it do to fulfill a need at a lowert cost and better performance.

   

Right now my design is pushing the envelope of what  a little micro can do, I've loot at TI's LM4F line, AVR...ect ect.

   

None have had even a chance of pulling it off, now the psoc comes along with a different way of doing things.

   

Like writing hardware in software, (to cool) and almost an ASIC and FPGA on a chip.

   

Well I am all in on this one, BTY, I use to design things with the CDP1802D, I have always pushed the design envelope and pain on keeping that track.

   

 

   

                          |---------------------------------------------|                              vcc

   

        |  |*              |         |

   

 

   

   

>---r1--|--|    *          r3        r6

   

 

   

 

           | +      *      |         |

   

 

           |  opamp    *---|----r5---|----->

           | -      *      |         |

>---r2--|--|    *          r4       === c1

        |  |*              |         |

   

   

                          |---------------------------------------------|                               |

   

                                                                                                                      O

   

                                                                                                                      ^

   

                                     software controlled switch                                  |

   

                                                                                                                      |

   

                                                                                                                      O

   

                                                                                                                      |

   

                                                                                                                   GND

0 Likes
Anonymous
Not applicable

looks like formatting killed that 😞

   

But I never did fit inside a little box on a computer screen.

0 Likes
Anonymous
Not applicable
        ok, up to ver 4, and still have a ways to go.   
0 Likes
ETRO_SSN583
Esteemed Contributor

As Bob knows, I am a contrarian.

   

 

   

“Do not count execution cycles, the next CPU generation will be quite different.”

   

In critical timing definitely look at execution, cycles, if you are having trouble meeting timing, thruput, speed, whatever.

   

Sometimes doing an inline ASM solution, or an ASM routine will cure the fact C compilers do a good job at most things,

   

but not all.

   

 

   

“When a program is too slow, wait one and a half year. The new CPU is twice as fast.”

   

Rarely wait for  technology to meet your goals, that’s a good way of losing your job. Your relevance is precisely because

   

you are at or close to the bleeding edge, you are designing what is not available, competitive edge, lower cost, etc..

   

 

   

“Do not use tricks to get out more of a chip than what is supported by its makers.”

   

Bob is right, if a chip is rated at 66 Mhz, do not pretend because your specific chip is 2 Ghz it will always run at that.

   

However the whole point of a programmable chip is precisely because it is programmable. The Vendors do not know

   

your intended purpose, nor should they care as long as you adhere to specs. However if you find and confirm with Cypress,

   

a new way of doing something, forge ahead. That’s what engineering is about. As far as the register TRM, use that if you

   

find that you can achieve more flexibility and design enhancement. But beware, Cypress heavily advertised and supported

   

use of register programming in PSOC 1, seems to be less so in 3/4/5, so confirm everything with them if you decide to

   

do register based programming. Note some module datasheets actually discuss some specific register manipulation, you

   

can infer that is supported based on what they tell you in module datasheet. Keep in mind Verilog, which is highly

   

supported and encouraged, is the ultimate register level manipulator. There you create everything, sort of ( synthesizer tool

   

actually doing most of it).

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

’”When I set of all the loop functions, I laid them all out with returns, as some need to return data and some don't, but come to find out that C can only return one var on exit, and as you can see, ADC exits with four var, so i'm working on understanding pointers for this data to be passed. “

   

 

   

An array, passed as a pointer to a function, is the best way to do this. For several reasons. First the whole array does not

   

get pushed onto the stack on call, hence less code, faster speed. In this case you operate on array in f() and just return

   

nothing, as the array was modified by your code. Looks like

   

 

   

unsigned long MyRay[ 4 ];                             //  Declare the array

   

void    Get4lVariables (  &MyRay[ 0 ]  );       // Function Proto, can also be typed as

   

void    Get4lVariables (  MyRay );

   

..

   

..

   

void  Get4Variables ( MyRay ) {

   

            MyRay[ 0 ] = 1011L;

   

            MyRay[ 1 ] = 234567L;

   

            MyRay[ 2 ] = 33211L;

   

            MyRay[ 3 ] = 445567L;

   

            return;

   

}

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

Screwup, should be -

   

 

   

unsigned long MyRay[ 4 ];                                                         //  Declare the array

void    Get4lVariables(  unsigned long *AnyRay  );             // Function Proto

void main(void)
{


    Get4lVariables (  MyRay );

    for( ; ; ){ }
    
}
void  Get4lVariables( unsigned long *AnyRay ) {

    AnyRay[ 0 ] = 1011L;

    AnyRay[ 1 ] = 234567L;

    AnyRay[ 2 ] = 33211L;

    AnyRay[ 3 ] = 445567L;

     return;

}

0 Likes
HeLi_263931
Honored Contributor II
        Regarding your DDS question, you might want to look at some stuff:   
http://www.cypress.com/?rID=39408   
http://www.psocdeveloper.com/uploads/tx_piapappnote/an2109.pdf (for PSoC1 though)   
http://www.hendriklipka.de/hardware/admscope.html   
0 Likes
ETRO_SSN583
Esteemed Contributor

Caution, keep in mind DDS at 300 Khz x #samples/wave period = rates

   

you have to move data at and make decisions. So if you choose 100

   

samples/waveform, then 300 Khz turns into a 30 Mhz DMA rate, probably

   

a challenge.

   

 

   

All depends on how much distortion you can tolerate.

   

 

   

Regards, Dana.

0 Likes
HeLi_263931
Honored Contributor II

The DMA won't be the limiting factor here, since the IDAC can only handle up to 8Msps. So given 300kHz output frequency there won't be more than about 24 samples per output period (but AFAIK even dedicated DDS chips aren't more accurate than that).

0 Likes
ETRO_SSN583
Esteemed Contributor

There are DDS chips that clock into the Ghz, with much more resolution and higher

   

frequency than can be done in PSOC DDS approach. There is a pile of them in

   

several hundred Mhz clocking, and the below at 3.5 Ghz, 12 bit I might add.

   

 

   

www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9914/products/product.html

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

I was looking at the Vdac, being a 1Msps part and only needing four smaples to represent any frequency, and that my waveforum requirements are for a squarewave.

   

This would get up to 250khz, however, I would not have the frequency resolution to meet the 1 Hz steping. 

   

There is an answer to this problem without using another chip, the fact that the psoc 5 has a up/dowm mixer in it 🙂

   

I am also looking at a pwm to solve the problem, but that adds it's own problems, the final answer will no doubt be a compromise or may in fact incorporate a mix of all three solutions.

   

 

   

I took a break from learning C, only so much new stuff I can cram in there in a short time, so I was looking at the Sigma Delta converter and found the non-linearities near ground to be confusing, more will follow on this as soon as I have time to look into it.

   

 

   

Any problem can be solved by throwing more at it, But at some point one finds the futility in this and simplicity wins out.

   

In other  words, any thing is possible, just may not be practical at this time. The true art of engernerring, is finding a balance between those two goals, as simplicity lowers cost and and complexity may or may not add performance, put always increases costs.
 

0 Likes
HeLi_263931
Honored Contributor II

If you look at the posts I referenced, you will find a NCO (numerically constrolled oscillator). This allows you to have much better frequency control than a simple divider. And since you can control not only the NCO, but also its clock source, you can get rather high frequency resolution (at the cost of some complicated math to calculate the needed setting for clock and NCO)

0 Likes
ETRO_SSN583
Esteemed Contributor

The project at the Cypress web site compiles but does not seem to

   

work, for the indexed DDS. I have filed a CASE and will post results

   

when I get them.

   

 

   

Also you might file a CASE requesting contact with author to see if he

   

can confirm your target spped goals.

   

 

   

Regards, Dana.

View solution in original post

0 Likes
Anonymous
Not applicable

hli,

   

 

   

The NCO is a great idea, seen it posted just as a VCO (that did not work) also some one posted an update to it, but that also did not work, and your your post were it is used in the oscope.

   

I think it is a great idea, I just don't know enough about the psoc or C at this time to fix it, but will get there at some point.

   

It would be nice to have an out of the box answer, but I just don't think that is going to happen.

   

I really have not given the full spec's as to what I am after, like the phase noise, and jitter specs, as right now I don't even know them. But I am open to any idea that uses just the psoc 5, as long as there is 65% headroom left in cpu power for other tasks.

   

and responce time to user input has to be under 3 micro-seconds. I can say that any of the ARM MPUs at this point are going to have a hard time keeping up. But the psoc 5 has such a great analog section to it, the direct dma, I think it can pull off what I am after. I do have a prototype working of my invention done in analog forum with a AVR CPU doing just the math. it just doing that is not even close to target goals. a LM4F120 running at 80 Mhz easly kept up, but rhad to have a lot of analog support.

   

The idea is to turn as much of my analog front end in to digital/software and use the analog section to cover what the cpu cant handle, if that means making an analog VCO  into it, that is what i'll do.

   

 

   

Like I said, I think the psoc is the best bet to get a single chip solution for this design.

   

I am sorry if I came off as being dismissive, it was not intention or desire to do so!

   

I think the support here has been great, above and byhond the scope of this forum, and I do thank you for it.

   

OK, have some time today to look back in to pointers.

   

 

   

danaaknight,

   

Is this line below, a global var, when placed outside of main?

unsigned long MyRay[ 4 ];      

   

I thought the hwhole idea of pointers whas not to use global var.

0 Likes
Bob_Marlowe
Expert II
        *ANY* variable declared outside a function (Do not forget: main() is a function, too) is a global variable. Its scope (visiability) starts with the declaration, its endurance (lifetime) is while main() is running. Pointers and global variables do not have a defaulted relationdship, they contain the address of a variable (or of a function)   
   
Bob   
0 Likes
ETRO_SSN583
Esteemed Contributor

If yiou review the thread there are pros and cons using Globals. I have designs

   

where there are almost no globals, and ones at the extreme opposite. If you

   

have 'serial" code, and many f()'s using the same array, make it global and use

   

a pointer to it. Saves code space, especially on variables > machine native integer

   

size, like longs and floats.

   

 

   

Take a look again at Bob's and my comments on globals. You never get something

   

for nothing, well almost never.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

at this point i'm just tring to figure out how to use pointer to pass info back and fourth from main.

   

I do get the idea of pointers, the pointer holds the adderess of the var, and the var has the data

   

and that, *ANY* variable declared outside a function  is a global variable, and I know main() is a function.

   

I lossely understand the object part of C, not fully there yet

   

I also get using global over local, and in this little voltmeter, it be a lot easier just to use globals, but I'd not learn any thing new.

   

I guess until I get in there and write some code, i'll not see the light.

   

 

   

int x = 1, y = 2, z[10];
int *ip;                                     /* ip is a pointer to int */
ip = &x;                                   /* ip now points to x */
y = *ip;                                    /* y is now 1 */
*ip = 0;                                  /* x is now 0 */
ip = &z[0];                             /* ip now points to z[0] */

   

int *ip;

   

double *dp, atof(char *);

   

I get all of the above, next is a part I don't get,

   

If ip points to the integer x, then *ip can occur in any context where x could, so
*ip = *ip + 10;
increments *ip by 10.

   

Why would the the pointer be incremented by 10 and not x, and why would you increment this pointer?, would you not be getting some other unknown data, as you are nolonger pointing to x?

0 Likes
Anonymous
Not applicable

*ip = *ip + 10;
increments *ip by 10.

   

 

   

LOL, never mind, I see that *ip is still the pointer to x, *ip remains unchanged.

   

but the later part of my question still holds, why would you change the value of a pointer, and the results of doing so.

0 Likes
ETRO_SSN583
Esteemed Contributor

When you are addressing an array your are doing so with a pointer.

So you often do something like this -

uint8 i = 0;

unit8 charray[ 10 ];

..

..

lets clear charray

for ( i = 0, i < 9, charray[ i ] = 0, i++ );

we could do it this way

uint8 *ip = &charray[ 0 ];

for ( i = 0, i < 9, *( ip + i ) = 0, i++ );     // Result the same

   



both are equivalent

   



pointers can be byte, word, long, but not bit.

pointers can also point to functions, so that the f() you execute can be

chosen via a computation. Also point to structures.

   



Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

This might be usefull, attached.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

This project is by Brad Budlong of Cypress, but it does not work, atlest for me.

   

 

   

Oh and Dana, Thanks again for yet more homework. 🙂

0 Likes
Bob_Marlowe
Expert II

With a new project and new usermodules (and new problems) I would suggest you to start a new thread...

   

 

   

Bob

0 Likes