• AVR Freaks

PIC24FV MCCP Capture Question

New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2020/05/12 16:51:34
  • Location: 0
  • Status: offline
2020/10/05 12:18:12 (permalink)

PIC24FV MCCP Capture Question

I am rather new to microprocessors but have figured out ADC/DAC/PWM functions and applications (which having before done most of this type work in LABVIEW is impressive with the speeds)
My current issue is understanding the MCCP capture mode.  I'm thinking it is simple and I just can't see it.  My application is to run a brushed DC 24V motor at a given speed using PWM and an optical encoder (simple LED and toothed wheel) arrangement for feedback.  I have the PWM part working using MCCP1 and I'm trying to use MCCP2 Capture mode to get the encoder period and adjusting the PWM duty cycle based on the error between the measured period and target period.
I've read the datasheet, the specific datasheet on MCCP module and I thought they implied that once my even occurs (falling edge) the clock count is written to the CCP2BUFL register and the count is reset.  Watching the debugger variable values, this does not appear to be happening.  I continually get register values much higher than expected so it appears the register is not resetting to 0 after the falling edge.  My while loop is simple:
   while (1)
        error = enc_tgt_P - CCP2BUFL;
        if(error > 0){                      //error > 0, slow down
        pwm_duty = pwm_duty - 2;
            if (pwm_duty < 15) pwm_duty = 15;

        if(error < 0){
            pwm_duty = pwm_duty + 1;        //error < 0, speed up
            if (pwm_duty > 100) pwm_duty = 100;
    return 1;
Any guidance would be appreciated.

0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 4.5