16 bit PWM using CCP1 - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 61 of 61
  1. #41
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Quote Originally Posted by richard View Post
    your version cannot work since CCP1CON and CCPR1H are not in bank 0

    and yes the code you marked red serves no purpose in the given example
    My point was that the code in red stopped it working and I could not work out why it was there.

  2. #42
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    the code in red just wastes time ,it's not what stopped the program from working . the problem is the changing sfr's in the wrong bank.

  3. #43
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Quote Originally Posted by richard View Post
    the code in red just wastes time ,it's not what stopped the program from working . the problem is the changing sfr's in the wrong bank.
    It did stop it working on my 18F452 though.

  4. #44
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    bsf INTCON,7 ;GIE = 1
    bsf INTCON,6 ;PEIE = 1 Enable peripheral interrupts
    bsf PIE1,0 ; TMR1IE= 1 Enable TMR1

    intcon bits 6 and 7 should already be set , setting them again should do no harm
    pie1.0 is also set , setting it again can't hurt

    it just wastes 12 cpu cycles

    the problem lies elsewhere, PWM_VAL must be > 30 ,values from 0-29 wont work could that have happened

  5. #45
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    intcon bits 6 and 7 should already be set , setting them again should do no harm
    pie1.0 is also set , setting it again can't hurt
    That is exactly what I thought and could not find anything to indicate otherwise in the datasheet.

    the problem lies elsewhere, PWM_VAL must be > 30 ,values from 0-29 wont work could that have happened
    No I started PWM_VAL for zero and incremented up in steps of 1 and it worked all the way rolling over and starting from 0. If 0-29 does not work I could not detect it with my voltmeter.

  6. #46
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    just tried your "red" code in the isr on a pic18f45k20

    you are right

    bsf INTCON,6 ;PEIE = 1 Enable peripheral interrupts
    bsf PIE1,0 ; TMR1IE= 1 Enable TMR1

    these two lines lock it up. can't see why yet

    it looked harmless but its not ,its much worse than useless

  7. #47
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    N
    o I started PWM_VAL for zero and incremented up in steps of 1 and it worked all the way rolling over and starting from 0. If 0-29 does not work I could not detect it with my voltmeter
    I'm using a cro those <30ish pwm's cause the output pin to be permanently high when you expect a very small pw , in real life that could be nasty
    try a loop range yourself of 0 to say 28

  8. #48
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    The point of coming here is to learn and I am now comparing the architecture of the 18F452 and the 16F1827. They are completely different, not surprise there.

    I have found the sfrs are in bank 5 on the 16F1827 but I have no idea how to use this information.

  9. #49
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Quote Originally Posted by richard View Post
    N
    I'm using a cro those <30ish pwm's cause the output pin to be permanently high when you expect a very small pw , in real life that could be nasty
    try a loop range yourself of 0 to say 28
    Just tried it no problem 0 gave 0 volts 9 gave 3 mV.

  10. #50
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    CALLS TO ASM always set bank 0

    pbp has a macro you can use "chk?rp sfr" it will ckeck that the appropriate bank is set (see status or bank sfr)
    the mpasm assembler can also do a " BANKSEL SFR"

    BEFORE YOU RETURN T0 PBP YOU MUST SET BANK BACK TO BANK 0
    Last edited by richard; - 26th August 2014 at 11:23. Reason: still can't spell

  11. #51
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    not on a cro

    using a main loop like this
    MAIN:

    PWM_VAL = PWM_VAL+1
    PAUSE 500
    if pwm_val > 29 then pwm_val=0
    toggle portd.1
    Goto MAIN

  12. #52
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Quote Originally Posted by richard View Post
    not on a cro
    What is a cro?

  13. #53
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    oscilloscope

    depending on your age , in the old days a cathode ray oscilloscope, cro for short

  14. #54
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Quote Originally Posted by richard View Post
    N
    I'm using a cro those <30ish pwm's cause the output pin to be permanently high when you expect a very small pw , in real life that could be nasty
    try a loop range yourself of 0 to say 28
    I will take your word for it as I have no instrument that will replicate your results, and as I have found in the past just because I can not see it does not mean it is not there.

  15. #55
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    the 30 figure came from the pic16f1825 using dt_ints14
    for a pic18f45k20 the figure is 25 using dt_ints18
    for a pic18f45k20 using DEFINE INTHAND the figure is 11
    seems dt_ints introduces more latency

    point is 0 is not off and pwm < latency is not a small pw

  16. #56
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Quote Originally Posted by richard View Post
    your version cannot work since CCP1CON and CCPR1H are not in bank 0

    and yes the code you marked red serves no purpose in the given example
    Richard,
    Thanks for your reply.
    Yes, you're right. 103 error occurs after compiling. Banksel command is used, will you?

    Talat

  17. #57
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Thanks
    Yes, you're right.
    My first version was like you, did not work. To better understand the problem I have added including red lines.
    I tried again and the result is the same version. In the start-up process produces two pulses and then stops.

  18. #58
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    I installed the PBP trial version 3.0.7 to try. Nothing's changed. Error 113 continues (Post 56, I wrote 103, it's wrong)


    Name:  16b.png
Views: 398
Size:  60.1 KBName:  16b.png
Views: 398
Size:  60.1 KB

  19. #59
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Hi,
    Check your spelling of CCPR1H and CCPR1L.

    /Henrik.

  20. #60
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Hi,
    Henrik, congratulations for being careful, thank you.
    This is a completely copy-paste disaster
    Talat

  21. #61
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: 16 bit PWM using CCP1

    Quote Originally Posted by talatsahim View Post
    Hi,
    Henrik, congratulations for being careful, thank you.
    This is a completely copy-paste disaster
    Talat
    That error comes from post #35 and #37 is there anyway these posts can be corrected?

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. How to tell which PICs can handle 16 bit variables?
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st August 2005, 08:44
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

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