Joe G
Member
I've been trying to get my pwm eccp P1A, P1B pins to output pwm. Also trying to get ccp2 and ccp3 to output a pwm. All I can get to output a pwm signal is the P1A and the ccp2 pins, I was able to get all the pwm outputs on a PIC18F45K20 to simulat on MPLAB's sim. but for the last 10 days I couldn't get the same to operate or simulate with the PIC18f46k80. Maybe I missed something or the 'sims' won't work with this chip. thanks for any and all help. I've also moved on from Ass'y to learning C18 so I'm a bit new w/ the C language.
Code:
/* PIC18F46K80 44pin */
/** C O N F I G U R A T I O N B I T S ******************************/
//#pragma config SOSCSEL = DIG //turn off sosc
#pragma config IESO = OFF, FOSC = INTIO2 // CONFIG1H
#pragma config BOREN = OFF // CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = OFF // CONFIG3H
#pragma config STVREN = OFF, XINST = OFF // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // CONFIG5L
#pragma config CPB = OFF, CPD = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // CONFIG7L
#pragma config EBTRB = OFF // CONFIG7H
/** I N C L U D E S **************************************************/
#include <p18F46K80.h>
#include <timers.h> // header file
#include <math.h>
#include <delays.h>
#include <capture.h> // header file
#include <pwm.h> // header file
/** V A R I A B L E S *************************************************/
// declare constant data in program memory starting at address 0x180
#pragma idata
//unsigned char reg_read = 0;
#pragma udata // declare statically allocated uinitialized variables
void InterruptServiceHigh ();
void InterruptServiceLow ();
unsigned long range, n;
unsigned char loc, front, ForB;
int long zone;
/** I N T E R R U P T S ***********************************************/
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
_asm
goto InterruptServiceHigh //jump to interrupt routine
_endasm
}
#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow (void)
{
_asm
goto InterruptServiceLow //jump to interrupt routine
_endasm
}
//** D E C L A R A T I O N S *******************************************/
#pragma code // declare executable instructions
void PING();
void rotate();
void go_frt();
void go_bk();
void set_pole();
//===========================================================================
void main (void)
{
CM1CON = 0;
CM2CON = 0;
ADCON0 = 0;
ANCON0 = 0;
ANCON1 = 0;
ADCON1 = 0;
CCP1CON=0;
CCP2CON=0;
CCP3CON=0;
CCP4CON=0;
LATA = 0;
LATB = 0;
LATC = 0;
LATD = 0;
LATE = 0;
TRISA= 0; //A6,A7 =fwd, rev. A5=turbo(npn)
TRISB= 0b00001111; //B0,1,2,3 = bumpers; B5,6=
TRISC= 0; //C0, C1 steering incoder; C2,6=steering; C7=PING; C4,5=sonar incoders
TRISD= 0; //D7=IR-REC; D0,1= steering limit sw's
TRISE= 0; //E0=sonar and stuff FET,
ODCON = 0;
CCPR1L = 0;
CCPR1H = 0;
CCPR2L = 0;
CCPR2H = 0;
CCPR3L = 0;
CCPR3H = 0;
PR2 = 250;
PR4 = 250;
CCPR1L = 125;
CCPR2L = 80;
CCPR3L = 80;
T1CON = 0b00000001;
T2CON = 0b00000100;
T4CON = 0b00000100;
//TRISCbits.TRISC7 = 1; // D7 = ccp4
INTCON = 0b11000000;
INTCON2 = 0b00000000;
//INTCON3 = 0b00111000; //portb ext ie b0,1,2,3 falling edge
CCPTMRS = 0b00000110; //timer allocations for ccp's
CCP1CON = 0b00001100; //tmr1 D4 P1B =right turn sonar, D5 P1A =left turn sonar
CCP2CON = 0b00001100; // pwm RC2 tmr2 C2 //steering
CCP3CON = 0b00001100; // pwm RC6 tmr2 C6 //steering
PSTR1CON = 0b00000010; //P1B =right turn sonar
//CCP4CON = 0b00000100; //ccp4 falling edge tmr1 C7
CCPR2L = 0;
CCPR2H = 0;
PR2 = 250;
T1CON = 0b00110001;
T2CON = 0b00000100;
TRISCbits.TRISC1 = 1;
CCPR1L = 200;
CCPR1H = 0;
//set_pole(); //set loc for org stepper pole loc
while(1)
{
while(! PIR1bits.TMR1IF==1);
{
//rotate();
PIR1bits.TMR1IF=0;
TMR1H=0;
TMR1L=0;
// LATDbits.LATD6=~LATDbits.LATD6;
CCPR1L +=50;
if(CCPR1L>=201)
{ CCPR1L=0;
Delay1KTCYx(5);
PSTR1CONbits.STRA=~PSTR1CONbits.STRA;
PSTR1CONbits.STRB=~PSTR1CONbits.STRB;
PSTR1CONbits.STRC=~PSTR1CONbits.STRC;
}
}
}
}//main
Last edited: