• AVR Freaks

Hot!Harmony, dynamic timers and PWM

Author
pio.ep
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2017/05/29 09:36:05
  • Location: 0
  • Status: offline
2017/06/16 16:02:41 (permalink)
0

Harmony, dynamic timers and PWM

I just started playing around with this harmony thing and there's some weird stuff going on.
my first attempt was a usual "hello world" led blinking, couple checkboxes then generate and it worked great. a callback from a timer with a counter toggling a led.
 
then I thought I'll do a pwm but there was a problem. after searching I found a post on this forum that PWM doesn't work with dynamic timer driver, so I switched it to static. pwm started working great but the program stopped calling the callback function.
 
I started digging.
it turns out that in the auto generated code the timer2(pwm timer) doesn count at all. so I started comparing the blink and pwm timer code. the only difference was the "DRV_TMR_AlarmRegister" function. So I added it and an empty callback.
 
I noticed that the generated code never sets the period for PWM in dynamic implementation.
 
is there a way to make it work so it just counts without that callback?
 
static void APP_OC_Task (void)
{
 switch(appData.ocStates)
 {
  default:
  
  case APP_OC_START:

   /* Start the output compare operation */
   DRV_OC_Start(appData.handleOC0, DRV_IO_INTENT_EXCLUSIVE);
 
 /////////////******************* I had to add this to make it work******************************/////////////////////
          DRV_TMR_AlarmRegister(
                appData.handleTMR1,
                80000,
                APP_TMR_DRV_IS_PERIODIC,
                (uintptr_t)NULL,
                TimerCallback2);
  /////////////******************* I had to add this to make it work******************************/////////////////////
   /* Start Timer Driver */
   DRV_TMR_Start (appData.handleTMR1);
   
   appData.ocStates = APP_OC_DONE;
   
   break;
   
  case APP_OC_DONE:
      
   break;
 }
}

#1

3 Replies Related Threads

    arpananand
    Super Member
    • Total Posts : 416
    • Reward points : 0
    • Joined: 2009/11/18 04:35:42
    • Location: 0
    • Status: offline
    Re: Harmony, dynamic timers and PWM 2017/06/18 10:09:30 (permalink)
    3 (1)
    for dynamic timer driver, i guess calling "DRV_TMR_AlarmRegister is necessary for setting up timer period. but if you don't want callback, then how about passing NULL for the callback argument in DRV_TMR_AlarmRegister API?
     
    #2
    RISC
    Super Member
    • Total Posts : 5376
    • Reward points : 0
    • Status: offline
    Re: Harmony, dynamic timers and PWM 2017/07/02 12:24:41 (permalink)
    0
    Hi,

    This is a tested example on PIC32 USB starter kit II using OC1.

    It is derived from the Harmony example v2.03b "oc_pwm". (it should run on previous Harmony versions if you patch changes. Just unzip it in c:\microchip\harmony\v2_03b\apps\examples\peripheral\oc\
    It will create on OC1 output a PWM signal

    It uses Timer2 in dynamic mode (without interrupt) and timer2 is driving OC1

    Regards
    (remove the .txt extension it is a zip file)
     
    post edited by RISC - 2017/07/07 15:32:26
    #3
    EmbeddedEngineer
    New Member
    • Total Posts : 26
    • Reward points : 0
    • Joined: 2016/02/24 06:56:35
    • Location: 0
    • Status: offline
    Re: Harmony, dynamic timers and PWM 2019/03/20 04:45:46 (permalink)
    0
    how to configure PWM for PIC32MZ EF in Hamony I need demo code please help
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5