2

I was implementing a driver for ccp1 peripheral and after implementing it and using proteus for simulation, the enhanced PWM doesn't work while I made sure that the CCP1CON is loaded correctly and T2CON too and I don't know what is the problem.

It should output 50% duty cycle with 20kHz with P1A, P1C both active low and P1B, P1D both active high.

And according to datasheet Full-bridge output forward, P1D modulated; P1A active; P1B, P1C inactive.

Here are the registers of CCP1CON and T2CON and also TRISC and TRISD:

registers value

output config

The code:

#include "app.h"
#include "device_config.h"
#include "MCAL_Layer/CCPx/CCP1/hal_ccp1.h"
#include "MCAL_Layer/Timers/Timer3/hal_timer3.h"
#include "MCAL_Layer/Timers/Timer2/hal_timer2.h"

cpp1_t ccp1_obj = {
  .ccp1_interrupt_handler = NULL,
  .ccp1_interrupt_priority = INTERRUPT_LOW_PRIORITY,
  .ccp1_mode = CCP1_PWM_MODE_SELECT,
  .ccp1_mode_variant = CCP1_PWM_MODE_P1AC_LOW_P1BD_HIGH,
  .ccp1_pwm_output_config = FULL_BRIDGE_OUTPUT_FORWARD,
  .ccp1_pwm_frequency = 20000,
  .timer2_postscaler_value = 1,
  .timer2_prescaler_value = 1
};
timer2_t timer2_obj = {
  .PR2_preloaded_value = 99,
  .TMR2_preloaded_value = 0,
  .postscaler_value = 1,
  .prescaler_value = 1
};
int main(void)
{
    Std_ReturnType ret = E_OK;
    ret |= ccp1_init(&ccp1_obj);
    ret |= timer2_init(&timer2_obj);
    ccp1_pwm_set_duty_cycle(50);
    while (1)
    {

    }
    return (ret);
}

I don't know what to do after that and it doesn't output PWM.

8
  • What are the return values of the functions you are calling? Do they return error codes? Commented Nov 3, 2024 at 10:01
  • @mkrieger1 no only the ccp1_init as the interrupt handler is the stuct is null(it means that this object cant use interrupts because of that and it isn't necessarily needed in pwm mode) Commented Nov 3, 2024 at 23:34
  • Which PIC18 are you using? Have you switched your ouüut pins to digital? Is Timer 2 running? Commented Nov 4, 2024 at 10:53
  • @Mike I am using pic18f4620 and yeah the pins of the CCP1 are all digitals and they are output Commented Nov 4, 2024 at 13:09
  • And is Timer2 running? Please check Commented Nov 4, 2024 at 14:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.