• AVR Freaks

Module CCP3

Author
Ushoran
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/04/15 16:48:15
  • Location: 0
  • Status: offline
2019/07/23 06:25:37 (permalink)
0

Module CCP3

Hello, I'm doing my final degree work, and I'm programming the PIC16(L)F18425 with the hope to detect 3 diferent PWM signals from a RF receiver. For that porpouse I'm using 3 of the 4 CCPx modules. CCP1 and CCP2 are working fine, but CCP3 is not going as well as I want. In brief, when the duty cycle that I apply on the CCP3 pin its larger than certain value, one output pin configured as digital output takes the high level and other output pin taks low level, while the duty cycle get lower that the value the outputs levels are reversed. With the Mplab simulator it works nice, but when i apply the signals on the lab the behaivor of output pins didnt work well. In fact the levels of the uoput pins only works when I disconnect the signal of CCP1, while all the signals are connected to the CCPx pins only CCP1 and CCP2 are working correctly. 
Its posible that CCP3 registers are linked to CCP1?
I attach the .c file, the comments are in Spanish, sorry for the inconvenience, I have not had time to translate them.
#1

1 Reply Related Threads

    pcbbc
    Super Member
    • Total Posts : 1188
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Module CCP3 2019/07/23 07:57:37 (permalink)
    +1 (1)
    UshoranWhen the duty cycle that I apply on the CCP3 pin its larger than certain value, one output pin configured as digital output takes the high level and other output pin taks low level, while the duty cycle get lower that the value the outputs levels are reversed.

    And what is the "certain value"?
     
    Having looked at your code, one thing that stands out like a sore thumb:
    You are doing floating point arithmetic in you interrupt service routine.  That is going to be chewing up a lot of CPU resources.  It's almost certainly at least part of the problem at higher frequencies/duty cycles.
    Where ever possible I would suggest removing and using integer arithmetic ONLY.
     
    For example treat all values of tiempo[2] as being multiplied by 200 internally.  So compare against 1400 instead of 7.0.
     
    If you absolutely must have floating point arithmetic (hint: there are very few situations where it is absolutely necessary and where integer only/fixed point cannot be made to work the same or better) then confine all floating point calculations to your mainline code so the ISR is not burdened with them.
     
    Edit: Also you should let TMR1 freerun when using CCP.  I have no idea why you are resetting it to 0xB1E0.  Other than the fact you need to use it for counting 1000 counts and controlling A4/A5.  Use a different timer for that, and you CCP code will be substantially easier - no need to check for overflows and wrap arounds for example.
     
    And you didn't give any of your initialization code either, so we have no idea if there is something wrong with the setup of CCP4.
    post edited by pcbbc - 2019/07/23 08:08:05
    #2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5