Multiple HPWM's 16F877


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    35

    Default Multiple HPWM's 16F877

    Am I at all close? I can get it to compile without it but adding a
    "For HPWMFREQ2 leaves me in the dark as two FOR NEXT loops is not correct but both timers need to change frequency at the same time. Thanks again to the best support group I've ever known!


    DEFINE LOADER_USED 1
    DEFINE ONINT_USED 1
    DEFINE OSC 10
    DEFINE CCP1_REG PORTC 'Hpwm 1 pin port pin 17 rc2 ccp1
    DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
    DEFINE ADC_BITS 12 ' Set number of bits in result 8-10-12
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 500 ' Set sampling time in microseconds


    HPWMFREQ VAR WORD
    HPWMFREQ2 VAR WORD
    DUTY VAR BYTE
    DUTY2 VAR BYTE

    CNTRL var word 'ADC BEGINNING SAMPLE
    TST var word 'ADC COMPARISON SAMPLE

    HPWMFREQ=1500 'CURRENT FREQUENCY OF HPWM
    HPWMFREQ2=3000 'CURRENT FREQUENCY OF HPWM
    CNTRL=0 'ADC CONTROL
    TST=0 'ADC TEST SAMPLE
    TRISA = 255 'ADC Set PORTA to all input
    ADCON1 = 2

    BEGIN:
    hpwm 1,DUTY, HPWMFREQ
    HPWM 2,DUTY2,HPWMFREQ2 'OR HPWMFREQ/2?
    ADCIN 0, CNTRL
    For HPWMFREQ = 1500 To 2000 Step 100
    'FOR HPWMFREQ2=3000 to 4000 Step 200
    DUTY=65
    DUTY2 = 65
    HPWMFREQ=HPWMFREQ+1
    HPWMFREQ2=HPWMFREQ2+1
    ADCIN 0, CNTRL
    ADCIN 0, TST
    IF TST < CNTRL THEN
    HPWMFREQ=HPWMFREQ +1
    HPWMFREQ2=HPWMFREQ2+1
    Endif
    ADCIN 0, TST
    if TST >= CNTRL then
    HPWMFREQ=HPWMFREQ +1
    HPWMFREQ2=HPWMFREQ2+1
    ENDIF
    NEXT HPWMFREQ
    goto BEGIN:
    end

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi,
    When you add the FOR HPWMFREQ2=3000 to 4000 Step 200 you also need to add a NEXT HPWMFREQ2

    But even when you do it won't work. The manual says:
    Some devices have 1, 2 or 3 PWM channels. On devices with 2 channels, the Frequency must be the same on both channels.
    /Henrik Olsson

  3. #3
    Join Date
    Jun 2006
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    But does it mean that the chips with three pwm's need to be the same frequency? I'll try it in the simulator then run it on the chip Thanks much for your time! Emmett

  4. #4
    Join Date
    Jun 2006
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    Hi group, The PBP manual says that the highest frequency at the HPWM's at any oscillator speed is 32767Hz. Is this correct? I'm looking for 48Khz. Also It says that if two are used they have to be the same frequency. The same frequency if I use three? Don't understand the limitations. Thanks again all! Emmett

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


    Did you find this post helpful? Yes | No

    Default

    It could depend of the PIC too.

    BTW @48MHZ, the highest frequency possible by using the calc should be 'round 5 MHZ (even if i have some doubt), 32.xxxKHZ is really low.

    HPWM is certainelay limited. To avoid this limitation, you have to write to the CCP register.
    Here's a short code snip for 2.5MHZ @ 50% duty cycle on a 16F877.
    Code:
    DEFINE OSC 20
    TRISC=0
    DUTY VAR WORD
    
    T2CON=%00000100
    PR2=1
    DUTY=4
    CCP1CON=%00001100 ' PWM MODE
    CCP1CON.5=DUTY.1
    CCP1CON.4=DUTY.0
    CCPR1L=DUTY>>2
    
    START:
          PAUSE 1
          GOTO START
    <IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1113&stc=1&d=116044582 1">
    Attached Images Attached Images  
    Last edited by mister_e; - 10th October 2006 at 03:03.
    Steve

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

Similar Threads

  1. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 15:18
  2. 16f877 and ps/2 keyboard error???
    By boraciner in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th July 2009, 08:14
  3. serial communication between CMUcam and PIC 16F877
    By gengkeys in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th March 2007, 06:43
  4. Multiple PIC's with 1 crystal
    By puma in forum Schematics
    Replies: 11
    Last Post: - 20th March 2007, 17:02
  5. 4 Quadrant dc drive with 16F877
    By mns45 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 23rd February 2006, 13:05

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