Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 18 of 18

Thread: +-10 volts control signal

  1. #1
    Junior Member
    Join Date
    Jul 2015
    Posts
    13

    +-10 volts control signal

    I plan on controlling a proportional hydraulic valve with integrated electronics, it takes a +- 10 volts control voltage.
    can anyone give me a hint how I should generate that +-10V control voltage using a teensy 3.2.

    I thought of using an H-bridge but I'm not entirely sure if the valve electronics like to get 10 volts on the reference pin?

    thanks in advance!

  2. #2
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    991
    I'd use a op amp amplifier to provide gain and offset to the teensy DAC output. With a +/- 12V supply.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,452
    Yup. I've configure the DAC to use the 1.2V internal reference, and then use an opamp to scale 0-1.2V to -10 to +10V

  4. #4
    Junior Member
    Join Date
    Jul 2015
    Posts
    13
    Quote Originally Posted by PaulStoffregen View Post
    Yup. I've configure the DAC to use the 1.2V internal reference, and then use an opamp to scale 0-1.2V to -10 to +10V
    thanks a lot, I'm gonna do that. any recommendation for a suitable opamp?

  5. #5
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    991
    This ebay item might be useful:

    Negative Voltage Dual DC12V -12V Power Supply Module 5-12V to 12V

  6. #6
    Junior Member
    Join Date
    Jul 2015
    Posts
    13
    Quote Originally Posted by jonr View Post
    This ebay item might be useful:

    Negative Voltage Dual DC12V -12V Power Supply Module 5-12V to 12V
    I guess you forgot to provide a link?!

    Anyway I've got a TRACO DC/DC converter with dual output +/-15 Volts 12 - 36 Volts Vin. that should work perfectly with a dual supply opamp.

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,421
    Quote Originally Posted by PaulStoffregen View Post
    Yup. I've configure the DAC to use the 1.2V internal reference, and then use an opamp to scale 0-1.2V to -10 to +10V
    Using the analog code directly with : analogReference(EXTERNAL);

    Allows getting 3.3V range - is there a way, and a reason, to have the Audio code allow something similar?

    I took a T_3.6 to get sine waves out both DACs to have 'real' data to read from a T_4.x with ADC code and 1.2v was boring in IDE Plotter after getting it to work. So used direct write with the above for 3.3V.

  8. #8
    Junior Member
    Join Date
    Jul 2015
    Posts
    13
    Quote Originally Posted by defragster View Post
    Using the analog code directly with : analogReference(EXTERNAL);

    Allows getting 3.3V range - is there a way, and a reason, to have the Audio code allow something similar?

    I took a T_3.6 to get sine waves out both DACs to have 'real' data to read from a T_4.x with ADC code and 1.2v was boring in IDE Plotter after getting it to work. So used direct write with the above for 3.3V.
    Does that mean I can make use of the full 3V3 range on the DAC output?

  9. #9
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,421
    Quote Originally Posted by gueee View Post
    Does that mean I can make use of the full 3V3 range on the DAC output?
    It seems it can be done - reading the INFO below and then browsing the code:
    Code:
    #include <Audio.h>
    
    // GUItool: begin automatically generated code
    AudioSynthWaveformSine   sine2;          //xy=313.00000381469727,383.0000057220459
    AudioSynthWaveformSine   sine1;          //xy=315,250
    AudioOutputAnalogStereo  dacs1;          //xy=561,350
    AudioConnection          patchCord1(sine2, 0, dacs1, 1);
    AudioConnection          patchCord2(sine1, 0, dacs1, 0);
    // GUItool: end automatically generated code
    
    
    
    void setup() {
      Serial.begin(115200);
      AudioMemory(20);
      sine1.frequency(10);
      sine1.amplitude(10.0);
      sine2.frequency(5);
      sine2.amplitude(10.0);
      dacs1.analogReference(EXTERNAL);
    }
    
    void loop() {
    }
    This is the info : pjrc.com/teensy/gui/?info=AudioOutputAnalogStereo
    AudioOutputAnalogStereo
    Summary
    Transmit 12 bit stereo audio using Teensy 3.5 or 3.6 built-in digital to analog converters.

    Boards Supported
    Teensy 3.5
    Teensy 3.6
    Audio Connections
    Port Purpose
    In 0 Audio Channel (Left)
    In 1 Audio Channel (Right)
    Functions
    analogReference(ref);

    Configure output voltage range:
    INTERNAL selects 1.2 volt peak-to-peak output.
    EXTERNAL selects 3.3 volt peak-to-peak output.

    Hardware


    Signal range default is 0 to 1.2V

    The output voltage has DC level. Some applications require a DC-blocking capacitor. If unsure, a 10F is usually a safe value to use. If an aluminum or tantalum capacitor is used, the positive terminal should connect to Teensy's DAC pin.

    The DAC pin is used with the Prop Shield to drive speakers.

    Examples
    Notes
    The output rate is 44.1 kHz (no oversampling). Ultrasonic noise present if not filtered. This may not be an issue for many uses, but care should be used if amplified and driven to high power tweeters.

    When using 3.3V output, the power supply is used for the analog reference. Noise present on the 3.3V power can couple to the DAC output signal.

  10. #10
    Junior Member
    Join Date
    Jul 2015
    Posts
    13
    Quote Originally Posted by defragster View Post
    It seems it can be done - reading the INFO below and then browsing the code:
    is that applicable for the teensy 3.1/3.2 to your knowledge?
    I wonder if I have to make use of the audio lib, since it seems a bit overkill for simply outputting an analog DC signal?

  11. #11
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,421
    According to the Audio Gui { right PANE when the left PANE item is clicked } it is the same: pjrc.com/teensy/gui/?info=AudioOutputAnalog

    The above AUDIO code was replaced with this direct code that - for the simple case at hand worked perhaps better for the desire to have the two DACs at hand out of Phase:
    Code:
    // Simple DAC sine wave test on Teensy 3.1
    
    #define uSec_DELAY 200
    float phase = 0.0;
    const float twopi = 3.14159 * 2;
    elapsedMicros usec = 0;
    float val0, val1;
    
    void setup() {
      analogWriteResolution(12);
      analogReference(EXTERNAL);
      val0 = sinf(phase) * 2000.0 + 2050.0;
      val1 = sinf(twopi - phase) * 2000.0 + 2050.0;
    }
    
    void loop() {
      if (usec >= uSec_DELAY) {
        analogWrite(A21, (int)val0);
        analogWrite(A22, (int)val1);
        phase = phase + 0.02;
        if (phase >= twopi) phase -= twopi;   // if (phase >= twopi) phase = 0;  // errata noted below
        val0 = sinf(phase) * 2000.0 + 2050.0;
        val1 = sinf(twopi - phase) * 2000.0 + 2050.0;
        usec = usec - uSec_DELAY;
      }
    }
    Last edited by defragster; 06-08-2021 at 05:17 PM.

  12. #12
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,101
    Quote Originally Posted by gueee View Post
    thanks a lot, I'm gonna do that. any recommendation for a suitable opamp?
    One capable of being powered from +/-12V, and which can swing to within 2V of the rails. Precision might be important
    since you'll have a gain of 17 or so, each 1mV of input offset translates to 17mV of output offset. Most opamps can handle
    2k loads, many can handle 500 ohm loads - what is the impedance of the control circuit being driven?

  13. #13
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    991
    > if (phase >= twopi) phase = 0;

    I think this should be:

    > if (phase >= twopi) phase -= twopi;

  14. #14
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,421
    Quote Originally Posted by jonr View Post
    > if (phase >= twopi) phase = 0;

    I think this should be:

    > if (phase >= twopi) phase -= twopi;
    Code found from another post {by Paul} was edited to get that and it results in two waves?
    Click image for larger version. 

Name:	dualSine.jpg 
Views:	8 
Size:	57.6 KB 
ID:	25003

    T_3.6 dual DAC output read by T_4.0 ADC code and sampled out to IDE Plotter with these notes on T_4.0 display showing it is running both 0 to 3.3V and they SUM to 3.30 { 3.28 to 3.31 }:
    Code:
    	2 pins read 238582 times/sec at ms=2265499 [396=waitCnt 4512649=LpCnt]
    P#19: 1.62V <P#16: 1.68V <:: Sum=3.29
    
    	2 pins read 238583 times/sec at ms=2266499 [395=waitCnt 4512646=LpCnt]
    P#19: 2.79V <P#16: 0.51V <:: Sum=3.30
    
    	2 pins read 238189 times/sec at ms=2267499 [400=waitCnt 4505168=LpCnt]
    P#19: 3.27V <P#16: 0.04V <:: Sum=3.31

  15. #15
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    991
    But 2π isn't a multiple of .02 - so it has a small rounding glitch every time it hits 2π.

  16. #16
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,421
    Quote Originally Posted by jonr View Post
    But 2π isn't a multiple of .02 - so it has a small rounding glitch every time it hits 2π.
    Well that isn't cool. Made Changes

    Scanned the code wrong saw = -twopi instead of the -= twopi as written ...

  17. #17
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,452
    Opps, yeah, the way I wrote that code will indeed have a small phase error at the end of every cycle. It was meant to be only "a quick sanity check" to verify whether the DAC hardware was working.

    The audio library has much better waveform synthesis code, which is also far more efficient.

  18. #18
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,421
    Quote Originally Posted by PaulStoffregen View Post
    Opps, yeah, the way I wrote that code will indeed have a small phase error at the end of every cycle. It was meant to be only "a quick sanity check" to verify whether the DAC hardware was working.

    The audio library has much better waveform synthesis code, which is also far more efficient.
    @Paul : quick question? :: RE Audio code in post #9 - how can the two DAC's get sine out of phase as the p#11 sample above?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •