Shop OBEX P1 Docs P2 Docs Learn Events
PWM — Parallax Forums

PWM

jokerswildjokerswild Posts: 31
edited 2007-09-28 21:47 in General Discussion
G'day fellas.

Got a quick question. I want to control a 12V 120mm fan using a logic mosfet.
I'm reading temperature with a thermistor and RCTIME and controlling the mosfet using PWM.

Currently i have the mosfet connected via a current limiting resistor and a pull up to 5V on gate.

Whats the best way to 'clean' the PWM so the fan doesn't 'hunt' (pulses with the PWM duration)?

Cheers!

Comments

  • PJMontyPJMonty Posts: 983
    edited 2007-09-27 05:25
    Jokerswild,

    I don't understand what you mean by cleaning the PWM so the fan doesn't hunt. Also, what are you doing with the fan? Are you trying to maintain a temperature by cooling (or not) with the fan? What are you cooling? Is the temperature reading device in the airstream? If so, it will be cooled off, giving erroneous readings.

    Thanks,
    PeterM
  • jokerswildjokerswild Posts: 31
    edited 2007-09-27 06:27
    Er I guess i should of tried more things before posting here....

    The 'hunt' is when the program is doing other things, not PWM.

    Is there a way i can run a PWM in the background while the program is looping. I don't know how to use interrupts, i guess i will need to learn?

    Thanks for any help!
  • PJMontyPJMonty Posts: 983
    edited 2007-09-27 06:46
    Jokerswild,

    Interrupts are your friend. BTW, are you programming in assembly or SX/B ? I think that SX/B can do PWM in the background for you, but I wouldn't swear to it. I'm an assembly programmer by nature, so I haven't really used SX/B.

    Thanks,
    PeterM
  • jokerswildjokerswild Posts: 31
    edited 2007-09-27 06:51
    Thanks. I'm using SX/B. BASIC is the only programming language i know.

    Time to hit the books, thanks for your help PJMonty!
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-09-27 14:50
    Hello,

    Which SX chip are you using? SX/B can use the built in timers on the SX chip. I've been using the SX48 which has two built-in 16-bit timers. I think the SX28 has a single 8-bit timer but I haven't used that one in any projects yet. The timers can run in the background since they are built into the hardware while you do other stuff. You need to use specific pins for each timer so check the datasheet to get the proper connections for which chip you are using.

    For the SX48 using timer 1 (PIN RB.6)

    TIMER1 PWM, Spd, Duty

    The value you select for the duty cycle will depend on the clock speed you're using.

    Hope this helps,

    Robert
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-09-27 15:09
    You can add background PWM to SX/B -- see the attached program. Note, though, that any time-based instructions (PAUSE, RCTIME, SEROUT, etc.) will be adversely affected when the interrupts are run, so you may need to adjust for that. In my example program there is a subroutine called DELAY_MS that uses the ISR for delays.
  • jokerswildjokerswild Posts: 31
    edited 2007-09-27 22:15
    RobotWorkshop- I'm using the SX28 so i cannot use the TIMER1 function. I do have 48's and 52's but i dont have any smd boards to test with. Thanks for the info!

    JonnyMac- I'll have a go at dissecting your program, i think your ideas will help me. Thanks!

    Post Edited (jokerswild) : 9/28/2007 12:23:59 AM GMT
  • msb80scmsb80sc Posts: 8
    edited 2007-09-28 21:47
    I'm doing the same thing but controlling a 19" 12 volt fan on a car radiator. I am not much of a coder. Mostly use examples of code and modify it to do what I want. I decided to clean up the code to match some of the examples I have. So I changed my PWM speeds to read like this.

    LOW_SPEED:
    · PWM RC.0, 64, 50

    This caused the led in my SX28 test circuit to pulse. Then went back to the way I coded it when I was using a BS2.

    LOW_SPEED:
    ·PWM RC.0, 64, 50
    ··GOTO Start

    This brought back a steady light that varied bright to dim with the different PWM commands.
Sign In or Register to comment.