joergn
Joined: 15 Jul 2010 Posts: 15 Location: Hamburg Germany
|
18F45K22 ECCP unit problem |
Posted: Mon Jul 19, 2010 11:35 am |
|
|
Hi, does anybody tried the 18F45K22 ?
I am using the internal osc with PLL to obtain a 64Mhz clock without external resonator but my mute is meanwhile low, because I still have not managed to bring the ECCP unit in operation.......
I have PWM experience with the 18F4431, which has power PWM and a CCP
unit, so the setup_CCPx commands and set_pwm_dutyx(); I tried in the same way but no success so far.
I have the latest 4.109 compiler update.
The 18F45K22 has 5 CCPs which can be operated with 3 different timers,
or all at the same timer 2.
When I am trying to use the SETUP_CCPx command the CCP1 and
CCP2 compiles but SETUP_CCP3 leads to an error:
*** Error 12 "main.c" Line 83(15,16): Undefined identifier -- SETUP_CCP3
1 Errors, 0 Warnings.
After no succes with the inbuilt functions I tried it with the SFRs directly
like it was posted in the forum with a 18F8722.
My code is at the moment:
Code: | #include <18F45K22.h>
#device ICD=TRUE
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO // this is the internal OSC active
#FUSES NOPROTECT
#FUSES NOEBTRB
#FUSES NOEBTR
//#FUSES NOXINST
#FUSES NODELAYINTOSC
#FUSES NOWRTC
#use delay(clock=64Mhz ) // setting the high f works just here ;-)
#use rs232(baud=38400,xmit=PIN_C6 ,rcv=PIN_C7 , parity=N,bits=8) |
Code: |
#include <main.h>
// Define of PIN layout///////////////////////////////////
#define BATD 0 // AN0
#define TEMPERATUR 8 // AN8 ; ist jetzt digital configuriert
#define LED1 PIN_D4
#define RESERVE1 PIN_D0
#define RESERVE3 PIN_C5
#define MAXLOOPS 20;
//#define SELECT TRUE;
// MCU specific register definitions
#define PR2 0xFBB // Timer2 Period Register
#define PR4 0xF52 // Timer4 Period Register
#define PR6 0xF4B // Timer6 Period Register
#define CCPR1L 0xFBE // Capture/Compare/PWM Register 1, Low Byte
#define CCPR1H 0xFBF // Capture/Compare/PWM Register 1, High Byte
#define CCPR2L 0xF67 // Capture/Compare/PWM Register 1, Low Byte
#define CCPR2H 0xF68 // Capture/Compare/PWM Register 1, High Byte
#define CCPR3L 0xF5E // Capture/Compare/PWM Register 1, Low Byte
#define CCPR3H 0xF5F // Capture/Compare/PWM Register 1, High Byte
#define PWM1CON 0xFB7 // PWM Dead-Band Delay register,
#define PWM2CON 0xF65 // PWM Dead-Band Delay register,
#define PWM3CON 0xF5C // PWM Dead-Band Delay register,
#define CONFIG3H 0x300005 // MCLRE — P2BMX T3CMX HFOFST CCP3MX PBADEN CCP2MX "1011 1111"
#define TRISA 0xF92
#define TRISB 0xF93
#define TRISC 0xF94
#define TRISD 0xF95
#define TRISE 0xF96
#define CCP1CON 0xFBD // CCPx PIN CONFIGURATION CCP PRESCALER setting
#define CCP3CON 0xF5D
#define ECCP1 CCP1CON
#define ECCP1AS 0xFB6 // ENHANCED PWM AUTO-SHUTDOWN
#define ECCP3AS 0xF5B
#define CCPTMRS0 0xF49 // PWM TIMER SELECTION CONTROL REGISTER 0
#define CCPTMRS1 0xF48 // PWM TIMER SELECTION CONTROL REGISTER 1
void Initmcu(void)
{
setup_timer_0(T0_INTERNAL|T0_DIV_16);
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_4 );
setup_timer_2 ( T2_DIV_BY_1, 50, 1); // (mode, period, postscale) used by default as CCPx PWM base
setup_timer_3(T3_INTERNAL|T3_DIV_BY_2);
setup_timer_4 ( T4_DIV_BY_4, 0xc0, 2);
setup_timer_5 (T5_INTERNAL | T5_DIV_BY_2);
setup_timer_6 ( T6_DIV_BY_4, 0xc0, 2);
setup_comparator(NC_NC_NC_NC);
*TRISC = 0x00; //Set Port C to outputs. CCP1 and CCP2 are on PortC
*TRISE = 0x00; //Set Port E to outputs. CCP3 A and B are on PortE
//output_low(PIN_E0);
//output_low(PIN_E1);
//output_low(PIN_C2);
*CCPTMRS0 = 0x00; // all ECCP1,2,3 are operated with Timer2
//SETUP_CCP1(CCP_PWM);
*CCP1CON = 0x0E;
*CCP3CON = 0x0E;
//SETUP_CCP3(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_PWM_H_H);
*PR2 = 24; //Period = 4 * Tosc *(PR2+1) * TMR2Prescaler
//set_pwm1_duty(31);
//set_pwm3_duty(31);
//*PWM1CON = 0x03;
//*PWM3CON = 0x03;
*CCPR3L = 0x0C; // Duty cycle CCP3
*CCPR1L = 0x0C;
*ECCP1AS = 0x00;
*ECCP3AS = 0x00;
}
long mscounter;
long dutyc3;
void main()
{
mscounter=0;
dutyc3=230;
//setup_adc (ADC_CLOCK_DIV_64);
//setup_adc_ports( ALL_ANALOG|VSS_VDD );
Initmcu();
while(true)
{
//mscounter++;
//output_toggle(LED1);
//if(mscounter ==0)
output_high(RESERVE3);
delay_cycles(100);
//delay_us(1);
output_low(RESERVE3);
delay_us(1);
}
}
|
hoping for some hints and best Regards
Hi I meanwhile tracked down the reason: timer2 is not running after the setup_timer_2 command.
So after turning on by SFR programming: *T2CON = 0x05;
it worx.
It seems as if the chip is not yet supported with all the commands.
Code: | void Initmcu(void)
{
delay_ms(10);
setup_timer_0(T0_INTERNAL|T0_DIV_16);
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 );
//setup_timer_2 ( T2_DIV_BY_1,127, 1 ); // (mode, period, postscale) used by default as CCPx PWM base
*T2CON = 0x05; // activates timer2 directly !!!!!!
//set_timer2(0);
setup_timer_3 (T3_DIV_BY_2);
setup_timer_4 ( T4_DIV_BY_4, 0xc0, 2);
setup_timer_5 (T5_INTERNAL | T5_DIV_BY_2);
setup_timer_6 ( T6_DIV_BY_4, 0xc0, 2);
setup_comparator(NC_NC_NC_NC);
*TRISC = 0x00; //Set Port C to outputs. CCP1 and CCP2 are on PortC
*TRISE = 0x00; //Set Port E to outputs. CCP3 A and B are on PortE
*CCPTMRS0 = 0x00; // all ECCP1,2,3 are operated with Timer2
//SETUP_CCP1(CCP_PWM);
*CCP1CON = 0x0E;
*CCP3CON = 0b10001100; //
//SETUP_CCP3(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_PWM_H_H);
*PR2 = 80; //Period = 4 * Tosc *(PR2+1) * TMR2Prescaler 50kHz
//set_pwm1_duty(31);
//set_pwm3_duty(31);
//*PWM1CON = 0x03;
*PWM3CON = 0x03;
*CCPR3L = 40; // Duty cycle CCP3 50%
*CCPR1L = 0x0C; // Duty cycle CCP1
*ECCP1AS = 0x00;
*ECCP3AS = 0x05;
//output_high(PIN_E0);
//output_high(PIN_E1);
//output_low(PIN_C2);
}
|
;-O |
|