PWM PIC Project

Discussion in 'Embedded Systems and Microcontrollers' started by SubnetMask, May 3, 2009.

  1. SubnetMask

    Thread Starter New Member

    May 3, 2009
    8
    0
    I just picked up a small PIC Programmer & Experimentation board, mainly to try to create a (relatively) simple controller, and in the process, have been bitten by the PIC :). Really neat, inexpensve controller with seemingly endless possibilites. Anyway, the project I'm looking to do will likely involve either a PIC12F683, PIC16F819 or PIC16F627A. What I'm looking to do is create a controller that when an input on the PIC is activated (press a button/flip a switch), it puts out a low PWM signal at 100Hz, ramping from 0% to 90% duty cycle over about one second, and staying at 90% DC until the input is deactivated.

    I want to put this in between another PWM controller and a solenoid so I can manually enable the solenoid, and in order to prevent the other controller from fussing, I need the circuit to be pass-through when not active, but when activated, switch the other controller from the solenoid to a dummy load that simulates the solenoid, with the PIC ramping up the solenoid.

    Think it's doable? Does anyone have any suggestions for books or other resources that could "Fast track" me to completing this controller? While this controller was the main reason the PICs got my attention, with the seemingly endless possibilities, I'd like to learn much more about how to program PICs. Any suggestions/Advice would be appreciated.

    Thanks,
    Dave
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Which programming language will you use to program it and which compiler?
     
  3. SubnetMask

    Thread Starter New Member

    May 3, 2009
    8
    0
    Not a clue; Any suggestions would be welcome and appreciated. I'm hoping to find some books locally.
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Go to www.microchip.com, they have soem tutorials there.

    Also, search in google for 'PIC tutrorials', you will get many.
     
  5. XtremeelectroniX

    New Member

    Nov 6, 2008
    6
    0
    Are you interested in PICs and learning about them or are you only interested in this once off project?
     
  6. DonQ

    Active Member

    May 6, 2009
    320
    11
    I might suggest simply reading the incoming PWM continuously. Have a load continuously applied to this input to satisfy the incoming signal. When you read this signal, convert it to a numeric value, such as percent duty cycle.

    Then have another routine controlling the output. Have it respond to a duty cycle command, such as percent duty cycle.

    Then the problem is only deciding which command to send to the output controller. It also gives you a way to start at the current setting when you ramp up, since you have been continuously reading the incoming PWM. When you go "inactive", simply pass the value from the incoming reading to the output PWM control.

    You will have a counter for measuring the incoming signal; probably use a built-in PWM controller for the output signal; and a counter for controlling the rate at which the output is advanced while it is ramping up.
     
  7. SubnetMask

    Thread Starter New Member

    May 3, 2009
    8
    0
    Originally I was interested in this one project, but since I've checked them out and seen all you can do with them, I'm very interested in learning how to do more and to really know how to program them. I picked up some 16F876A, 16F819 and 12F683 (the one I want to use for this project) PICs to play with, and have a Vellemann programmer & experiment board. I was also eyeing up the EasyPIC5 development board.

    Since I originally posted, I've changed the circuit design and built a "prototype" board for the circuit. Instead of having the relays and such, what I've set up is have the output from the controller connected to GP4 with a 10K resistor to +12 to fool the controller into thinking it's still connected to the solonoid (The sol is about 10K), and my override switch hooked to GP1. GP0 & GP2 would be outputs to a N-Channel Mosfet which would actuate the solonoid (with a diode on each output to prevent feedback into the PIC). In the programming, the general idea would be when the override switch is off, the pic basically looks at GP4 and translates it's status to GP0 (If GP4=low, bring GP0 high, if GP4=high, bring GP0 low). The PIC should be fast enough to able to put out a matching 100Hz PWM signal by toggling the state of GP0.

    Then, if the override switch is on (GP1 = low), ignore GP4 and bring up GP2/CPP1 as a 100Hz PWM signal, either ramped smoothly from 0% to 90% over about 1 second or stepped 0% => 50% => 60% => 90% over roughly the same period, then keep it there until the switch is turned off.

    Now I just need to figure out how to program the thing. Any suggestions for a good book that is aimed for the noob that has no experience with PICs, and gives a good, in-depth learning experience?

    Thanks,
    Dave
     
  8. randyjones

    New Member

    May 12, 2008
    2
    0
    You really need to decide what language you will be using. I teach a one semester community college class using PICs, and the students "get" to use Microchip's MPLAB in assembly language. This helps them learn what's going on "under the hood" but may not the best direction for you to take.

    There are many options; here is one to consider: You may have heard of the BASIC Stamp from Parallax. There are many code examples, and the language is well supported. A company called MicroEngineering Labs makes a compiler - PicBasic Pro - that closely compares with the BASIC Stamp 2 language, which is nice because there is so much info out there. PicBasic Pro has been around for over 10 years, and is regularly updated for new PICs, new features, etc. I have used it for a number of personal and commercial projects. There is a downloadable free trial version that will probably let you write a large enough program for this project.

    If you want to PWM at 100 Hz, each cycle lasts 10 ms - 10 thousandths of a second. At your max PWM of 90%, you still have 1 ms "off'" time, which should be enough to do your calculations and "housekeeping" (assuming you are running the PIC's clock at 4 MHz or something like that). So, even if the PIC you use doesn't have a PWM module, you could generate the PWM in software and use the time the PWM signal is off to run your code. I did something very similar to this for a client using an 8-pin PIC, with far more sophisticated PWM outputs (continuously varying frequency and duty cycle, high precision, shut off in 1/2 hour, etc.)

    Here's an approach you could use:

    Set up the PIC's onboard timer for 10 ms (one output cycle). You don't need to use interrupts - just watch the timer flag at the end of your loop to know when to start over.

    Beginning of loop: Turn on PWM output pin and use software timing loop to provide correct on time. If the duty cycle is 35% right now, you need to delay 3.5 ms. After the delay, turn off output pin and run your code that monitors input pins, decides what to do, calculates duty cycle for the next cycle, etc. Then wait until the timer times out, which indicates you have completed the current 10 ms cycle and are ready to start over. This works because the code you run during he "off" time is pretty simple and should take a very short time. After that is done, you are just sitting there waiting for the timer to let you know that this cycle is over and it's time to start over. I've even done things like this without using a timer, by counting and timing the individual machine cycles. Not recommended - heh, heh!!!

    I have a couple dozen PIC books. None of them is perfect. You need to decide what language you are using before buying books, though. They typically focus on one particular language, perhaps two (such as assembly and C). Have fun! I started playing with PICs about 15 years ago, and now make a nice living doing projects that are usually PIC-based.

    Randy Jones
     
  9. SubnetMask

    Thread Starter New Member

    May 3, 2009
    8
    0
    Thanks Randy. It sounds like PicBASIC might be a good direction for me to head to start trying to learn :). I'll see what I can find in the way of books and come back to this subject.
     
  10. sibujacob

    New Member

    Dec 8, 2013
    3
    0
Loading...