Initial commit of files

This commit is contained in:
2021-01-22 10:16:20 -05:00
parent 32d165ec8f
commit ed92211680
534 changed files with 68563 additions and 19 deletions

87
src/libPIC/pwm.c Normal file
View File

@ -0,0 +1,87 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* PWM Output
*----------------------------------------------------------------------------
* Output PWM (8 bit resolution for now)
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "system.h"
#include "delay.h"
#include "pwm.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void PwmInit( void )
{
RC1 = RC2 = 0;
PR2 = 255; // max period
T2CON = 0b00000111; // 16:1 prescale
// PWM1
TRISC1 = 0;
CCPR1L = 0;
CCP1CON = 0b00001100;
// PMW2
TRISC2 = 0;
CCPR2L = 0;
CCP2CON = 0b00001100;
}
// duty cycle 0-PWM_DUTY_MAX (use macro)
void PwmOut( BYTE byPin, WORD wDuty )
{
// clip
if ( wDuty > PWM_DUTY_MAX )
wDuty = PWM_DUTY_MAX;
// allows custom rate for timer 2
if ( PR2 != 255 )
wDuty = wDuty * PR2 / PWM_DUTY_CYCLE;
// scale duty cycle
if ( byPin == 1 )
CCPR1L = wDuty;
if ( byPin == 2 )
CCPR2L = wDuty;
}