Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
p33c_pwm.c
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2  * and any derivatives exclusively with Microchip products.
3  *
4  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5  * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7  * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8  * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9  *
10  * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11  * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12  * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13  * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14  * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15  * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16  * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17  *
18  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19  * TERMS.
20  */
21 
22 // Include standard header files
23 #include <xc.h> // include processor files - each processor file is guarded.
24 #include <stdint.h> // include standard integer data types
25 #include <stdbool.h> // include standard boolean data types
26 #include <stddef.h> // include standard definition data types
27 
28 #include "p33c_pwm.h"
29 
30 
50 volatile uint16_t p33c_PwmModule_Initialize(void)
51 {
52  volatile uint16_t retval=1;
53 
55 
56  return(retval);
57 }
58 
59 
75 {
76  volatile struct P33C_PWM_MODULE_s* pwm;
77 
78  // Capture Handle: set pointer to memory address of desired PWM instance
79  pwm = (volatile struct P33C_PWM_MODULE_s*) ((volatile uint8_t*)&PCLKCON);
80 
81  return(pwm);
82 }
83 
84 
104 volatile uint16_t p33c_PwmModule_Dispose(void)
105 {
106  volatile uint16_t retval=1;
107 
109 
110  return(retval);
111 }
112 
113 
127 volatile struct P33C_PWM_MODULE_s p33c_PwmModule_ConfigRead(void)
128 {
129  volatile struct P33C_PWM_MODULE_s* pwm;
130 
131  // Set pointer to memory address of desired PWM instance
132  pwm = (volatile struct P33C_PWM_MODULE_s*)
133  ((volatile uint8_t*) &PCLKCON);
134 
135  return(*pwm);
136 
137 }
138 
139 
158 volatile uint16_t p33c_PwmModule_ConfigWrite(volatile struct P33C_PWM_MODULE_s pwmConfig)
159 {
160  volatile uint16_t retval=1;
161  volatile struct P33C_PWM_MODULE_s* pwm;
162 
163  // Set pointer to memory address of desired PWM instance
164  pwm = (volatile struct P33C_PWM_MODULE_s*)
165  ((volatile uint8_t*) &PCLKCON);
166  *pwm = pwmConfig;
167 
168  return(retval);
169 
170 }
171 
172 
188 volatile struct P33C_PWM_GENERATOR_s p33c_PwmGenerator_ConfigRead(volatile uint16_t pgInstance)
189 {
190  volatile struct P33C_PWM_GENERATOR_s* pg;
191 
192  // Set pointer to memory address of desired PWM instance
193  pg = (volatile struct P33C_PWM_GENERATOR_s*)
194  ((volatile uint8_t*) &PG1CONL + ((pgInstance - 1) * P33C_PWMGEN_SFR_OFFSET));
195 
196  return(*pg);
197 
198 }
199 
200 
218  volatile uint16_t pgInstance,
219  volatile struct P33C_PWM_GENERATOR_s pgConfig
220 )
221 {
222  volatile uint16_t retval=1;
223  volatile struct P33C_PWM_GENERATOR_s* pg;
224 
225  // Set pointer to memory address of desired PWM instance
226  pg = (volatile struct P33C_PWM_GENERATOR_s*)
227  ((volatile uint8_t*) &PG1CONL + ((pgInstance - 1) * P33C_PWMGEN_SFR_OFFSET));
228  *pg = pgConfig;
229 
230  return(retval);
231 
232 }
233 
234 
250 volatile uint16_t p33c_PwmGenerator_Initialize(volatile uint16_t pgInstance)
251 {
252  volatile uint16_t retval=1;
253  volatile struct P33C_PWM_GENERATOR_s* pg;
254 
255 
256  // Set pointer to memory address of desired PWM instance
257  pg = p33c_PwmGenerator_GetHandle(pgInstance);
258 
259  // Disable the PWM generator
260  retval &= p33c_PwmGenerator_Disable(pg);
261 
262  // Reset all SFRs to default
263  retval &= p33c_PwmGenerator_ConfigWrite(pgInstance, pgConfigClear);
264 
265  /* PWM GENERATOR CONTROL REGISTER LOW */
266  pg->PGxCONL.bits.ON = 0; // Disable PWM generator
267  pg->PGxCONL.bits.CLKSEL = 0b01; // Clock Selection: Selected by PWM module register PCLKCON.MCLKSEL bits
268  pg->PGxCONL.bits.MODSEL = 0b000; // Mode Selection: Independent Edge PWM mode
269  pg->PGxCONL.bits.TRGCNT = 0b000; // Trigger Count Selection: PWM Generator produces 1 PWM cycle after triggered
270  pg->PGxCONL.bits.HREN = 1; // PWM Generator 1 High-Resolution Enable bit: PWM Generator 1 operates in High-Resolution mode
271 
272  return(retval);
273 }
274 
275 
276 
290 volatile uint16_t p33c_PwmGenerator_Dispose(volatile uint16_t pgInstance)
291 {
292  volatile uint16_t retval=1;
293 
294  // Clear all registers of pgInstance
296 
297  return(retval);
298 }
299 
300 
316 volatile uint16_t p33c_PwmGenerator_Enable(volatile struct P33C_PWM_GENERATOR_s* pg)
317 {
318  volatile uint16_t retval=1;
319  volatile uint16_t timeout=0;
320 
321  // Set PWM generator override bits to prevent signals being generated outside the device
322  pg->PGxIOCONL.bits.OVRENH = 1;
323  pg->PGxIOCONL.bits.OVRENL = 1;
324 
325  // Assign GPIO ownership to I/O module control
326  pg->PGxIOCONH.bits.PENH = 0;
327  pg->PGxIOCONH.bits.PENL = 0;
328 
329  // Turn on the PWM generator
330  pg->PGxCONL.bits.ON = 1;
331 
332  // enforce update of timing registers
333  pg->PGxSTAT.bits.UPDREQ = 1;
334 
335  // If high resolution mode is enabled, check if clock has locked in without errors
336  if(pg->PGxCONL.bits.HREN)
337  {
338  while((!PCLKCONbits.HRRDY) && (timeout++<5000));
339  if ((timeout >= 5000) || (PCLKCONbits.HRERR)) // if there is an error
340  return(0); // return ERROR
341 
342  }
343 
344  // Assign GPIO ownership to given PWM generator
345  pg->PGxIOCONH.bits.PENH = 1;
346  pg->PGxIOCONH.bits.PENL = 1;
347 
348  return(retval);
349 
350 }
351 
352 
366 volatile uint16_t p33c_PwmGenerator_Disable(volatile struct P33C_PWM_GENERATOR_s* pg)
367 {
368  volatile uint16_t retval=1;
369 
370  // Set PWM generator override bits to prevent signals being generated outside the device
371  pg->PGxIOCONL.bits.OVRENH = 1;
372  pg->PGxIOCONL.bits.OVRENL = 1;
373 
374  // Assign GPIO ownership to I/O module control
375  pg->PGxIOCONH.bits.PENH = 0;
376  pg->PGxIOCONH.bits.PENL = 0;
377 
378  // Turn on the PWM generator
379  pg->PGxCONL.bits.ON = 0;
380 
381  return(retval);
382 
383 }
384 
385 
400 volatile uint16_t p33c_PwmGenerator_Resume(volatile struct P33C_PWM_GENERATOR_s* pg)
401 {
402  volatile uint16_t retval=1;
403 
404  // Set PWM generator override bits to prevent signals being generated outside the device
405  pg->PGxIOCONL.bits.OVRENH = 0;
406  pg->PGxIOCONL.bits.OVRENL = 0;
407 
408 
409  return(retval);
410 
411 }
412 
413 
428 volatile uint16_t p33c_PwmGenerator_Suspend(volatile struct P33C_PWM_GENERATOR_s* pg)
429 {
430  volatile uint16_t retval=1;
431 
432  // Set PWM generator override bits to prevent signals being generated outside the device
433  pg->PGxIOCONL.bits.OVRENH = 1;
434  pg->PGxIOCONL.bits.OVRENL = 1;
435 
436 
437  return(retval);
438 
439 }
440 
441 
442 
457 volatile uint16_t p33c_PwmGenerator_SetPeriod(
458  volatile struct P33C_PWM_GENERATOR_s* pg,
459  volatile uint16_t period
460  )
461 {
462  volatile uint16_t retval=1;
463 
464  // Set PWM generator period
465  pg->PGxPER.value = period;
466 
467  return(retval);
468 
469 }
470 
471 
472 
491  volatile struct P33C_PWM_GENERATOR_s* pg,
492  volatile uint16_t duty
493  )
494 {
495  volatile uint16_t retval=1;
496 
497  // Set PWM generator duty cycle
498  pg->PGxDC.value = duty;
499 
500  return(retval);
501 
502 }
503 
504 
505 
525  volatile struct P33C_PWM_GENERATOR_s* pg,
526  volatile uint16_t dead_time_rising,
527  volatile uint16_t dead_time_falling
528  )
529 {
530  volatile uint16_t retval=1;
531 
532  // Set PWM generator period
533  pg->PGxDTH.value = dead_time_rising;
534  pg->PGxDTL.value = dead_time_falling;
535 
536  return(retval);
537 
538 }
539 
555 volatile struct P33C_PWM_GENERATOR_s* p33c_PwmGenerator_GetHandle(volatile uint16_t pgInstance)
556 {
557  volatile struct P33C_PWM_GENERATOR_s* pg;
558 
559  // Capture Handle: set pointer to memory address of desired PWM instance
560  pg = (volatile struct P33C_PWM_GENERATOR_s*)
561  ((volatile uint8_t*)&PG1CONL + ((pgInstance - 1) * P33C_PWMGEN_SFR_OFFSET));
562 
563  return(pg);
564 }
565 
566 
580 volatile uint16_t p33c_PwmGenerator_GetInstance(volatile struct P33C_PWM_GENERATOR_s* pg)
581 {
582  volatile uint16_t retval=1;
583 
584  // Null-pointer protection
585  if (pg == NULL)
586  return(0);
587 
588  // Capture Instance: set pointer to memory address of desired PWM instance
589  retval = (volatile uint16_t)
590  (((volatile uint16_t)&pg->PGxCONL - (volatile uint16_t)&PG1CONL) / P33C_PWMGEN_SFR_OFFSET) + 1;
591 
592  if (retval > P33C_PG_COUNT)
593  return(0); // PWM generator not member of a valid group
594 
595  return(retval);
596 }
597 
598 
612 volatile uint16_t p33c_PwmGenerator_GetGroup(volatile struct P33C_PWM_GENERATOR_s* pg)
613 {
614  volatile uint16_t retval=1;
615  volatile uint16_t pgInstance;
616 
617  // Null-pointer protection
618  if (pg == NULL)
619  return(0);
620 
621  // Get group of PWM generator
622  pgInstance = (volatile uint16_t)
623  (((volatile uint16_t)&pg->PGxCONL - (volatile uint16_t)&PG1CONL) / P33C_PWMGEN_SFR_OFFSET + 1);
624 
625  // Verify PWM generator group is valid and available
626  if (pgInstance > P33C_PG_COUNT)
627  return(0); // PWM generator not member of a valid group
628  else if (pgInstance > 4)
629  retval = 2; // PWM generator is member of group #2 [PG5-PG8]
630  else
631  retval = 1; // PWM generator is member of group #1 [PG1-PG4]
632 
633  return(retval);
634 }
635 
636 
671  volatile struct P33C_PWM_GENERATOR_s* pgHandleMother,
672  volatile uint16_t pgMotherTriggerOutput,
673  volatile struct P33C_PWM_GENERATOR_s* pgHandleChild,
674  volatile bool ChildImmediateUpdate
675  )
676 {
677  volatile uint16_t retval=1;
678  volatile uint16_t pgMotherInstance=0;
679  volatile uint16_t pgChildInstance=0;
680  volatile uint16_t pgMotherGroup=0;
681  volatile uint16_t pgChildGroup=0;
682  volatile uint16_t pgInstance;
683 
684  // Null-pointer protection
685  if ((pgHandleMother == NULL) || (pgHandleChild == NULL))
686  return(0);
687 
688  // Capture PWM generator instances and groups for given handles
689  pgMotherInstance = p33c_PwmGenerator_GetInstance(pgHandleMother);
690  pgMotherGroup = p33c_PwmGenerator_GetGroup(pgHandleMother);
691 
692  pgChildInstance = p33c_PwmGenerator_GetInstance(pgHandleChild);
693  pgChildGroup = p33c_PwmGenerator_GetGroup(pgHandleChild);
694 
695  // Enable update trigger broadcast in Mother PWM
696  // PWM generator broadcasts software set/clear of the UPDREQ status bit and EOC signal
697  pgHandleMother->PGxCONH.bits.MSTEN = 1;
698 
699  // PWM Generator Trigger Output Selection
700  // 0b011 = PGxTRIGC compare event is the PWM Generator trigger
701  // 0b010 = PGxTRIGB compare event is the PWM Generator trigger
702  // 0b001 = PGxTRIGA compare event is the PWM Generator trigger
703  // 0b000 = EOC event is the PWM Generator trigger
704  pgHandleMother->PGxEVTL.bits.PGTRGSEL = (pgMotherTriggerOutput & 0x0003);
705 
706  // Configure child PWM in slaved mode, incorporating immediate of EOC selection
707  pgHandleChild->PGxCONH.bits.UPDMOD = (0b010 | ChildImmediateUpdate); // Slaved SOC update
708  pgHandleChild->PGxCONH.bits.TRGMOD = 1; // PWM Generator operates in Retriggerable mode
709  pgHandleChild->PGxEVTL.bits.UPDTRG = 0b00; // Timing register updates triggered through UPDREQ bit (PGxSTAT[3])
710  pgHandleChild->PGxCONL.bits.MODSEL = 0b000; // Independent Edge PWM mode;
711 
712  /* Set sync trigger input to Child generator
713 
714  SOCS[3:0]: Start-of-Cycle Selection bits(1,2,3)
715  1111 = TRIG bit or PCI Sync function only (no hardware trigger source is selected)
716  1110-0101 = Reserved
717  0100 = Trigger output selected by PG4 or PG8 PGTRGSEL[2:0] bits (PGxEVTL[2:0])
718  0011 = Trigger output selected by PG3 or PG7 PGTRGSEL[2:0] bits (PGxEVTL[2:0])
719  0010 = Trigger output selected by PG2 or PG6 PGTRGSEL[2:0] bits (PGxEVTL[2:0])
720  0001 = Trigger output selected by PG1 or PG5 PGTRGSEL[2:0] bits (PGxEVTL[2:0])
721  0000 = Local EOC ? PWM Generator is self-triggered
722 
723  */
724 
725  if (pgMotherGroup == pgChildGroup)
726  {
727  // If both PWM generators are member of the same group,
728  // direct synchronization can be used
729 
730  if (pgMotherGroup == 1)
731  pgHandleChild->PGxCONH.bits.SOCS = pgMotherInstance;
732  else if (pgMotherGroup == 2)
733  pgHandleChild->PGxCONH.bits.SOCS = (pgMotherInstance - 4);
734  else
735  return(0); // Exit if PWM generator group is out of range
736 
737  }
738  else
739  {
740  // Synchronization across PWM generator groups need to be routed
741  // through the PCI Sync function
742 
743  pgInstance = p33c_PwmGenerator_GetInstance(pgHandleChild);
744 
745  pgHandleChild->PGxCONH.bits.SOCS = 0b1111;
746  pgHandleChild->PGxSPCIL.bits.PSS = 0b00001; // Internally connected to the output of PWMPCI[2:0] MUX
747  pgHandleChild->PGxLEBH.bits.PWMPCI = pgInstance;
748  }
749 
750 
751  return(retval);
752 
753 }
754 
755 /* ********************************************************************************************* *
756  * PWM MODULE BASE CONFIGURATION TEMPLATES
757  * ********************************************************************************************* */
758 
759 
773 volatile struct P33C_PWM_MODULE_s pwmConfigClear = {
774 
775  .vPCLKCON.value = 0x0000, // HRRDY=0, HRERR=0, LOCK=0, DIVSEL=0b00, MCLKSEL=0b00
776  .vFSCL.value = 0x0000, // FSCL=0
777  .vFSMINPER.value = 0x0000, // FSMINPER=0
778  .vMPHASE.value = 0x0000, // MPHASE=0
779  .vMDC.value = 0x0000, // MDC=0
780  .vMPER.value = 0x0000, // MPER=0
781  .vLFSR.value = 0x0000, // LFSR=0
782  .vCMBTRIGL.value = 0x0000, // CTA1EN=0, CTA2EN=0, CTA3EN=0, CTA4EN=0, CTA5EN=0, CTA6EN=0, CTA7EN=0, CTA8EN=0
783  .vCMBTRIGH.value = 0x0000, // CTB1EN=0, CTB2EN=0, CTB3EN=0, CTB4EN=0, CTB5EN=0, CTB6EN=0, CTB7EN=0, CTB8EN=0
784  .LOGCON_A.value = 0x0000, // PWMS1A=0b0000, PWMS2A=0b0000, S1APOL=0, S2APOL=0, PWMLFA=0b00, PWMLFAD=0b000
785  .LOGCON_B.value = 0x0000, // PWMS1B=0b0000, PWMS2B=0b0000, S1BPOL=0, S2BPOL=0, PWMLFB=0b00, PWMLFBD=0b000
786  .LOGCON_C.value = 0x0000, // PWMS1C=0b0000, PWMS2C=0b0000, S1CPOL=0, S2CPOL=0, PWMLFC=0b00, PWMLFCD=0b000
787  .LOGCON_D.value = 0x0000, // PWMS1D=0b0000, PWMS2D=0b0000, S1DPOL=0, S2DPOL=0, PWMLFD=0b00, PWMLFDD=0b000
788  .LOGCON_E.value = 0x0000, // PWMS1E=0b0000, PWMS2E=0b0000, S1EPOL=0, S2EPOL=0, PWMLFE=0b00, PWMLFED=0b000
789  .LOGCON_F.value = 0x0000, // PWMS1F=0b0000, PWMS2F=0b0000, S1FPOL=0, S2FPOL=0, PWMLFF=0b00, PWMLFFD=0b000
790  .PWMEVT_A.value = 0x0000, // EVTAOEN=0, EVTAPOL=0, EVTASTRD=0, EVTASYNC=0, EVTASEL=0b000, EVTAPGS=0b000
791  .PWMEVT_B.value = 0x0000, // EVTBOEN=0, EVTBPOL=0, EVTBSTRD=0, EVTBSYNC=0, EVTBSEL=0b000, EVTBPGS=0b000
792  .PWMEVT_C.value = 0x0000, // EVTCOEN=0, EVTCPOL=0, EVTCSTRD=0, EVTCSYNC=0, EVTCSEL=0b000, EVTCPGS=0b000
793  .PWMEVT_D.value = 0x0000, // EVTDOEN=0, EVTDPOL=0, EVTDSTRD=0, EVTDSYNC=0, EVTDSEL=0b000, EVTDPGS=0b000
794  .PWMEVT_E.value = 0x0000, // EVTEOEN=0, EVTEPOL=0, EVTESTRD=0, EVTESYNC=0, EVTESEL=0b000, EVTEPGS=0b000
795  .PWMEVT_F.value = 0x0000 // EVTFOEN=0, EVTFPOL=0, EVTFSTRD=0, EVTFSYNC=0, EVTFSEL=0b000, EVTFPGS=0b000
796  };
797 
798 
813 volatile struct P33C_PWM_MODULE_s pwmConfigDefault = {
814 
815  .vPCLKCON.value = 0x0003, // HRRDY=0, HRERR=0, LOCK=0, DIVSEL=0b00, MCLKSEL=0b11
816  .vFSCL.value = 0x0000, // FSCL=0
817  .vFSMINPER.value = 0x0000, // FSMINPER=0
818  .vMPHASE.value = 0x0000, // MPHASE=0
819  .vMDC.value = 0x0000, // MDC=0
820  .vMPER.value = 0x0000, // MPER=0
821  .vLFSR.value = 0x0000, // LFSR=0
822  .vCMBTRIGL.value = 0x0000, // CTA1EN=0, CTA2EN=0, CTA3EN=0, CTA4EN=0, CTA5EN=0, CTA6EN=0, CTA7EN=0, CTA8EN=0
823  .vCMBTRIGH.value = 0x0000, // CTB1EN=0, CTB2EN=0, CTB3EN=0, CTB4EN=0, CTB5EN=0, CTB6EN=0, CTB7EN=0, CTB8EN=0
824  .LOGCON_A.value = 0x0000, // PWMS1A=0b0000, PWMS2A=0b0000, S1APOL=0, S2APOL=0, PWMLFA=0b00, PWMLFAD=0b000
825  .LOGCON_B.value = 0x0000, // PWMS1B=0b0000, PWMS2B=0b0000, S1BPOL=0, S2BPOL=0, PWMLFB=0b00, PWMLFBD=0b000
826  .LOGCON_C.value = 0x0000, // PWMS1C=0b0000, PWMS2C=0b0000, S1CPOL=0, S2CPOL=0, PWMLFC=0b00, PWMLFCD=0b000
827  .LOGCON_D.value = 0x0000, // PWMS1D=0b0000, PWMS2D=0b0000, S1DPOL=0, S2DPOL=0, PWMLFD=0b00, PWMLFDD=0b000
828  .LOGCON_E.value = 0x0000, // PWMS1E=0b0000, PWMS2E=0b0000, S1EPOL=0, S2EPOL=0, PWMLFE=0b00, PWMLFED=0b000
829  .LOGCON_F.value = 0x0000, // PWMS1F=0b0000, PWMS2F=0b0000, S1FPOL=0, S2FPOL=0, PWMLFF=0b00, PWMLFFD=0b000
830  .PWMEVT_A.value = 0x0000, // EVTAOEN=0, EVTAPOL=0, EVTASTRD=0, EVTASYNC=0, EVTASEL=0b000, EVTAPGS=0b000
831  .PWMEVT_B.value = 0x0000, // EVTBOEN=0, EVTBPOL=0, EVTBSTRD=0, EVTBSYNC=0, EVTBSEL=0b000, EVTBPGS=0b000
832  .PWMEVT_C.value = 0x0000, // EVTCOEN=0, EVTCPOL=0, EVTCSTRD=0, EVTCSYNC=0, EVTCSEL=0b000, EVTCPGS=0b000
833  .PWMEVT_D.value = 0x0000, // EVTDOEN=0, EVTDPOL=0, EVTDSTRD=0, EVTDSYNC=0, EVTDSEL=0b000, EVTDPGS=0b000
834  .PWMEVT_E.value = 0x0000, // EVTEOEN=0, EVTEPOL=0, EVTESTRD=0, EVTESYNC=0, EVTESEL=0b000, EVTEPGS=0b000
835  .PWMEVT_F.value = 0x0000 // EVTFOEN=0, EVTFPOL=0, EVTFSTRD=0, EVTFSYNC=0, EVTFSEL=0b000, EVTFPGS=0b000
836  };
837 
838 /* ********************************************************************************************* *
839  * PWM GENERATOR CONFIGURATION TEMPLATES
840  * ********************************************************************************************* */
841 
842 
856 volatile struct P33C_PWM_GENERATOR_s pgConfigClear = {
857 
858  .PGxCONL.value = 0x0000, // ON=0, TRGCNT=0b000, HREN=0, CLKSEL=b00, MODSEL=0b000
859  .PGxCONH.value = 0x0000, // MDCSEL=0, MPERSEL=0, MPHSEL=0, MSTEN=0, UPDMOD=0b000, TRGMOD=0, SOCS=0b0000
860  .PGxSTAT.value = 0x0000, // SEVT=0, FLTEVT=0, CLEVT=0, FFEVT=0, SACT=0, FLTACT=0, CLACT=0, FFACT=0, TRSET=0, TRCLR=0, CAP=0, UPDATE=0, UPDREQ=0, STEER=0, CAHALF=0, TRIG=0
861  .PGxIOCONL.value = 0x0000, // CLMOD=0, SWAP=0, OVRENH=0, OVRENL=0, OVRDAT=0, OSYNC=0b00, FLTDAT=0, CLDAT=0, FFDAT=0, DBDAT=0
862  .PGxIOCONH.value = 0x0000, // CAPSRC=0b000, DTCMPSEL=0, PMOD=0b00, PENH=0, PENL=0, POLH=0, POLL=0
863  .PGxEVTL.value = 0x0000, // ADTR1PS=0b00000, ADTR1EN3=0, ADTR1EN2=0, ADTR1EN1=0, UPDTRG=0b00, PGTRGSEL=0b000
864  .PGxEVTH.value = 0x0000, // FLTIEN=0, CLIEN=0, FFIEN=0, SIEN=0, IEVTSEL=0b00, ADTR2EN3=0, ADTR2EN2=0, ADTR2EN1=0, ADTR1OFS=0b00000
865  .PGxFPCIL.value = 0x0000, // TSYNCDIS=0, TERM=0b000, AQPS=0, AQSS=0b000, SWTERM=0, PSYNC=0, PPS=0, PSS=0b00000
866  .PGxFPCIH.value = 0x0000, // BPEN=0, BPSEL=0b000, ACP0b000, SWPCI=0, SWPCIM=0b00, LATMOD=0, TQPS=0, TQSS=0b000
867  .PGxCLPCIL.value = 0x0000, // TSYNCDIS=0, TERM=0b000, AQPS=0, AQSS=0b000, SWTERM=0, PSYNC=0, PPS=0, PSS=0b00000
868  .PGxCLPCIH.value = 0x0000, // BPEN=0, BPSEL=0b000, ACP0b000, SWPCI=0, SWPCIM=0b00, LATMOD=0, TQPS=0, TQSS=0b000
869  .PGxFFPCIL.value = 0x0000, // TSYNCDIS=0, TERM=0b000, AQPS=0, AQSS=0b000, SWTERM=0, PSYNC=0, PPS=0, PSS=0b00000
870  .PGxFFPCIH.value = 0x0000, // BPEN=0, BPSEL=0b000, ACP0b000, SWPCI=0, SWPCIM=0b00, LATMOD=0, TQPS=0, TQSS=0b000
871  .PGxSPCIL.value = 0x0000, // TSYNCDIS=0, TERM=0b000, AQPS=0, AQSS=0b000, SWTERM=0, PSYNC=0, PPS=0, PSS=0b00000
872  .PGxSPCIH.value = 0x0000, // BPEN=0, BPSEL=0b000, ACP0b000, SWPCI=0, SWPCIM=0b00, LATMOD=0, TQPS=0, TQSS=0b000
873  .PGxLEBL.value = 0x0000, // LEB=0
874  .PGxLEBH.value = 0x0000, // PWMPCI=0b000, PHR=0, PHF=0, PLR=0, PLF=0,
875  .PGxPHASE.value = 0x0000, // PGxPHASE=0
876  .PGxDC.value = 0x0000, // PGxDC=0
877  .PGxDCA.value = 0x0000, // PGxDCA=0
878  .PGxPER.value = 0x0000, // PGxPER=0
879  .PGxTRIGA.value = 0x0000, // PGxTRIGA=0
880  .PGxTRIGB.value = 0x0000, // PGxTRIGB=0
881  .PGxTRIGC.value = 0x0000, // PGxTRIGC=0
882  .PGxDTL.value = 0x0000, // DTL=0
883  .PGxDTH.value = 0x0000, // DTH=0
884  .PGxCAP.value = 0x0000 // CAP=0
885  };
886 
887 
888 
889 // end of file
P33C_PWM_GENERATOR_s::bits
struct tagPG1CONLBITS bits
Definition: p33c_pwm.h:197
p33c_PwmGenerator_SetPeriod
volatile uint16_t p33c_PwmGenerator_SetPeriod(volatile struct P33C_PWM_GENERATOR_s *pg, volatile uint16_t period)
Sets the period of a given PWM generator.
Definition: p33c_pwm.c:457
pgConfigClear
volatile struct P33C_PWM_GENERATOR_s pgConfigClear
Default RESET configuration of one PWM generator instance SFRs.
Definition: p33c_pwm.c:856
P33C_PWM_GENERATOR_s::PGxLEBH
union P33C_PWM_GENERATOR_s::@70 PGxLEBH
P33C_PWM_GENERATOR_s::PGxIOCONH
union P33C_PWM_GENERATOR_s::@58 PGxIOCONH
P33C_PWM_GENERATOR_s::PGxSTAT
union P33C_PWM_GENERATOR_s::@56 PGxSTAT
p33c_PwmGenerator_Disable
volatile uint16_t p33c_PwmGenerator_Disable(volatile struct P33C_PWM_GENERATOR_s *pg)
Disables a given PWM generator.
Definition: p33c_pwm.c:366
p33c_PwmGenerator_ConfigWrite
volatile uint16_t p33c_PwmGenerator_ConfigWrite(volatile uint16_t pgInstance, volatile struct P33C_PWM_GENERATOR_s pgConfig)
Disposes a given PWM generator by resetting all its registers to default.
Definition: p33c_pwm.c:217
pwmConfigClear
volatile struct P33C_PWM_MODULE_s pwmConfigClear
Default RESET configuration of the PWM module SFRs.
Definition: p33c_pwm.c:773
p33c_PwmModule_ConfigWrite
volatile uint16_t p33c_PwmModule_ConfigWrite(volatile struct P33C_PWM_MODULE_s pwmConfig)
Writes a user-defined configuration to the PWM base module registers.
Definition: p33c_pwm.c:158
P33C_PWM_MODULE_s::vPCLKCON
union P33C_PWM_MODULE_s::@0 vPCLKCON
P33C_PWM_GENERATOR_s::PGxDTL
union P33C_PWM_GENERATOR_s::@78 PGxDTL
p33c_PwmGenerator_SyncGenerators
volatile uint16_t p33c_PwmGenerator_SyncGenerators(volatile struct P33C_PWM_GENERATOR_s *pgHandleMother, volatile uint16_t pgMotherTriggerOutput, volatile struct P33C_PWM_GENERATOR_s *pgHandleChild, volatile bool ChildImmediateUpdate)
Sets the synchronization triggers of two PWM generators, of which the Mother PWM generator is the tri...
Definition: p33c_pwm.c:670
P33C_PWM_GENERATOR_s::PGxSPCIL
union P33C_PWM_GENERATOR_s::@67 PGxSPCIL
p33c_PwmModule_GetHandle
volatile struct P33C_PWM_MODULE_s * p33c_PwmModule_GetHandle(void)
Gets pointer to PWM module SFR set.
Definition: p33c_pwm.c:74
P33C_PWM_GENERATOR_s
Definition: p33c_pwm.h:195
p33c_PwmGenerator_GetGroup
volatile uint16_t p33c_PwmGenerator_GetGroup(volatile struct P33C_PWM_GENERATOR_s *pg)
Get the PWM generator group.
Definition: p33c_pwm.c:612
p33c_PwmGenerator_GetHandle
volatile struct P33C_PWM_GENERATOR_s * p33c_PwmGenerator_GetHandle(volatile uint16_t pgInstance)
Returns the PWM generator index.
Definition: p33c_pwm.c:555
p33c_PwmModule_Dispose
volatile uint16_t p33c_PwmModule_Dispose(void)
Resets all PWM base module registers to their RESET default values.
Definition: p33c_pwm.c:104
p33c_PwmGenerator_Suspend
volatile uint16_t p33c_PwmGenerator_Suspend(volatile struct P33C_PWM_GENERATOR_s *pg)
Disables the PWM generator outputs but keeps the module running.
Definition: p33c_pwm.c:428
p33c_PwmGenerator_SetDeadTimes
volatile uint16_t p33c_PwmGenerator_SetDeadTimes(volatile struct P33C_PWM_GENERATOR_s *pg, volatile uint16_t dead_time_rising, volatile uint16_t dead_time_falling)
Sets the dead-times of a given PWM generator.
Definition: p33c_pwm.c:524
P33C_PWM_MODULE_s
Definition: p33c_pwm.h:86
P33C_PWM_GENERATOR_s::value
uint16_t value
Definition: p33c_pwm.h:198
P33C_PWM_MODULE_s::value
uint16_t value
Definition: p33c_pwm.h:90
p33c_PwmGenerator_GetInstance
volatile uint16_t p33c_PwmGenerator_GetInstance(volatile struct P33C_PWM_GENERATOR_s *pg)
Get the PWM generator instance index of a known PWM object pointer address.
Definition: p33c_pwm.c:580
pwmConfigDefault
volatile struct P33C_PWM_MODULE_s pwmConfigDefault
Default initialization configuration of the PWM module SFRs.
Definition: p33c_pwm.c:813
P33C_PWM_GENERATOR_s::PGxDTH
union P33C_PWM_GENERATOR_s::@79 PGxDTH
p33c_PwmModule_Initialize
volatile uint16_t p33c_PwmModule_Initialize(void)
Initializes the PWM base module by resetting all its registers to default.
Definition: p33c_pwm.c:50
p33c_PwmGenerator_Resume
volatile uint16_t p33c_PwmGenerator_Resume(volatile struct P33C_PWM_GENERATOR_s *pg)
Disables a PWM generator IOs.
Definition: p33c_pwm.c:400
P33C_PWM_GENERATOR_s::PGxCONH
union P33C_PWM_GENERATOR_s::@55 PGxCONH
p33c_PwmGenerator_SetDutyCycle
volatile uint16_t p33c_PwmGenerator_SetDutyCycle(volatile struct P33C_PWM_GENERATOR_s *pg, volatile uint16_t duty)
Sets the on-time of a given PWM generator.
Definition: p33c_pwm.c:490
p33c_PwmGenerator_Dispose
volatile uint16_t p33c_PwmGenerator_Dispose(volatile uint16_t pgInstance)
Disposes a given PWM generator by resetting all its registers to default.
Definition: p33c_pwm.c:290
p33c_PwmModule_ConfigRead
volatile struct P33C_PWM_MODULE_s p33c_PwmModule_ConfigRead(void)
Read the current configuration from the PWM base module registers.
Definition: p33c_pwm.c:127
P33C_PWM_GENERATOR_s::PGxPER
union P33C_PWM_GENERATOR_s::@74 PGxPER
P33C_PWM_GENERATOR_s::PGxEVTL
union P33C_PWM_GENERATOR_s::@59 PGxEVTL
P33C_PWM_GENERATOR_s::PGxCONL
union P33C_PWM_GENERATOR_s::@54 PGxCONL
p33c_PwmGenerator_ConfigRead
volatile struct P33C_PWM_GENERATOR_s p33c_PwmGenerator_ConfigRead(volatile uint16_t pgInstance)
Disposes a given PWM generator by resetting all its registers to default.
Definition: p33c_pwm.c:188
P33C_PWM_GENERATOR_s::PGxIOCONL
union P33C_PWM_GENERATOR_s::@57 PGxIOCONL
P33C_PWM_GENERATOR_s::PGxDC
union P33C_PWM_GENERATOR_s::@72 PGxDC
p33c_PwmGenerator_Initialize
volatile uint16_t p33c_PwmGenerator_Initialize(volatile uint16_t pgInstance)
Initializes a given PWM generator by resetting all its registers to default.
Definition: p33c_pwm.c:250
p33c_PwmGenerator_Enable
volatile uint16_t p33c_PwmGenerator_Enable(volatile struct P33C_PWM_GENERATOR_s *pg)
Enables a given PWM generator with output pins disabled.
Definition: p33c_pwm.c:316