10-bit HPWM


Closed Thread
Results 1 to 6 of 6

Thread: 10-bit HPWM

  1. #1
    Peter Oors's Avatar
    Peter Oors Guest

    Default 10-bit HPWM

    Hello,
    How do I setup a 16F819 for 10-bit HPWM?
    8-bit HPWM is no problem, see (a part of) the code.

    @ DEVICE PIC16F819,INTRC_OSC_NOCLKOUT
    @ DEVICE CCPMX_ON ' RB3 PWM
    @ DEVICE PIC16F819,MCLR_OFF
    DEFINE OSC 8 ' not in use for 4MHz
    OSCCON = $70 ' 70=8 MHz, 60=4 MHz
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 3
    ADCON1 = %00001110 '0=analog, 1,2,3,4=digital
    TRISA = %11111111
    TRISB = %00000000
    PORTB = %00000000
    n var byte ' for 10 bit it should be a word
    HPwm 3,n,1000

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


    Did you find this post helpful? Yes | No

    Default

    the only things that spring to my mind is:

    1. PIC16F819 have only one PWM channel so use:
    HPwm 1,n,1000

    2. maybe manual configuration will have to be done for CCP1CON and CCPR1L registers

    or may try to set PR2 manually

    see page 71 of datasheet section 9.3.3 SETUP FOR PWM OPERATION. sometimes PicBasic will not do everything we have to setup.

    datasheet there:
    http://ww1.microchip.com/downloads/e...Doc/39598d.pdf

    App note AN594 use CCP
    http://ww1.microchip.com/downloads/e...tes/00594b.pdf

    And this beauty CCP tricks 'tip
    http://ww1.microchip.com/downloads/e...Doc/41214a.pdf


    these should place you on the way.

    many regards
    Steve

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

  3. #3
    Peter Oors's Avatar
    Peter Oors Guest


    Did you find this post helpful? Yes | No

    Unhappy

    At first, I am not familiar with assembler, PicBasic Pro I can work with.
    It seems it's not complete yet.
    I think it doesn't "see" 2 bits.
    At portb I use a led to see if it works.
    The led's intensity increases 4 times like a sawtooth, decreases the same way, 10-bits in 4 times 8 bits.
    Would you be so kind to help me with the final part?
    OSCCON = $60 ' 4 MHz
    CCP1CON = %00111100
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 3
    ADCON1 = %00000111
    TRISA = %11111111
    TRISB = %00000000
    PORTB = %00000000
    n VAR WORD
    Clear
    BEGIN:
    For n=1 TO 1023
    HPwm 1,n,1000
    Pause 4
    Next
    Pause 2000
    For n=1023 TO 1 STEP -1
    HPwm 1,n,1000
    Pause 4
    Next
    Pause 2000
    GoTo BEGIN

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Always worthwhile doing a search...

    http://www.picbasic.co.uk/forum/show...=&threadid=170

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


    Did you find this post helpful? Yes | No

    Default

    That could'nt be more clear than this
    Steve

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

  6. #6
    Peter Oors's Avatar
    Peter Oors Guest


    Did you find this post helpful? Yes | No

    Talking

    Hello,

    Thanks to all, it works fine now.
    We made the next loop with a led, just for testing!

    @ DEVICE PIC16F819,INTRC_OSC_NOCLKOUT
    @ DEVICE CCPMX_ON ' RB3 PWM
    @ DEVICE PIC16F819,MCLR_OFF
    OSCCON =$60 ' 4 MHz
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 3
    PR2 =249 ' Set PR2 to get 1kHz out
    T2CON =%00000100 ' Values for PWM period
    CCP1CON =%00001100 ' Set PWM Mode
    ADCON1 =%00001110 ' 0=analog, 1,2,3,4=digital
    TRISA =%11111111
    TRISB =%00000000
    PORTB =%00000000
    n VAR WORD
    '=====
    BEGIN:
    For n=1 TO 1023 STEP 4
    GoSub loop
    Pause 10
    Next
    For n=1023 TO 1 STEP -4
    GoSub loop
    Pause 10
    Next
    GoTo BEGIN
    loop:
    T2CON=%00000101 ' Turn on Timer2, Prescaler=4
    CCP1CON.4 =n.0 ' Store n to registers as
    CCP1CON.5 =n.1 ' a 10-bit word
    CCPR1L =n>>2
    Return

    Thanks all,
    Peter

Similar Threads

  1. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  3. Need help with 16f819 10 bit ADC
    By bannrikae in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th September 2005, 15:20
  4. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07
  5. 10 Bit HPWM?
    By Desterline in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th December 2003, 19:13

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