How to deal with my program?

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

cross mob
Anonymous
Not applicable
        Now,i design a project to sample the datas of sine and cosine signals and store them to the SRAM.But I can't read the datas on the display correctly.In real,there are no datas showed on the LCD.I have uploaded the whole project and some pictures about it.Help me ,thanks.   
0 Likes
15 Replies
Anonymous
Not applicable
0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Did you already try to just write static data to the LCD? That way you can rule out problems with regards to that. If you succeed with that, try as next step to show data you have sampled.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When uploading a Workspace Bundle DO NOT use chrome, use IE or FireFox instead.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 hi Jobs,

   

the ile did not got uploaded, try to upload again.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable
0 Likes
Anonymous
Not applicable

@hli, i have not used the calling functions,only the main function in main.c.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I cannot see the places where you set the "dataready" variables, probably you set it in the generated .c-files.

   

Since this can get lost under some circumstances I would suggest to use a different way using an own interrupt module and

   

CY_ISR_PROTO(), CY_ISR() and isr_StartEx() as described in "System Reference Guide" under Creator Help.

   

There is an API for your ADC that will check or wait for a conversion done, first try could be to use this instead of an interrupt.

   

The conversion of an int16 to a string is best done with sprintf() but you may use the number-conversion routines of the LCD-module, look at the APIs in datasheet. Remember you do not have got an OS in the world of embedded processors, so you'll have to do everything yourself. So your function gcvt() may not work.

   

If there is nothing to see on your LCD try to write a "Hello World" and wait for a second...

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Somne thoughts -

   

 

   

1) You have two arrays, each int16, sized 19200. By my calculations

   

thats 76800 bytes, the part only has 64 KB. That leaves no room for stack

   

or any other variables, your own or the API's.

   

 

   

2) The arrays are declared as int16 in 1) above, but you are stuffing them

   

with a float from ADC_SAR_1_CountsTo_Volts(resultn); The arrays should

   

be declared as float.

   

 

   

3) The LCD has no applicable number conversion routines for what you are

   

trying to do. Bob's recommendation to use sprintf() makes most sense.

   

Attached help with formatting for sprintf()/printf().

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Thanks for Bob and danaaknight's help.First,i want to convert the float to the string,but the sprintf() may not have this function.And,i modified my project,the gcvt() can work well.But,i wonder why ADC_Setoffset() can not influent on the result of  ADC_CountsTo_Volts().There are negative numbers should be showed on the display in my ideal result.So,can you help me?PS:Bob is right,I set the ADC own interrupts in ADC_SAR_1_INT.c and ADC_SAR_2_INT.c.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable
0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Some corrections, untested but may work.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

It is so kind of you to help me modify the project although the result is same with mine.Thanks.

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your interrupt handling dissapeared again, so dataready didn't become ready  . Now it's using the safe way.

   

static array in main() gets initialized to zero when main() starts, that takes a lot of time, so I declared them as global vars.

   

That were the only changes I made. Program tested and is running.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I looked at code and here are some thoughts -

   


   

1) Your reference should be Vdd/2, and range set to 0.0 ± Vdda/2 (Differential) –Input ± Vdda/2

   

You should not need to use the offset function then.

   


   

2) You did not set the flags in the IRQ, dataready1 and dataready2 when ISR

   

occured.

   


   

3) You are converting at a rate of 100 KSPS, then trying to write LCD at that rate.

   

LCD has its own controller, and at this rate you are over writing the LCD rate wise.

   

It will never display every sample taken. Seems to me you should take a set of samples

   

(5000) then step thru the sample array showing on LCD at some very slow rate ?

   


   

4) You di not enable global interrupts. Right after you enter main() issue a CyGlobalIntEnable;

   


   

5) In ISR you set a flag, then in main() try to process loading array with sample. Problem I

   

see is that at 100 KSPS guarenteeing main() stores the sample in time problematic. I would

   

think about doing that in the ISR, which then requires you inc the i pointer for the array.

   


   

In general you might want to consider a DMA approach to memory to get the arrays filled.

   


   

Regards, Dana.

0 Likes
Anonymous
Not applicable

yeah,the interrupt functions in the files expect main .c always disappear after rebuilding the project.I adopt the your recommendations.It work well.Thanks Bob.And i also learn a lot  from your coding style.Thanks also to danadak,your suggests are also useful. 

0 Likes