HPWM down


Closed Thread
Results 1 to 6 of 6

Thread: HPWM down

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default HPWM down

    I am attempting to control my motor using the HPWM. The code works, but the header has a problem .

    I used a header from a post I found here,it works, but I would liek to know what is wrong with mine

    This do not work:
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    PAUSE 300 ' start-up delay
    DEFINE CCP1_REG PORTB 'Hpwm 1 pin port, RIGHT
    DEFINE CCP1_BIT 3 'Hpwm 1 pin bit

    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %00000000
    loop:
    HPWM 1,127,1000

    Goto loop 'Do it forever
    end


    This code works:
    @ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF, CCPMX_ON
    OSCCON=$60 ' use internal 4MHZ osc
    PAUSE 300 ' start-up delay
    DEFINE CCP1_REG PORTB 'Hpwm 1 pin port, RIGHT
    DEFINE CCP1_BIT 3 'Hpwm 1 pin bit

    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %00000000
    loop:
    HPWM 1,127,1000

    Goto loop 'Do it forever
    end

    As soon as i turn off the internal oscillation and put in a 20Mhz crystal, it does not work
    Last edited by lerameur; - 9th January 2007 at 21:07.

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    In your first program you forgot the "@ device"-statement. This statement is neccessary for every program! How should the PIC knows to initialize his oszillator ?
    And use the "DEFINE OSC"-statement !
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yes and no, it goes much than this... using 20MHz, you can't produce a 1KHZ frequency. The lowest would be around 1.221 KHz...

    It's all explain in the PBP manual OR showned in my PicMultiCalc.
    <img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1318&stc=1&d=116838497 7">
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    like i said I tried that:
    Here is the code, it does not work, it always stays on high

    @ DEVICE PIC16F88, MCLR_ON, HS_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF, CCPMX_ON

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal

    PAUSE 100 ' start-up delay

    DEFINE CCP1_REG PORTB 'Hpwm 1 pin port, RIGHT
    DEFINE CCP1_BIT 3 'Hpwm 1 pin bit

    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %00000000

    loop:
    PORTB.4=1 'Enable B+ Both motors forward
    PORTB.5=0 'Enable B-
    PortB.6=1 'Enable A+
    PortB.7=0 'Enable A-
    HPWM 1,127,2000 'enable pin 13 Now for the speed of each motor
    pause 5500
    HPWM 1,210,2000
    pause 5500

    Goto loop 'Do it forever
    end
    Last edited by lerameur; - 10th January 2007 at 00:05.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    HPWM 1,127,1300 'enable pin 13 Now for the speed of each motor
    pause 5500
    HPWM 1,210,1300
    about now?

    EDIT: it's working here...
    Last edited by mister_e; - 9th January 2007 at 23:56.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I decided to put it at 5000
    HPWM 1,127,5000 'enable pin 13 Now for the speed of each motor
    pause 5500
    HPWM 1,210,5000
    pause 5500
    and it works


    thanks guys

Similar Threads

  1. need help on hpwm
    By helmut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 15:49
  2. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05
  3. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  4. HPWM and A to D interaction question 18F252
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th May 2006, 03:50
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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