Ture: Wow, 10K of the 32k just for one PWM and not much else!
My program uses 2PWM, 6 A2D channels, Rotary Encoder (3-wire), IC2, LCD interface (4 PORTB bits), One moment. Sw, two debug bits, a diagnostic LED[/size]
Can anyone tell me: What would this same config take in terms of program mem on a PSoC4?
My current project can configure two 16F88x PWM1 and PWM2 takes exactly145-bytes of program mem.
Actual total code shown below to config and control 2 PWMs: THIS CODE COMPILES SUCCESSFULLY
//---------------------------------------------------------------------------
#include <htc.h>
__CONFIG(0x20F2);//CONFIG word 1 bit5=MCLRE=1=RESET PIN1, bit14,15 not used
//BOREN=SW CTRL bit12=LVP=0 HV programming
//SBOREN SW CTRLD bit2:0 are OscType 010 for 20MHz Xtal
__CONFIG(0x3FFF);//CONFIG word 2 //LVBOREN BOR3V Enabled <2.1V BOR
static unsigned int DCyc,DCyc1;
void PWM1Setup(void);
void PWM2Setup(void);
interrupt int_server(void)
{
if (T0IF) // TMR0 overflow flag, if set triggers IRQ TMR0Clk=Clk/2
{ TMR0=17; //Comp needed for 4Mhz, calibrates timer for 1uS/IRQ.
T0IF=0; //12 inst cycles IRQ Dly +5 cyles for tot=250 counts/IRQ x2uS
XitTimer:;
} //------------------------------------------------
//SetDuCy:
CCPR1L=(DCyc>>2);
CCP1X=(DCyc & 2)==2; //bit1 of PWM (LSB 1)
CCP1Y=(DCyc&1); //bit0 of PWM (LSB 0), 1024 duty cycle values
CCPR2L=(DCyc1>>2);
CCP2X=(DCyc1 & 2)==2; //bit1 of PWM (LSB 1)
CCP2Y=(DCyc1&1); //bit0 of PWM (LSB 0), 1024 duty cycle values
}//-----end of Interrupt Handler---------------------------------------
//-------------------------------------------------------------------------
void main(void)
{
Resetit:;
INTCON = 0; // Interrupts disabled
TRISC =0xB8; // UART TXD=RC6 input, RXD=RC7,RC5 for ROTENC
// RC3,4 for i2c cbit3, cbit4 will be used for i2c
// i2c Clock cbit3 held low until ready, i2cinit() to receive
// roten lines cbit5 cbit7 are high and ready
//cbit1, cbit2 setup for PWM
OPTION_REG=0x80; // div by 2 TMR0 prescaler. Turnoff weak pullups B0-B7
T0IE=1; // Enable TMR0 rollover IRQ
TMR0=0; // Must be set in IRQ routine for 100-uS IRQ's 20-Mhz Xtal
T1CKPS0=1; // Set TMR1 prescaler to div. by 8
T1CKPS1=1; // 0x03 = div. by 8 for 1.6uS counts with 20-MHz Xtal
TMR0=0; // Reset each IRQ, correction for 100-uS IRQ's with 20-Mhz Xtal
TMR1ON=0; // Disable TMR1 until started in IRQ routine
PEIE=1; // Must be 1 for ADIE(or any peripheral IRQ to be enabled)
GIE=1; // Global enable all unmasked IRQs
PWM1Setup();
PWM2Setup();
start:; //--------------------- START ------------------------------
DCyc1=500;
DCyc=500;
goto start;
} // ============== end of main() =================
//==== PWM setup CCP1 cbit2 ====
void PWM1Setup(void) //CCP1 output cbit2 PWM setup
{
CCP2IE=0;
CCPR2H=0;
CCPR2L=0;
TMR1IE=0; // Disable TMR1 IRQ's
TMR1IF=0;
TMR2IE=0;
TMR2IF=0;
T2CON=0b00000000;
PR2=0xFF; //19.53KHz 20Mhz Highest PWM freq for 10-Bit Resolution
TMR2ON=1; //Turn on TMR2 used for duty cycle period
CCP1CON=0b00001100; //Turn on PWM mode 0 Duty Cycle
}
//==== End of PWM1Setup ====
//--------------------------------------------------------------------------
void PWM2Setup(void) //CCP2 cbit1 setup
{
CCP2CON=0b00001100; //Turn on CCP2 PWM mode with 0 Duty Cycle
}
//==== End of PWM2Setup ====