Problem with a software SPI, teensy interface BNC DAC pin 14

Status
Not open for further replies.

Bastiaan

Well-known member
Hello

I am trying to solve a software bug in my coding of the teensy3.2.

first hunch,
can I use the DAC on pin 14 simultaniously with the ADC analogRead A3, A4? or are they not seperated?
and if so How can I seperate them?

What I am trying to do, 2 buttons a tft screen and a teensy with a BNC driver opamp, is driven by a sequence of a staircase function 0...10V-->voltage_divider--->0...3.3V, which gives me different phases 0,1,2 on the screen, sofar so good.

if the 3 phase is on the screen a blue and a red button needs to be pressed and is checked with a simple if statement.

if pressed Red or Blue, the DAC on 14 gives out a specific voltage over a second bnc that is equal to -12V,0,12V from the opamp.

the voltage sticks on -12V for some reason

I have attached the code just in case.

sincerely yours

Bastiaan
 

Attachments

  • BP_25_07_2017.ino
    7.3 KB · Views: 89
This may or may not be your problem. If you enter this while loop, there is no way out and your program will hang here.

Code:
            int xblue = analogRead(A3);
            int xred = analogRead(A4);
           while (xblue >= 3000 && xred >= 3000)
            {
              buttonType = 0;
              buttonPressed = 1;
            }
 
Hi rcarr,

I changed this, attached the code, and discovered that the ADC and DAC are somehow connected and is not exiting the loop, is there a way to prevent the ADC Meddling with the DAC? from the PDF K20 MK20DX64VLH7 page 730 I cant see that it is meddling with the ADC.

if I use a seperate program to test the DAC on pin A14 I get a nice change in output voltage.

I will write a continous read program and see what the DAC A14 will do during the continious read.
 

Attachments

  • BP_25_07_2017.ino
    7.9 KB · Views: 81
I do not see in the new file where you fixed the infinite loop. You seem convinced there is nothing wrong with your program. I know sometimes it is difficult to find ones own mistake because you keep thinking in the same way. Many times I have thought it must be a compiler bug at fault when I can not see my error in my code. In my defense I have worked with some buggy compilers in the past.

So this line in your program:

Code:
         if (New_Data - Old_Data <= 400) // test if step occured
isn't this backwards. Shouldn't it be >= 400 ? Meaning the voltage is stepping up?

How are your switches wired? Do they produce 3.3 volts when pressed or do they produce 0.0 volts when pressed?
 
Hi rcarr,

the program in short: if the buttons A3, A4 are not pressed, do the loop forever.
The loop: yellow 0, red 1, Phase 2 Blue 2, Black screen, wait for press buttons A3,A4
if Pressed set the DAC on pin 14 to a certain value / high if red button is pressed, Low for blue.
restart Loop start ADC read A2.

go back to the beginning of the loop.
I measured that the DAC is taking over the voltage from the ADC which is not ackward but I think I have to switch off the ADC during phase 3.




the switches produce 3.3V
 
Perhaps you are just forgetting that all the DAC lines of code are commented out in this program?
Code:
//                              float Output_DAC=2090; 
//                               analogWrite(A14,int(Output_DAC));                        
//                               delay(100);
//                               Output_DAC=400; 
//                               analogWrite(A14,int(Output_DAC));
//                               delay(100);
//                               Output_DAC=2090; 
//                               analogWrite(A14,int(Output_DAC));                 
//                               delay(100);
 
works

first, yes I had to uncomment that in.

if you do a simple DAC sinewave or say to a simple DAC INO test file to tests it ouput / go to this value and stay there, it does this perfectly.

however if you use the ADC and the DAC at the same time, the voltage is not simular on its output,

what I am tryin to understand is does the ADC have any influence on the DAC? on its output during conversion?
something like a reference voltage?


sincerely yours

B
 

Attachments

  • BP_27_07_2017_Test.ino
    10.5 KB · Views: 79
what I am tryin to understand is does the ADC have any influence on the DAC? on its output during conversion?
something like a reference voltage?

Activity on the ADC can create a small amount of noise on the reference voltage, which can be reflected on the DAC output if it's configured to use the same reference.

But other than some high frequency noise, the DAC output should be independent of the ADC operation.

Of course, if you code updates the DAC output at different speeds depending on how much time other stuff in your program takes the execute, adding ADC or other non-ADC code could alter the timing, which might make the waveform look different. Especially if the time between DAC updates isn't consistent, you might get strange looking results.
 
Thanks Paul for your time and enlightening this.

Ill try and have a look at it and see if the program has a difference on the ADC and DAC.
 
Status
Not open for further replies.
Back
Top