DAC output with timer

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi everyone, I am using CY8C27443

   

My task is to output the DAC value in a period of time (seconds), to be more precise, I attach a picture below

   

I offset the voltage to 2.5V so in first 100s, the DAC value is 2.05V, after that it's changed to 2.2V and so on (with rate of change equal 1V/s). 

   

I implemented it using the DAC with a 8 bit timer. An interrupt is generated each 2ms, so I can get the 1s period (I attached my prj below). I update my DAC value for each phase. However the output didn't go like the picture but it was only true in the first phase (2.05V in 100s) then it went wrong. To be specific, it went up directly to 3.7V then went down to 2V, then it repeated (sorry the result was on the oscilloscope so I was unable to post it here). 

   

Could you please take a look at my project and tell me what went wrong, thank you very much!

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

Generally: Global variables which get changed in an interrupt-handler MUST be declared as "volatile" or accesses to them might get optimized-out depending on the compiler and the settings you use.

   

I cannot deduct from your (uncommented) program how you are setting the requred dac under which circumstances. To be honest: flag and flag1 are not rather meaningful variable names...

   

 

   

You wrote     while (10<flag1<=11)
 

   

when you mean if(flag1 == 11) it is better to write that down.

   

 

   

the fmod function with integer arguments will consume many MIPS better use the %-operator

   

 

   

I would suggest you to (at least for the test-phase) set the CPU speed to 12 or 24 MHz, 3 MHz can sometimes be too slow.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you are creating a complex waveform, or a periodic waveform,

   

or even a one shot waveform, consider using an interrupt driven

   

table approach. That would eliminate the jitter in sampling time you

   

incur in your approach, if that is of concern.

   

 

   

An ap note that may be of use - www.cypress.com/     AN2025

   

 

   

www.cypress.com/     AN2096

   

www.cypress.com/     AN74170

   

 

   

Also set Op-Amp Bias and A-Buff_Power in global properties to high

   

power to get full CM range at output pin.

   

 

   

Regards, Dana.

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

 Bob and danaa, thank you for your replies!

   

I changed my prj as your suggestions, however,the results are not true as expected. It only went well in the first ten seconds (2.05V), but after that it jumped directly to 3.6V (picture below) and went on at this value. 

   

   

To danaa: I also thinked of look up table but in the sine wave prj, it updated with each counter tick, however for my prj, it must update with both milisec and secs so I didn't get the idea to manage it. 

   

I also attached my prj with comments, please take a look again and give me some advice. Thanks alot!

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

I am missing the infinite loop that usually is used in embedded programming. Your code exits in main() and you do not know what will happen then.

   

The variavle named "value" (better name would be "DAC_Value") is declared as a global variable and only initialized once. I would at least initialize it in the routine where I use it or declare it as a local var to get the chance to call the routine twice or more often.

   

I would suggest you not to count up your value all the time, there are points within your program where you may assign a constant to it to generate the wanted voltage, so in case of mis-counting you get a defined voltage.

   

Why do you stop the DAC at the end? What voltage do you want at the end of the cycle? and what do you want to happen after one cycle is through?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Here is the modification I made to your program:

   

 

   

while (tick1s<=10)  //DAC output 2.05V if the time is below 10s, the analog output value is later offset by -2.5V

   

{

   

DAC9_1_WriteStall(value);

   

}

   

while  (tick1s==11)      //DAC output increase with rate of change 0.15V/s

   

{

   

if(tick2ms%16==0)

   

{

   

value +=1;

   

DAC9_1_WriteStall(value);

   

}

   

}

   

while(tick1s < 22)   //DAC output at 2.2V

   

{

   

DAC9_1_WriteStall(value);

   

}

   

    while(tick1s==22)   // DAC output increase to 3.1V with rate of change 1V/s

   

{

   

if(tick2ms%3==0)

   

{

   

value+=1;

   

DAC9_1_WriteStall(value);

   

}

   

}

   

while(tick1s<50)    //Keep the voltage at 3.1V

   

{

   

DAC9_1_WriteStall(value);

   

}

   

      //DAC9_1_Stop();

   

 

   

The program as stated should be functionnal, but in your case your problem is related to the interrupt. 

   

 

   

In the following line : if(tick2ms%16==0), your program have the time to do several pass before tick2ms get changed. Consequently this line: value+=1; will be executed more than once, so the variable "value" will be higher than expected.

   

 

   

Regards

0 Likes
Anonymous
Not applicable

Thank you guys for your replies!

   

To Bob: You're right, I have added the infinite loop and changed the DAC_value to local variables. I also assigned some constant DAC value to get the defined voltage and after that I found the errors in my project. As I said above, the initial value for my DAC is 2.05V, then it comes up to 2.2V and after some time it goes to 3.1V. Then it will be offset to -2.5V to get the value in the picture in my first post

   

To Eric: You got the point. The problem lies where I update the DAC value. Here is the modified code I get from Bob's and your suggestions

   
    void Timer_DAC(void)   
   
    {   
   
     int DAC_value_2_05V = 167;   
   
     int DAC_value_2_2V = 198;   
   
     int DAC_value_3_1V = 373;   
   
     while (tick1s<=10)  //DAC output 2.05V if the time is below 10s, the analog output value is later offset by -2.5V   
   
     {   
   
     DAC9_1_WriteStall(DAC_value_2_05V);   
   
     }   
   
     while (tick1s==11)      //DAC output increase with rate of change 0.15V/s   
   
     {        
   
     if(tick2ms%16==0)   
   
     {   
   
     DAC_value_2_05V +=1;   
   
     DAC9_1_WriteStall(DAC_value_2_05V);   
   
     }   
   
     }   
   
     while (tick1s<22)   //DAC output at 2.2V   
   
     {   
   
     DAC9_1_WriteStall(DAC_value_2_2V);   
   
     }   
   
     while (tick1s==22)   // DAC output increase to 3.1V with rate of change 1V/s   
   
     {        
   
     if(tick2ms%3==0)        
   
     {   
   
     DAC_value_2_2V+=1;   
   
     DAC9_1_WriteStall(DAC_value_2_2V);   
   
     }   
   
     }   
   
     while (tick1s<50)   
   
     {   
   
     DAC9_1_WriteStall(DAC_value_3_1V);   
   
     }   
   
     //DAC9_1_Stop();   
   
    }   
   
        
   
    the signal is from the middle of the screen to the right.    
   
    My idea is when tick1s equals 11 (at the second of 11), I will have tick2ms tick 500 times so for each time tick2ms equal 16, 32, 48,... to 500 (tick2ms%16==0) then the DAC_value will be updated. However it comes up so high (about 3.6V - DAC value around 450). After that I used constant DAC value and it went down as in the picture. The change occured at the time expected so I think the interrupt works well.    
   
    Do you guys have any idea why was it like this?    
0 Likes
Anonymous
Not applicable

To avoid this behaviour you could set a flag in your interrupt, execute the code once the flag is set then reset the flag. it will get set at the next interrupt and so on.

   

 

   

It could look somthing like this:

   

if(tick2ms%16==0 && flag2ms){

   

    flag2ms = 0;

   

    ...

   

}

   

 

   

Regards

0 Likes
Anonymous
Not applicable

 Thanks EricS, your idea is valuable to me!

   

I followed your suggestions and it seems to work out, however it still got some problems that I can't tell why it was like this. I have been trying all the morning but the results are the same. It seems that the counter in "if" function got double so the DAC value update got double too. I know this is going to work but I couldn't go to my expected results 😞

   

   

#pragma interrupt_handler Timer8_1_ISR

   

void Timer8_1_ISR(void)

   

{

   

flag2ms=1;

   

tick2ms++;

   

if (tick2ms == 500) //output period of timer is 2ms, so I set the interrupt to get 1s

   

{ tick2ms = 1;

   

tick1s++;

   

}

   

}

   

void Timer_DAC(void)

   

{

   

int DAC_value_2_05V = 167;

   

int DAC_value_2_2V = 198;

   

int DAC_value_3_1V = 373;

   

while (tick1s<=10)  //DAC output 2.05V if the time is below 10s, the analog output value is later offset by -2.5V

   

{

   

DAC9_1_WriteStall(DAC_value_2_05V);

   

}

   

while (tick1s==11)      //DAC output increase with rate of change 0.15V/s

   

{

   

if(tick2ms%16==0 && flag2ms)

   

{

   

flag2ms=0;

   

DAC_value_2_05V +=1;

   

}

   

DAC9_1_WriteStall(DAC_value_2_05V);

   

}

   

while (tick1s<22)   //DAC output at 2.2V

   

{

   

DAC9_1_WriteStall(DAC_value_2_2V);

   

}

   

while (tick1s==22)   // DAC output increase to 3.1V with rate of change 1V/s

   

{

   

if(tick2ms%3==0 && flag2ms)

   

{

   

flag2ms=0;

   

DAC_value_2_2V+=1;

   

}

   

DAC9_1_WriteStall(DAC_value_2_2V);

   

}

   

while (tick1s<50)

   

{

   

DAC9_1_WriteStall(DAC_value_3_1V);

   

}

   

//DAC9_1_Stop();

   

}

   

Please take a look and give me some advices. Thank you so much!

0 Likes
Anonymous
Not applicable

It may be easier if you upload the project here.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Why not consider a table driven approach. Say tsktable[ 5 ][ 3 ], first element in

   

table length of time for a specific part of waveform, second the begining V, third

   

end V, and based on timer value ramp or stay put the DAC outut. You could even

   

add a 4 elemnet to table, that is timer values to initiate next part of waveform. So you

   

just test in code timer value and current element of table. when equal you then implement

   

the table instructions, either ramp or stay put.

   

 

   

Then if start and end V same, do nothing for all but the first time sample. If end V >

   

start V ramp each timer sample the count increment to get to final V.

   

 

   

Just a thought, Dana,

   

 

   

 

   

 

   

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

 Here is my current project, please have a look!

   

Danaa: Thank you, I will think of your approach. In fact, I didn't know there is a table approach to this DAC, I only know of the array approach as in sine wave example. 

   

Regards, 

0 Likes
Anonymous
Not applicable

1. How do you get the 3 DAC values?

   

 

   

int DAC_value_2_05V = 167;

   

int DAC_value_2_2V = 198;

   

int DAC_value_3_1V = 373;

   

2. With 5V full swing and 512 steps, each step should be 9.77mV and you have 32 increments within 1 second, so it would be 0.3125 V. the change would then be 0.3125V/S which is what you are getting now

0 Likes
Anonymous
Not applicable

To my understanding, the DAC range and ADC range is determined by Ref Mux parameter in Global Resources. 

   

I chose Ref Mux equals to (Vdd/2)+/-Bandgap so the DAC range would be 1.2V to 3.8V with values from 0 to 511. That's how I get the DAC values for each voltage. 

   

If the full range swing is 5V then it will go as you say but the DAC range is 2.6V so it should be halved. 

   

Please correct me if I'm wrong. 

   

Regards, 

0 Likes
Anonymous
Not applicable

 In that case, your value should be correct.

   

How about toggle a output pin in the 2ms interrupt, and use a CRO to check if 

   

1. the timing is same every time and is 2ms

   

2. there should be 32 counts during the 11th seconds.

0 Likes
Anonymous
Not applicable

 Thanks H L, 

   

I tried as you told and toggle the LED every 2s, but the result is the LED toggle every 1s so I think that my timer has problem. However, when I measure the time elapsed for DAC value (under 10s, 11th second,...), it was true. 

   

I am so confused and couldn't tell what went wrong!

0 Likes
Anonymous
Not applicable

 I mean toggle an ouput in the 2ms interrupt routine, not using another 2s counter. use the CRO to measure if the toggle time is 2ms. you can try toggle when you increment the DAC value. then you should have 32 toggles within 1 second.

0 Likes
Anonymous
Not applicable

The 2ms interrupt routine also create one second period so I thouht that they would be the same. 

   

I will try it tormorrow, thank you H L!

0 Likes
Anonymous
Not applicable

 You can try in three steps.

   

1. create a main loop of incrementing a counter from 1 to 500 using a 2 ms delay. (DO NOT USE INTERRUPT)

   

   using the same operation to make a incremnt to the DAC every 16 counts and output to DAC.

   

   clear counter to 0 and DAC to lowest value when counter overflow.

   

   this way you would get a saw tooth wave, check for the lowest and highest value. After this you should know your DAC incrment and output is correct and the output voltage is correct.

   

 

   

2. Use the counter and 2 ms interrupt, in a mina loop, just check for the 2ms flag if the flag is set, clear the flag,  update a counter and also set a pin on the off. 

   

check the timing of the pulse and sure it is 2ms. 

   

If that works, you should know that your interrupt routine handling is correct

   

 

   

3, merge the two together to create the wayform using 2ms interrupt

   

If all works well, all this to your other parts of program that,

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

 Hi H L, 

   

thank you very much for your help. Sorry I wasn't able to work on my prj last week due to my assignment deadline 😞 

   

Luckily, I managed to create the expected waveform. It's a little tricky as I realized that the timer period is half and the rate of DAC change is doubled so I just double the timer count, I know that's it's bad as I didn't get things true and I'm going to come back for it. The problem now is the DAC output doesn't go down to the initial value after a loop but it keeps running at the final one.

   

However, I have another question, I need an ADC on another pin and then send it via UART, I tried to put it in the main loop but it didn't run, when I put it in the DAC funtion it worked (maybe due to the while loop in the DAC) but after each period it got the break and reset the ADC value (I need it continuously). 

   

I attached my prj below, could you give me some advice where to put my ADC function, thank you!

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

This might be of help -

   

 

   

www.cypress.com/

   

 

   

This should reflect the changes shown, you did not have the string terminated.

   

 

       

char buffer[ 5 ];

   

      void send_ADC(int Data)

   

      {

   

            buffer[0] = Data/1000+ '0';

   

            buffer[1] = (Data%1000)/100 + '0';

   

            buffer[2] = ((Data%100)/10) + '0';

   

            buffer[3] = ((Data%100)%10) + '0';

   

            buffer[ 4 ] = NULL;

   

            UART_1_PutString(buffer);

           

              }

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Thank you danaaknight, your link and your modification is helpful for me. 

   

I solved the problem by putting the ADC function into the DAC_Timer function like this: 

   

void Timer_DAC(void)

   

{

   

int result;

   

int DAC_value_2_05V = 167;

   

int DAC_value_2_2V = 198;

   

int DAC_value_3_1V = 373;

   

while (tick1s<=10)  //DAC output 2.05V if the time is below 10s, the analog output value is later offset by -2.5V

   

{

   

DAC9_1_WriteStall(DAC_value_2_05V);

   

result = readadc();

   

send_ADC(result);

   

}

   

while (tick1s==11)      //DAC output increase with rate of change 0.15V/s

   

{

   

if(tick2ms%32==0 && flag2ms)

   

{

   

flag2ms=0;

   

DAC_value_2_05V +=1;

   

}

   

DAC9_1_WriteStall(DAC_value_2_05V);

   

result = readadc();

   

send_ADC(result);

   

}

   

while (tick1s<22)   //DAC output at 2.2V

   

{

   

DAC9_1_WriteStall(DAC_value_2_2V);

   

result = readadc();

   

send_ADC(result);

   

}

   

while (tick1s==22)   // DAC output increase to 3.1V with rate of change 1V/s

   

{

   

if(tick2ms%6==0 && flag2ms)

   

{

   

flag2ms=0;

   

DAC_value_2_2V+=1;

   

}

   

DAC9_1_WriteStall(DAC_value_2_2V);

   

}

   

while (tick1s<50)

   

{

   

DAC9_1_WriteStall(DAC_value_3_1V);

   

result = readadc();

   

send_ADC(result);

   

}

   

 

   

//DAC9_1_Stop();

   

}

   

If the read ADC function is outside the while loop but in the main loop, the ADC only returns one result and stops. 

   

I am using Terminal to receive the ADC result and it doesn't give me as much result as I want. Do you think it's due to sampling rate or the capabilities of Terminal? I need the results to graph so I want as many points as possible. 

   

One more thing, when building the prj, I got so many warning about "calling an undeclared function...", it points to the readadc() and send_ADC(), may I have any problem with that? 

0 Likes
Anonymous
Not applicable

 Thank guys for your help!

   

I moved the other function above and don't see the warning anymore. About the sample rate, I calculated based on the equation in the datasheet and found out that the result was true. I set VC2 as the dataclock so the sample rate is only 4 samples/sec, however, when I set the dataclock to VC1 to get 60 samples/second, I didn't receive any data in the terminal. 

   

I set baud rate at 9600 and tried at 19200 but it didn't work. Do you guys have any idea why is that and what should I do to fix the problem?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You might bring the data clk out to a pin just to confim, otherwise

   

post project again so we can look at all settings.

   

 

   

Regards, Dana.

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

 Here is my current version of my prj. As from the function in the datasheet, sample rate = DataClock/[256*(2^bits-6 + 1)], with the dataclock set to VC1 = 24*10^6/12 = 2 MHz, sample rate = 2*10^6/256*129 = 60.56 samples/second. 

   

The Baudrate is set from clock of TX module equals VC1/13 = 153,846 Hz so the Baud rate should be 1/8 = 19200. 

   

Please look at my prj and give me some advice, thank you!

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I show in global properties you have CPU clck set to 3 Mhz, Sysclk/8,

   

should that be 24 Mhz, Sysclk/1 ?

   

 

   

Regards, Dana.

   

 

   

Block Diagram of AN32200

0 Likes
Anonymous
Not applicable

 Thank you for your replies, dana!

   

When I use a LabView program instead of Terminal, I was able to fetch data from the UART, but I'm not sure whether I got exact 60 samples/second. I will change the CPU clock to 24MHz for higher speed as you told, but could you suggest me a kind of test to see how many ADC samples I got in 1 second?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

The PSOC clock accuracy from datasheet is 23.4 Mhz to 24.6 Mhz.

   

 

   

If you are trying to get an AC line synchronous sampling rate then how many samples /

   

60 Hz cycle do you want ? If 1 sample per AC line cycle then feed a pin with a conditioned

   

signal from AC line and use that in interrupt to read ADC. If you need to read peak ac line

   

voltage this (old but useful) reference might help. You would use the SC block component,

   

see below. www.cypress.com/

   

 

   

If more than 1 sample per ac cycle then create a routine using ac line interrupt and count

   

the number of times you get adc result. If low bump up its clock in code with register writes.

   

Clock could be derived from PWM and you change its period slightly. If too many conversions

   

you lower ADC clock.

   

 

   

Regards, Dana.

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

 Thanks danaa for your help!

   

I solved the problem by using my Labview program, the number of samples doesn't matter anymore because I can control the display rate with the loop.

   

However, another problem appeared, when I put the readadc() and send_ADC() function in the while loop of putting DAC, the DAC function only show the fixed value, it didn't show the ramp up as before anymore:

   

   

As you can see, this is the image I took with my Labview chart, at the certain time, it changes the value and didn't show the ramp I expected. I tried removing the ADC function and the ramp appears again. I am so confused and don't understand why. Could you give me some advice on this problem? I attached my prj below.

   

Again, thanks for your help during the past time. I am so close to the result right now. 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

When you call main1() in main(), you then execute Timer_DAC() once,

   

then sit in an infinite while loop. Is that intended ?

   

 

   

The compiler may be doing the right thing with this                                                 if(tick2ms%32==0 && flag2ms)
(order of precedence) but I think for safety, readability you should type                 if( ( tick2ms%32 == 0 ) && flag2ms)
 

   

 I cant remember that table for the life of me.

   

 

   

Regards, Dana.

   

 

   

Order of precedence -

   

 

   

0 Likes
Anonymous
Not applicable

 In your code you use a lot of while(){} this kind of construct limits the numbers of things you MCU may do. It would be better to use the "if" construct and use a while loop in the main. 

   

In your read ADC rather than wait for the value to be ready, you check for the presence of the flag and read it only if it's ready. If not you continue.

   

 

   

As for the writestall, you write to the DAC every single loop. It would be better to write it on change only. In one of my project i was using this approach and it caused some instability at the pin output.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I noticed Dac9_2 is always written with a value of 255, seems

   

like you would only have to do that once based on your code.

   

What is DAC9_2 used for, seems like its irrrelevant ?

   

 

   

One other issue is the DAC9 has the potential to glitch. If thats a problem

   

you could filter its output with R-C low pass and pass back thru PGA to buffer.

   

Or if settling time not a big issue use a PWM followed by a LPF to create a DAC.

   

In fact you can get more resolution that the DAC9 offers. Just a thought.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Thanks guys for your replies!

   

danaa: my intention is to repeat the DAC() as control but I haven't come to that part. And thanks for your fix to my code. Beside, I used DAC9_2 to output 2.5V as the reference voltage for op amp and in amp, do you think it's ok to do that? In my prj, glitch isn't a problem so I think that's ok to use DAC 🙂 if further requirement needs precise DAC, I will try your suggestion. 

   

Erics: I tried with if before but it didn't run as I expected. and your sentence "In your read ADC rather than wait for the value to be ready, you check for the presence of the flag and read it only if it's ready. If not you continue.", could your explain it more for me? And for the Writestall in each loop, I need to have the output DAC value as in the graph I posted before so I have to put it in each loop as each loop is a period of time. Is that what you meant or I have misunderstood?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Use of DAC as reference OK, but maybe a little more noisey so

   

you might want to filter / bypass that. Note if you do a LPF arrangement

   

might be best to decouple C from buffer output, which could reduce

   

phase margin in output buffer.

   

 

   

The ouput buffer specs rated at 100 pF load, and 100 pF would not really

   

be enough to impact noise. So I suspect if you wanted to use .1 uF or

   

similiar to filter, that would significantly impact pahse margin.

   

 

   

Regards, Dana.

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

 I modified your project to reflect the changes I suggest you 

   

 

   

Regards

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

If you do the bypass a quick check of phase margin is

   

to use a pulsed load and look at time domain response.

   

 

   

Attached is an article that might be useful.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 Thank you so much Erics and danaa!

   

Sorry for the late reply, I was pretty busy lately and didn't have much time to work on the prj continuously. 

   

danaa: thanks for your information, I have read your document and understand what you mean. Before that I only know to use the decoupling cap at the power supply. 

   

 

   

Erics: thanks for your modification, it really works! now the DAC gives me the right signal form I want and also the value to increase the DAC step is back to normal, I really appreciate that but may you give me some kind of explaination so I could understand more thoroughly?

   

 

   

One more problem, now maybe the sampling rate OR the UART module in the prj has gone wrong. I have tested the LabView software with my previous version of prj and it works well. The variables of each module in two prj are the same, only the way to sample the data is change. I think there is some problem with that but don't know why because as you said, we don't wait for the flag but check for its presence and read it if it's ready (immediately???). As such, the transfer rate should be the same, but now the data displayed on the same LabView program was delayed by about 20 seconds, I mean I have tested it with the potentiometer on the board, the change on the graph appears after I change the potentiometer about 20 seconds, that's pretty strange. I have also change the sampling rate of the graph to display data but it doesn't change much. Do you have idea on that? 

   

 

   

Update: I tested with the Terminal and the data received changed immediately, but I still don't know why the LV program doesn't display it right. 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Post the project archive again, I get errors delay.h file missing,

   

and others....

   

 

   

    

   

          

   

“File”                                                           Designer

   

“Archive Project”

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

I don't have a clear explanation as to why it works perfectly now with the modification I gave you. However the Writestall function description says that it will stall the CPU if necessary so that may be a clue to investigate. The component datasheet says that it may stall the cpu until the begenning of phase1. If the CPU is stalled maybe it will alter your UART transfer.

   

 

   

Regards.

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

Thanks you guys for your replies!

   

To danaa: I got the same error, but in fact now we can remove the delay function because it's no need anymore. One more error is that DAC_value_2_05V value in the main1() so I put another value outside. I attached my archive below

   

 

   

To Erics: I don't think that's the problem because I use WriteStall with the previous prj version and it still worked out. However, I tried changing the WriteStall to WriteBlind but it didn't change anything. Now the thing concerns me is that the updated value in Terminal is fine while the value update in LV program is wrong (but the program works fine with the version before your modfication).

   

Update: I think that the problem now lies in the sampling rate of ADC because my program based on the number of sample received to display data on graph, before my sampling rate is about 60 samples/ second so I set the update rate in the program to 17msec, the data display on graph get updated almost immediately. Now the number of samples per second has changed so that update rate doesn't work anymore.

0 Likes