88 #ifndef _NZDEFAULT_PWM_H_
89 #define _NZDEFAULT_PWM_H_
91 #if defined(HAS_NZ_PWM)
93 #if (defined(__PIC24F__)) && defined(__C30__) // Microchip C30 compiler
95 #elif defined(__dsPIC33F__) && defined(__C30__) // Microchip C30 compiler
96 #elif defined(__PIC32MX__) // Microchip C32 compiler
98 #error Unknown processor or compiler. See Compiler.h
103 #define PWM_CLOCK_FREQ (GetInstructionClock())
104 #define PWM_CLOCK_PERIOD (1/GetInstructionClock())
115 #if defined(__PIC24FJ128GB106__) || defined(__PIC24FJ256GB106__) || defined(__PIC24FJ256GB206__)
116 extern volatile REGS_OC_ __attribute__ ((sfr(0x0190))) regs_oc_[9];
117 #elif defined(__PIC32MX__) // Microchip C32 compiler
119 extern volatile REGS_OC_ regs_oc_[9];
121 #error "nz_pwm no processor defined!"
128 #define PWM_FREQ_320HZ 49999
134 #define PWM_FREQ_1600HZ 9999
140 #define PWM_FREQ_3200HZ 4999
146 #define PWM_FREQ_8KHZ 1999
152 #define PWM_FREQ_16KHZ 999
158 #define PWM_FREQ_80KHZ 199
164 #define PWM_FREQ_160KHZ 99
167 #define PWM1_FREQ PWM_FREQ_16KHZ
171 #define PWM2_FREQ PWM_FREQ_16KHZ
175 #define PWM3_FREQ PWM_FREQ_16KHZ
179 #define PWM4_FREQ PWM_FREQ_16KHZ
183 #define PWM5_FREQ PWM_FREQ_16KHZ
187 #define PWM6_FREQ PWM_FREQ_16KHZ
191 #define PWM7_FREQ PWM_FREQ_16KHZ
195 #define PWM8_FREQ PWM_FREQ_16KHZ
199 #define PWM9_FREQ PWM_FREQ_16KHZ
232 #define PWM_CALCULATE_PERIOD_FOR_FREQUENCY(f) ((PWM_CLOCK_FREQ/f)-1)
253 #define pwm1OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC1; pwmOpenDefault(1, PWM1_FREQ, inverted);}
273 #define pwm2OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC2; pwmOpenDefault(2, PWM2_FREQ, inverted);}
293 #define pwm3OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC3; pwmOpenDefault(3, PWM3_FREQ, inverted);}
313 #define pwm4OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC4; pwmOpenDefault(4, PWM4_FREQ, inverted);}
333 #define pwm5OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC5; pwmOpenDefault(5, PWM5_FREQ, inverted);}
353 #define pwm6OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC6; pwmOpenDefault(6, PWM6_FREQ, inverted);}
373 #define pwm7OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC7; pwmOpenDefault(6, PWM7_FREQ, inverted);}
393 #define pwm8OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC8; pwmOpenDefault(8, PWM8_FREQ, inverted);}
413 #define pwm9OpenDefault(ppsOut, inverted) {ppsOut = OUT_FN_PPS_OC9; pwmOpenDefault(9, PWM9_FREQ, inverted);}
441 void pwmOpenDefault(BYTE chan, WORD period, BYTE inverted);
466 #define pwm1SetPeriod(period) pwmSetPeriod(1, period)
467 #define pwm2SetPeriod(period) pwmSetPeriod(2, period)
468 #define pwm3SetPeriod(period) pwmSetPeriod(3, period)
469 #define pwm4SetPeriod(period) pwmSetPeriod(4, period)
470 #define pwm5SetPeriod(period) pwmSetPeriod(5, period)
471 #define pwm6SetPeriod(period) pwmSetPeriod(6, period)
472 #define pwm7SetPeriod(period) pwmSetPeriod(7, period)
473 #define pwm8SetPeriod(period) pwmSetPeriod(8, period)
474 #define pwm9SetPeriod(period) pwmSetPeriod(9, period)
501 void pwmSetPeriod(BYTE chan, WORD period);
513 WORD pwmGetPeriod(BYTE chan);
520 #define pwm1GetPeriod() (OC1RS)
521 #define pwm2GetPeriod() (OC2RS)
522 #define pwm3GetPeriod() (OC3RS)
523 #define pwm4GetPeriod() (OC4RS)
524 #define pwm5GetPeriod() (OC5RS)
525 #define pwm6GetPeriod() (OC6RS)
526 #define pwm7GetPeriod() (OC7RS)
527 #define pwm8GetPeriod() (OC8RS)
528 #define pwm9GetPeriod() (OC9RS)
560 void pwmSetFreqAndDutyCycle(BYTE chan,
float freq,
float dc);
571 float pwmGetFrequency(BYTE chan);
583 #define pwm1SetDutyCycle(dc) pwmSetDutyCycle(1, dc)
584 #define pwm2SetDutyCycle(dc) pwmSetDutyCycle(2, dc)
585 #define pwm3SetDutyCycle(dc) pwmSetDutyCycle(3, dc)
586 #define pwm4SetDutyCycle(dc) pwmSetDutyCycle(4, dc)
587 #define pwm5SetDutyCycle(dc) pwmSetDutyCycle(5, dc)
588 #define pwm6SetDutyCycle(dc) pwmSetDutyCycle(6, dc)
589 #define pwm7SetDutyCycle(dc) pwmSetDutyCycle(7, dc)
590 #define pwm8SetDutyCycle(dc) pwmSetDutyCycle(8, dc)
591 #define pwm9SetDutyCycle(dc) pwmSetDutyCycle(9, dc)
603 void pwmSetDutyCycle(BYTE chan, WORD dc);
630 #define pwm1SetPercent(period, percent) (OC1R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
631 #define pwm2SetPercent(period, percent) (OC2R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
632 #define pwm3SetPercent(period, percent) (OC3R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
633 #define pwm4SetPercent(period, percent) (OC4R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
634 #define pwm5SetPercent(period, percent) (OC5R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
635 #define pwm6SetPercent(period, percent) (OC6R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
636 #define pwm7SetPercent(period, percent) (OC7R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
637 #define pwm8SetPercent(period, percent) (OC8R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
638 #define pwm9SetPercent(period, percent) (OC9R = ((((period+1)/100) * percent)==0) ? 0 : ((((period+1)/100) * percent)-1))
652 #endif //#if defined(HAS_NZ_PWM)