Shop OBEX P1 Docs P2 Docs Learn Events
Powering the prop from an automotive 12v source. — Parallax Forums

Powering the prop from an automotive 12v source.

eagletalontimeagletalontim Posts: 1,399
edited 2013-03-14 20:32 in Propeller 1
I am in the process of redesigning the power circuit on my project and am needing some advice. Currently, I am using the Prop Proto Board which has the 5V and 3.3V linear regulators built on it. I know that the 5V regulator cannot handle direct input from the vehicle (~14.2V) so I added an LM317 adjustable regulator before the Prop board to drop the voltage down to ~9V. I have also had to add a heat sink to the LM317 since it does get warm rather quickly. What I am looking to accomplish is to have a simple circuit that will accept the 14.2V from the vehicle and output 5V and 3.3V with little to no heat.

What I have found in my searching is the possibility of using a "drop in" switching regulator for the 5V rail and then an LDO regulator for the 3.3V rail. This method seems quite pricey. My other circuit which does the same thing as the current project I am working on but uses the SX28, has a standard 7805 linear regulator, has no heat issues and connects directly to the vehicle's power. I am limited on space on the PCB I am designing so the power circuit cannot have a bunch of parts. Any recommendations or components that could put me in the right direction?
«1

Comments

  • RaymanRayman Posts: 14,665
    edited 2013-03-10 16:22
    We've got a bunch of these USB power gizmos that plug into a cigarette lighter in a car.
    My first thought would be to use that or the innards of one.
    I imagine they are cheap...

    Another idea is to use these murata switching regulators:
    http://www.murata-ps.com/data/power/oki-78sr.pdf
  • Mike GreenMike Green Posts: 23,101
    edited 2013-03-10 16:29
    The issue with the linear regulators (LM317, 7805, etc.) is that the amount of heat they have to dissipate depends directly on the amount of current they have to supply and the voltage drop across the regulator. With a vehicle supply (~14.2V), the voltage drop to 5V is roughly 9V. These regulators have an upper limit of around 1A typically for the the amount of current they will supply. That's 9V x 1A = 9W of heat that has to be dissipated. If your circuit draws less current, that's less heat ... simple. The only way around this is to use a switching regulator. You can design and build your own or buy one ready made from someone. They're relatively pricey because they have several components on them. I've used Dimension Engineering's devices and they seem well made and a reasonable price for what you get. Here's a 5V fixed 1A regulator that can handle an input up to about 35V. They have higher current models.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-10 16:41
    So if I can locate a switching regulator that has a fixed output of 5V, then I should be able to use a standard linear 3.3V regulator correct? I am trying to keep all my other components through Jameco since I am purchasing everything else through them. It saves on shipping costs :) I have never used a switching regulator so it would be new to me for sure. From what I understand, a switching regulator can affect an ADC circuit which I am using so I need to stay with a linear 3.3V regulator to reduce noise the ADC may pick up.
  • kwinnkwinn Posts: 8,697
    edited 2013-03-10 17:33
    So if I can locate a switching regulator that has a fixed output of 5V, then I should be able to use a standard linear 3.3V regulator correct?

    Correct.
    I am trying to keep all my other components through Jameco since I am purchasing everything else through them. It saves on shipping costs :) I have never used a switching regulator so it would be new to me for sure.

    Keep in mind that a switching regulator chip is not the same as a 3 terminal regulator chip. It needs to have the correct components and proper board layout to work. There are 3 terminal switching regulator modules available that are a drop in replacement for a linear 3 terminal regulator, and this is the simplest way to go.
    From what I understand, a switching regulator can affect an ADC circuit which I am using so I need to stay with a linear 3.3V regulator to reduce noise the ADC may pick up.

    This is true. The high frequency switching produces noise that can affect linear circuits, and ADC's have some linear circuits that can be affected.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-10 17:48
    Is there a specific board layout to use for designing a switching regulator circuit? I did not see any specific ones. I figure to keep the traces large enough to handle the current and keep the external components close to the regulator to avoid any possible noise issues.

    Here is the switching regulator I am looking at for my project. https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_192381_-1 I don't think I need 3A, but I would like to have room to expand on my circuit for future use. The most power hungry device I have right now is the Parallax 2x16 1 wire serial display with backlight. The backlight is what causes all the heat in my circuit so I am limited to what else I can add in the future with my current power setup.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-10 19:43
    Wow, that was a bunch of info :) I understand a little better about switching regulators, but now I am worried about the ADC that I am using. I am not using a chip for the ADC conversion as I was trying to save some money on the original design. With ADC chips, they require a reference voltage which in my case would have to be 3.3V if I go with a Switching regulator for the 5V rail, and an LDO regulator for the 3.3V rail. I am currently using the ADC.spin which uses resistors and ceramic caps. If using the LDO regulator, would there be an issue with noise on the ADC and if so, would using an ADC IC be better? The input voltage the ADC is sampling is a max of 5.5V. I am not sure if it would work or not, but using a voltage divider circuit to drop the input voltage lower before it reaches the ADC chip would allow me to still run the ADC chip from the 3.3V rail which would be "outside" the noisy switching regulator correct?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-10 21:03
    Wow, that was a bunch of info :) I understand a little better about switching regulators, but now I am worried about the ADC that I am using. I am not using a chip for the ADC conversion as I was trying to save some money on the original design. With ADC chips, they require a reference voltage which in my case would have to be 3.3V if I go with a Switching regulator for the 5V rail, and an LDO regulator for the 3.3V rail. I am currently using the ADC.spin which uses resistors and ceramic caps. If using the LDO regulator, would there be an issue with noise on the ADC and if so, would using an ADC IC be better? The input voltage the ADC is sampling is a max of 5.5V. I am not sure if it would work or not, but using a voltage divider circuit to drop the input voltage lower before it reaches the ADC chip would allow me to still run the ADC chip from the 3.3V rail which would be "outside" the noisy switching regulator correct?

    Grrrhh, I just lost a long reply, here's the short version...

    Use these cheap switchers which replace 3 terminal linear regulators.
    Use suitable caps with the 3.3V LDO regulator.
    Use an ADC with a 2.5V reference (built-in) or external) or use a cheap micro if you can which is what I do (cheaper and better)
    Use a series diode and resistor (and opt. choke) from the +12V to the regulator along with a 1,000uf or greater cap on the regulator input.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-10 21:38
    What is the purpose of the series resistor coming from the vehicle power source into the regulator?

    I am also trying to find an ADC chip that may work for what I need, but I have 1 shot at this and am worried I will get the wrong one. Every part I am using, I am pulling the datasheet for and designing the PCB to use that one part. I have not used an ADC chip before so that is also another learning experience for me :) The board I am designing uses mostly SMD components to help save space so there is very little room for error.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-10 21:53
    What is the purpose of the series resistor coming from the vehicle power source into the regulator?

    I am also trying to find an ADC chip that may work for what I need, but I have 1 shot at this and am worried I will get the wrong one. Every part I am using, I am pulling the datasheet for and designing the PCB to use that one part. I have not used an ADC chip before so that is also another learning experience for me :) The board I am designing uses mostly SMD components to help save space so there is very little room for error.

    The resistor needs to be low enough that it does not cause too much of a voltage drop at maximum load but also high enough to help filter out some of the surges and spikes. This is where a small choke can help too but the resistor can't hurt and costs a cent or less. BTW, it also becomes the fuse just in case as a car battery can make a lot of smoke.

    As for the ADC it's best to know what you are measuring and what you want to do.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-03-10 22:05
    The series resistor is part of the filtering for the vehicle power. Vehicles are very very noisy with sometimes large spikes. Anything you can do to smooth these out is helpful. A series choke is a good idea (not necessarily on the board). Look at what's available for these chokes for automotive use.

    Breadboard your circuitry before building a prototype. There'll be some parts that won't work the same or won't work as fast because of the longer connections and higher capacitance, but it's better than not doing it.

    If you want the ADC to handle 5V for its input range, you'll need a 5V reference voltage. With adequate filtering, you could use the output of a 5V switching regulator for this. You could also use an adjustable switching regulator set for 6V or 6.5V followed by a linear 5V LDO regulator, then a 3.3V LDO regulator and run the ADC's reference from the filtered 5V reference. It all depends on how accurate you want it and how sensitive you can tolerate it to be to noise. An ADC with a built-in 5V reference may be the simplest. For high resolution (12-bit), you will likely need a low noise external 5V reference.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-10 22:23
    Right now, I don't think anything other than 8 bit would be necessary since I am just reading the vehicle throttle position sensor which is basically a potentiometer. The output of the TPS is right around 5.02V when the throttle is at full position. All I need for the Prop to see is numbers since I use a math formula to calculate 0% to 100% based on the ADC output from the ADC.spin.

    Here is the code I use to calculate the throttle:
    PUB ReadThrottle | thr, lt, ht, athr
      lt := 149                              ' Set Low throttle ADC return
      ht := 545                              ' Set High Throttle ADC return
      thr := adcsample / 100                 ' Filter lower number that jump alot
      if thr > ht                            ' Prevent higher than 100%
        thr := ht
      if thr < lt                            ' Prevent lower than 0%
        thr := lt
      thr := ht - thr                        ' Begin calculating percentage
      athr := ht - lt
      thr := thr * 100
      thr := thr / athr
      throttle := 100 - thr
      'throttle := adcsample / 100            ' Un-null for testing throttle range
      return
    

    I am also thinking of use another ADC circuit to read a pot that will allow the user to adjust a setting on the fly. This would allow me to use less pins instead of using a rotary switch. There should not be any external noise for this circuit as it would all be powered from the internal regulators.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-10 22:35
    Right now, I don't think anything other than 8 bit would be necessary since I am just reading the vehicle throttle position sensor which is basically a potentiometer. The output of the TPS is right around 5.02V when the throttle is at full position. All I need for the Prop to see is numbers since I use a math formula to calculate 0% to 100% based on the ADC output from the ADC.spin.

    Here is the code I use to calculate the throttle:
    PUB ReadThrottle | thr, lt, ht, athr
      lt := 149                              ' Set Low throttle ADC return
      ht := 545                              ' Set High Throttle ADC return
      thr := adcsample / 100                 ' Filter lower number that jump alot
      if thr > ht                            ' Prevent higher than 100%
        thr := ht
      if thr < lt                            ' Prevent lower than 0%
        thr := lt
      thr := ht - thr                        ' Begin calculating percentage
      athr := ht - lt
      thr := thr * 100
      thr := thr / athr
      throttle := 100 - thr
      'throttle := adcsample / 100            ' Un-null for testing throttle range
      return
    

    I am also thinking of use another ADC circuit to read a pot that will allow the user to adjust a setting on the fly. This would allow me to use less pins instead of using a rotary switch. There should not be any external noise for this circuit as it would all be powered from the internal regulators.

    For something this basic I might even consider a cheap comparator and RC DAC to measure the input voltage. But rather than the comparator just use a dual opamp such as the LM358 and have one of them boost the 3.3V DAC voltage and the other opamp can be the comparator (it doesn't need to be fast). If you need a circuit I will draw one up for you. Total cost of parts <$0.5

    I dislike using pots for any adjustments so consider using a single button input to ramp up through (and wraparound) the values you are after perhaps.

    P.S. The reason for a 2.5V reference is that the ADC doesn't need to have a reference of the same voltage range you are measuring as you simply divide down the input much like a cheap multimeter measures hundreds of volts.
  • Hal AlbachHal Albach Posts: 747
    edited 2013-03-11 08:40
    Here is a discussion at 8052.com regarding building a power supply to be used in an automotive environment.
    http://www.8052.com/forum/read/43807

    Hal
  • JasonDorieJasonDorie Posts: 1,930
    edited 2013-03-11 12:45
    These may or may not be appropriate, but they're cheap, and will handle well above the 14v you're working with: http://www.pololu.com/catalog/product/2098
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-11 21:49
    Ok, here is a schematic that I have assembled from 2 different parts that I think may work for my application. Please let me know if I am missing something or if something will not work properly. I am tempted to order the parts in this schematic and give it a test to see what kind of noise I get using my oscilloscope. ADC circuits are still new to me and I am learning how "external noise" could affect the readings.

    Here are the 2 regulators I am looking at :

    5V switching regulator : https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_245569_-1
    3.3V LDO linear regulator : https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_192524_-1
    1000 x 585 - 47K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-11 22:05
    Ok, here is a schematic that I have assembled from 2 different parts that I think may work for my application. Please let me know if I am missing something or if something will not work properly. I am tempted to order the parts in this schematic and give it a test to see what kind of noise I get using my oscilloscope. ADC circuits are still new to me and I am learning how "external noise" could affect the readings.

    Here are the 2 regulators I am looking at :

    5V switching regulator : https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_245569_-1
    3.3V LDO linear regulator : https://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_192524_-1

    You really need a proper PCB for a switching regulator and that's why I mentioned the switching regulators from Digikey and at $3.65 for one off they are really cheap. The 1k resistor value is way too high, you need to know what your maximum current draw is on the regulator input side as it will be around half that of the current draw on the 5V supply. Then calculate the resistor value as R=V/I but the trouble with that simple formula is that the current will increase because the regulator will be working off a lower voltage after the resistor. As a rule of thumb just use a 4R7 but make sure you use a diode in series with it too.

    The 33uf is no good either unless it's a low ESR type, you want quality not quantity, so just use a 10uf tantalum and a 0.1uf in parallel. In your switcher circuit. You had 1,000uf after the switcher and 100uf before it but I would be inclined to put the 1,000uf on the input and up to 470uf on the output but I really don't think the 2576 is the way to go.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-12 16:32
    The regulator from digikey you posted only outputs 500ma and I am not sure this is enough to power everything that will eventually be added to the circuit board. As of right now, besides the normal Prop circuitry, there is a 7 segment LED display which is run from the Prop pins with 470 ohm resistors, 2 Mosfet chips activated from a prop pin which power the positive side of a solenoid (Negative is naturally grounded), and a Parallax 2x16 backlit serial display. I am still working on finding an 8 bit ADC chip that will work for a 5V analog input and possibly running either a 555 timer or an op-amp as a schmitt trigger / filter for 2 square wave signals that are from the vehicle's stock sensors. I need to figure out the power supply issues before moving on to the ADC since the power could affect the ADC readings.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-12 16:51
    The regulator from digikey you posted only outputs 500ma and I am not sure this is enough to power everything that will eventually be added to the circuit board. As of right now, besides the normal Prop circuitry, there is a 7 segment LED display which is run from the Prop pins with 470 ohm resistors, 2 Mosfet chips activated from a prop pin which power the positive side of a solenoid (Negative is naturally grounded), and a Parallax 2x16 backlit serial display. I am still working on finding an 8 bit ADC chip that will work for a 5V analog input and possibly running either a 555 timer or an op-amp as a schmitt trigger / filter for 2 square wave signals that are from the vehicle's stock sensors. I need to figure out the power supply issues before moving on to the ADC since the power could affect the ADC readings.

    That regulator is just one of many but illustrates how simple, small, and cheap switching regulator modules have become although I'm sure 500ma is more than enough. For one, the solenoid is not powered from 5V anyway, Two, the LED display with those resistor values will be providing around 3ma per segment which is 24ma tops. Three, the backlight of the display will be around 100ma, Four, you can allow around 100ma for the Prop and circuitry (MOSFETs do not draw any static drive current). That brings it to under 250ma so we have 100% head-room.

    For a simple potentiometer reading you don't need speed or much resolution so either a simple I2C bus 8-bit ADC will do as you can run this at 5V or alternatively the dual opamp is more than adequate and you can learn a thing or two about ADCs.

    BTW, I design for 24V automotive systems as well and the tips I gave you are more than adequate for what you require.

    Check back on this message soon and I will have some part numbers.

    Since you are doing SMD I thought I'd just keep it simple and look for standard 8-pin SOIC packs and so I found a 16-bit I2C ADC with internal reference, the MCP3426 for $2.84 1-off This is way overkill for reading a pot but it's your decision. The 2.048V reference means you use a simple resistive divider on the input and the values can be convenient values as you have enough usable resolution to do a simple multiply and divide to convert the units.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-03-12 17:13
    BTW, I design for 24V automotive systems as well and the tips I gave you are more than adequate for what you require.

    Peter's tips are very helpful.

    So in summary, just to check (and partly because I might be building the same thing). Assume 1 amp max:
    1) diode - eg 1N4001
    2) Choke - presumably 1 amp so not one of those RF chokes. How many uH?
    3) Resistor. 4R7, wire wound, 5 or 10 watts?
    4) Capacitor, 1000uF, 25V (16V might be too low)
    5) Then regulator, either linear or switching.

    Does the order of components 1,2,3 matter?
    Should we add a fuse?
    Aluminium case, earthed?
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-12 17:40
    I have found a few ADC chips on Jameco since I have actually found jameco to be quite a bit cheaper than Digikey on many parts I commonly use, but I am not quite sure they will work for what I am trying to do. I did think about the voltage divider into the input, but in my other post, I thought I read that using an ADC with an internal power reference would be better? Maybe I read that wrong. All I need to read is a simple number range from an ADC based on voltage that is anywhere from 0.71V to a max of 5.5V. I have a math conversion function that reads the current ADC function I am using (ADC.spin) which is a 3 digit number. There is a low value setting, and a high value setting which is hard programmed into the function. The input to the ADC determines the percentage between the low or high setting which is used in another function.

    Back to the switching regulator....

    For a "spike protection" resistor you say a 4R7 is what I should use. I have a BUNCH of SMD resistors that I got in a combo pack and I do see a 4R7 which is a 4.7K right? All the ones that I have are 1/2 watt or 1/4 watt which is too low for the incoming power to the regulator so I would need to go with a larger watt resistor, possibly a wire wound correct?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-12 18:04
    Dr_Acula wrote: »
    Peter's tips are very helpful.

    So in summary, just to check (and partly because I might be building the same thing). Assume 1 amp max:
    1) diode - eg 1N4001
    2) Choke - presumably 1 amp so not one of those RF chokes. How many uH?
    3) Resistor. 4R7, wire wound, 5 or 10 watts?
    4) Capacitor, 1000uF, 25V (16V might be too low)
    5) Then regulator, either linear or switching.

    Does the order of components 1,2,3 matter?
    Should we add a fuse?
    Aluminium case, earthed?

    The standard 1N4004 is more than adequate considering that the 12V current will be about half of the 5V current and it's main task is not really for reverse protection but to isolate the input capacitors from "draining back" during cranking.. As for the choke that's only an optional extra but I have never needed to use it but it would be mainly for the high frequencies so I would have to have a look at a suitable one if it were used. The resistor provides that little bit of extra filtering due to the RC time constant but it's also an embedded fuse in the case of a catastrophic failure as even small lead-acid batteries can cause wiring to catch fire in a flash. This should just be your standard thick film but as a suggestion you can place two 400mW 10R in parallel (that's 10 ohms as the R is the decimal point and the shortform for ohms) which should fail nicely under overload. Sometimes I use a through-hole resistor and mount it off the board a little to prevent the PCB from being charred. There's a lot of material to consider if it is compliant to a standard.

    Generally I avoid user replacable fuses as they are problematic and undesirable for a few reasons. For light loads such as powering control logic I don't bother except maybe allow for the resistor fuse but in the case of heavy loads such as motors I use polyfuses that are rated much higher than the normal load (otherwise they become a problem). If I get a motor stall and for some reason the control system doesn't shut it down then the polyfuse will trip and do it's job nicely. Turn off the power and a few seconds later it's ready to go again.

    One of the biggest faults in ECUs and even domestic gadgets is the humble electrolytic capacitor. Too many times they dry out or burst open and for the sake of a few cents the whole unit is junked or "exchanged" by all-too-knowing repair establishments. BTW, just open your failing LCD monitor or ECU and visually inspect the electrolytics, especially those on the power input side or around the switching regulators and you might see signs of bursting or leaked electrolyte due to overheating. I've resurrected stacks of equipment simply by doing this. The point here is to give thought to the importance of that particular electrolytic that you are using and where and how it is being used. So, yes, choose a voltage rating that's certainly high enough and also consider the high temperature versions. Heating is not just due to cabinet temperature but also ripple current which is another parameter to consider along with ESR (it can get involved).

    When it comes to switching regulators I see the LM2576 and their ilk rear their dreaded heads time and time again. If you know how I feel about LM386 audio amplifiers then you might get an inkling about how I feel about far out-dated TO220 switching regulators. There are far far better ways of switching and the chips these days are more efficient and tiny while all the other components are small and cheap too (don't forget the other components). That said, there are those modules that are really cheap and just work because if you don't lay out the pcb correctly for your own switch-mode design then you will have problems.

    It just makes so much sense to use the switching regulator since the input supply is much higher than the logic supply and then to just use linear regulators to provide a nice clean ripple free logic supply. There's a lot of choice out there for linear regulators but I favour LDO types that are stable with a 1uf X7R ceramic.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-03-12 18:05
    and I do see a 4R7 which is a 4.7K right?

    4R7 is 4.7ohms. 4K7 is 4700 ohms.

    And yes, would need a larger wattage. Worst case, 1A so W=I^2R so that is 1x1x4.7 = 4.7 watts. I think your max was a few hundred mA but still best to have a reserve.

    Addit: cross post with Peter. Reading all the good advice...
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-12 18:15
    I have found a few ADC chips on Jameco since I have actually found jameco to be quite a bit cheaper than Digikey on many parts I commonly use, but I am not quite sure they will work for what I am trying to do. I did think about the voltage divider into the input, but in my other post, I thought I read that using an ADC with an internal power reference would be better? Maybe I read that wrong. All I need to read is a simple number range from an ADC based on voltage that is anywhere from 0.71V to a max of 5.5V. I have a math conversion function that reads the current ADC function I am using (ADC.spin) which is a 3 digit number. There is a low value setting, and a high value setting which is hard programmed into the function. The input to the ADC determines the percentage between the low or high setting which is used in another function.

    Back to the switching regulator....

    For a "spike protection" resistor you say a 4R7 is what I should use. I have a BUNCH of SMD resistors that I got in a combo pack and I do see a 4R7 which is a 4.7K right? All the ones that I have are 1/2 watt or 1/4 watt which is too low for the incoming power to the regulator so I would need to go with a larger watt resistor, possibly a wire wound correct?

    I would still go for the opamp approach but otherwise use an I2C ADC with internal "voltage" reference. I'm not quite sure why you would need any kind of speed or resolution etc since you are reading a pot, a most imprecise device in itself. At the most I would say 10-bits of resolution (can you move the knob of a standard pot 0.263 degrees?). from a cheap SAR ADC would be all that you would ever need.

    See my previous post regarding the other details.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-12 18:22
    I am trying to read 3 different sensors at the moment. Engine ignition (5V square wave), Throttle Position (Analog Pot 0.7V to 5V output from ECU to single wire), and Speed Sensor (5v Square wave). I have not heard of using an Op Amp to read analog signal. I may have to look that up and see how that works. The less components, the better since I will have more room to spare in the end :p
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-12 18:53
    Here's a simple ADC circuit using a dual opamp and some software.

    A simple opamp ADC.jpg


    EDIT: This was the circuit I originally drew up but you could do it with a single comparator and a input voltage divider

    Here's that circuit:
    A simple comparator ADC.jpg
    1024 x 756 - 115K
    1024 x 518 - 57K
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-12 20:21
    I am not quite understanding the DAC and Sense pins from the prop. Where can I learn about this type of setup? It seems easy enough to build and still uses 2 pins like my current ADC setup does.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-12 20:58
    The RC DAC integrates the duty cycle output from the Prop so you end up with an analog voltage. The duty cycle is not really PWM but you can think of it as a 0 to 100% PWM for this application. A 0% duty cycle will integrate to 0V whereas 100% will be 3.3V (it's the same as a logic high) and a 50% duty cycle is half of the 3.3V which is 1.65V. All you need to do is to "guess" the voltage of the input and the clue is the sense pin which responds with "too high" or "too low" just like the game of "guess the number between 1 and 100". If you start off at 50%=1.65V and the sense pin says too high then you know it's lower than that so you go to 25%= 0.825V and then the sense pin might say it's too low so now you know it's between 0.825V and 1.65V. The next guess (all guesses) is simply (MAX-MIN / 2) + MIN and so you successively approximate until your MIN and MAX levels are now too close or close enough.

    BTW, the comparator will output a high if the voltage on the + input is higher than the - input.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-03-12 21:02
    So basically, I could use the same code as the ADC.spin for the schematic you have posted above?

    ADC.spin
    {{
    *****************************************
    * generic ADC driver v1.0               *
    * Author: Beau Schwabe                  *
    * Copyright (c) 2007 Parallax           *
    * See end of file for terms of use.     *
    *****************************************
    }}
    CON
        SDF = 8                     'sigma-delta feedback ************************* DAC???
        SDI = 9                     'sigma-delta input ******************************* Sense ???
    
    PUB SigmaDelta (sample)
        cognew(@asm_entry, sample)   'launch assembly program in a COG
    
    DAT
                  org
    
    asm_entry     mov       dira,#1<<SDF                    'make SDF pin an output
    
                  movs      ctra,#SDI                       'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#SDF
                  movi      ctra,#%01001_000
                  mov       frqa,#1
    
                  mov       asm_c,cnt                       'prepare for WAITCNT loop
                  add       asm_c,asm_cycles
    
                  
    :loop         waitcnt   asm_c,asm_cycles                'wait for next CNT value
                                                            '(timing is determinant after WAITCNT)
    
                  mov       asm_new,phsa                    'capture PHSA
    
                  mov       asm_sample,asm_new              'compute sample from 'new' - 'old'
                  sub       asm_sample,asm_old
                  mov       asm_old,asm_new
                  
                  wrlong    asm_sample,par                  'write sample back to Spin variable "sample" 
                                                            '(WRLONG introduces timing indeterminancy here..)
                                                            '(..since it must sync to the HUB)
                                                            
                  jmp       #:loop                          'wait for next sample
    
                  
    
    asm_cycles    long      $FFFF                           '(use $FFFF for 16-bit, $FFF for 12-bit, or $FF for 8-bit)
    
    asm_c         res       1                               'uninitialized variables follow emitted data
    asm_cnt       res       1
    asm_new       res       1
    asm_old       res       1
    asm_sample    res       1
    asm_temp      res       1
    
    DAT
    {{
    &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    &#9474;                                                   TERMS OF USE: MIT License                                                  &#9474;
    &#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
    &#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    &#9474;
    &#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    &#9474;
    &#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software&#9474;
    &#9474;is furnished to do so, subject to the following conditions:                                                                   &#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          &#9474;
    &#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         &#9474;
    &#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   &#9474;
    &#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         &#9474;
    &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    }}
    
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-03-12 21:39
    So basically, I could use the same code as the ADC.spin for the schematic you have posted above?

    ADC.spin
    {{
    *****************************************
    * generic ADC driver v1.0               *
    * Author: Beau Schwabe                  *
    * Copyright (c) 2007 Parallax           *
    * See end of file for terms of use.     *
    *****************************************
    }}
    CON
        SDF = 8                     'sigma-delta feedback ************************* DAC???
        SDI = 9                     'sigma-delta input ******************************* Sense ???
    
    PUB SigmaDelta (sample)
        cognew(@asm_entry, sample)   'launch assembly program in a COG
    
    DAT
                  org
    
    asm_entry     mov       dira,#1<<SDF                    'make SDF pin an output
    
                  movs      ctra,#SDI                       'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#SDF
                  movi      ctra,#001_000
                  mov       frqa,#1
    
                  mov       asm_c,cnt                       'prepare for WAITCNT loop
                  add       asm_c,asm_cycles
    
                  
    :loop         waitcnt   asm_c,asm_cycles                'wait for next CNT value
                                                            '(timing is determinant after WAITCNT)
    
                  mov       asm_new,phsa                    'capture PHSA
    
                  mov       asm_sample,asm_new              'compute sample from 'new' - 'old'
                  sub       asm_sample,asm_old
                  mov       asm_old,asm_new
                  
                  wrlong    asm_sample,par                  'write sample back to Spin variable "sample" 
                                                            '(WRLONG introduces timing indeterminancy here..)
                                                            '(..since it must sync to the HUB)
                                                            
                  jmp       #:loop                          'wait for next sample
    
                  
    
    asm_cycles    long      $FFFF                           '(use $FFFF for 16-bit, $FFF for 12-bit, or $FF for 8-bit)
    
    asm_c         res       1                               'uninitialized variables follow emitted data
    asm_cnt       res       1
    asm_new       res       1
    asm_old       res       1
    asm_sample    res       1
    asm_temp      res       1
    
    DAT
    {{
    &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    &#9474;                                                   TERMS OF USE: MIT License                                                  &#9474;
    &#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
    &#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    &#9474;
    &#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    &#9474;
    &#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software&#9474;
    &#9474;is furnished to do so, subject to the following conditions:                                                                   &#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          &#9474;
    &#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         &#9474;
    &#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   &#9474;
    &#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         &#9474;
    &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    }}
    

    Short answer, NO.
    Lookup SAR & Sigma/Delta if you are interested to find out more.
Sign In or Register to comment.