Shop OBEX P1 Docs P2 Docs Learn Events
New member with programming questions — Parallax Forums

New member with programming questions

TomLTomL Posts: 15
edited 2006-07-30 02:55 in BASIC Stamp
First, I would like to say that I have used the BS2 in numerous projects. I can make it do what I want it to do most of the time. But, I am not an "effective or effecient" programmer. I am an Electronics teacher at a post secondary school, so I know the hardware fairly well. I am working on a new project, and can not get the "how to" straight in my head.

Project is a foot pedal motor speed control. The foot pedal turns a pot whose analog out goes to an ADC0804 (8 bit ADC). I want to read the ADC data and immediately pwm the same value. For instance, if I were mid range on throttle pedal, I shouild read about decimal 128, then I want to immediately generate pwm of 128 decimal. My brain has had a core dump.

Thanks

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-29 21:35
    Cane,

    ·· So you're interested in using the BASIC Stamp PWM command to generate an analog voltage?· What exactly will it be driving?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • TomLTomL Posts: 15
    edited 2006-07-29 21:58
    I know how to use pwm. I want to input data from an 8 bit a/d and immediately generate pwm of equal value to a fet motor driver.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-29 22:09
    Cane,

    ·· The range of·PWM is from 0-255, which is the same range as what the ADC returns.· So there is no problem with just using the RAW value from the ADC as a parameter for PWM, if you so desire it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • FranklinFranklin Posts: 4,747
    edited 2006-07-29 22:26
    val = (whatever you need to get the value from the pot)
    pwm pin, val, duration

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • TomLTomL Posts: 15
    edited 2006-07-29 22:39
    I understand the ranges are the same. So I can use raw data for pwm then.


    So, if speed was a variable word
    then I could INL speed, then pwm speed and this would be a 1 to 1 transfer. Position vs speed .

    I have used the bs2e in a lot of projects. I just can't write good programs. ha

    Visit my website and click on the robot boat link. It is an 8 foot r/c boat with a robot that fishes. Took 8 bs2 for me to get it to work.
    one bs2 per raido channel. I ain't a good programmer, but it worked.

    www.tomsstuff.net
    click on the robot boat link
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-29 22:42
    Cane,

    ·· You don't need a Word variable...0-255 is one byte and you could use the same byte to get the data from the ADC and send it to the PWM command.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • TomLTomL Posts: 15
    edited 2006-07-29 23:01
    What am I thinking. I know 8 bits is one byte. I told ya I had a core dump this morning..

    I get it.

    I will post the project here when I get it finished it that is ok. It will take a while to do this project. Rounding up stuff.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-30 00:14
    Cane Pole -

    If you were using a bus oriented microprocessor or similar CPU, then the ADC0804 might be a good choice for an 8-bit ADC. However, the PBASIC Stamp is NOT bus oriented, and one of the most PRECIOUS commodities (besides variable space, and to a lesser extent program memory) are your I/O pin ports. Using the ADC0804, you will be using (approx) 12 pin ports to do a job that can be done with THREE pin ports! I cringe when I see that sort of extragance or squandering of precious Stamp resources.

    Unless you have some unmentioned, compelling reaosn for using the ADC0804, please take a look at the ADC0831, and if you feel it fits your needs, pick one up and toss the ADC0804 back in the parts drawer. Here is a link to that ADC0831 chip and its data sheet:
    http://www.national.com/search/search.cgi/main?keywords=adc0831

    More than just the savings of pins by using a Microwire protocol, which is a synchronous serial input (PBASIC command - SHIFTIN), there are literally hundreds of examples throughout the Internet, and on the Parallax web site for using this (type of) chip with a PBASIC Stamp. Just as an additional comment, the ADC083X is a series of ADC's. Replace the "X" with 2, 4, or 8 and you have a 2-channel, 4-channel or 8-channel ADC of the same genre! Can't beat that with a stick!

    Kiss INL goodbye and say hello to many more I/O pin ports for possible future enhancements. If cost is of concern, ask for some samples. Most chip manufactures are happy to provide a few samples even to Cane Pole Computer Systems :-)

    I apologize if my response seems to ... come on "strong", but I just can't help but try to preserve the valuable resources of the venerable PBASIC Stamp, whether it's my project, or someone elses. Call it an idiot-syncracy :-)

    I have attached a PDF which has within it, a simple PBASIC program, using an ADC0831,· to start you on your way, just so there is less time lost on your part, since I'm such a inveterate pest :-) Check Applications Example # 2.

    Regards,

    Bruce Bates
  • TomLTomL Posts: 15
    edited 2006-07-30 01:45
    I understand where you are coming from Bruce

    As I stated, I teach electronics. This exercise (circuit) is about the parallel ADC not the BS2. I am more comfortable using the 6800 mpu than the BS2, but I have size constraints on this particular project. There are, by far, more parallel ADC's in the industrial world than the serial ones. I only pick up the bs2 a couple of times a year. I am not an effective bs2 programmer, but I get the job done. Hey, I go back to the days of the 6802. I am a GO TO, IF THEN, FOR NEXT programmer..........

    I like the bs2 for it's simplicity. I wish it had real time interrupt capabilities. I use the stamp in the classroom tutorial for my students. That is as far as I take it.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-30 02:05
    Cane Pole -

    Merely as a passing observation the 6800X is not exactly a micro-processor, unless you're speaking of the H2 or H8 series or something like that, so there is a bit of an apples and oranges comparison in mentioning the PBASIC Stamp and such an innately powerful CPU in the same teaching objective.

    FWIW, in the 10+ years I've worked with Stamps I·was never faced with a compelling need for a real time interrput. Of late, the polling facilty in the BS-2p? series of Stamps has worked admirably. Prior to that advent of polling I was able to use simple external hardware or software "tricks" to obviate the need for the "missing" real time interrupt.

    OTOH, I'm NOT saying that having a real time interrupt might not have been quicker to complete the project at hand. If nothing else, NOT having it available,·provides a real exercise in creative thinking, and to my mind, that's part of what teaching is all about, when I did it for a part-time living in a non-academic environment, and when I did it as a paid programmer.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 7/30/2006 2:28:17 AM GMT
  • TomLTomL Posts: 15
    edited 2006-07-30 02:55
    I understand your point.

    I also can get quite creative with hardware. I was using hardware long before there was such a thing as an IC. I can build anything with relays. Well, almost anything. Just takes a lot of room and a lot of relays.

    My students understand the difference between the microprocessors and the bs2. These are two different lectures. Both have different atmospheres in which they work, but also share a commonality. Presently, we are coverigng I/O devices, thus the ADC.
Sign In or Register to comment.