HiI'm trying TIM1 as an up-counter, and want to vary the duty cycle on my 
custom board where GPIO C7 (TIM1Ch2) - initialized as a push pull o/p, and 
connected to an LED to ground  - is the pin I have to use for this.
I'm Looking for a good source to understand the set up sequences and values, 
since I am going bit banging.
The SPL example does not mention anything about changing the values of the 
option bytes, but I see that in my STM8S003F3P6 chip(20 pin tssop) I need to 
set the AFR0 bit of OPT2 (as well as NOPT2) to use the TIM1Ch2 alternate 
function. My master clock is HSI at 16MHz.
Am I on the right track? 
If not, please give some pointers to where I can get the whole info on setting 
up TIM1. The O/P remains at 0V, though the code where the duty cycle is 
supposed to vary is running, and the duty cycle  variable varies. I use an led 
blinking at different rates to tell me where the code is running, and an LCD to 
display the contents of the variables, since I have not been able to get the 
hang of debugging SDCC generated code with ST-Link V2
Your help is appreciated.

I've tried to use the SPL code (the example SPL code) as much as possible, 
modified for my card, and since I'm using SDCC, I removed the enums statements, 
and instead defined the values wherever needed.

This is the code I use to initialize TIM1:
#define P6_OPT2     0x4803#define P6_NOPT2    0x4804#define P6_AFR0     0x01
 period=maxduty;
 duty=period/2; 
  TIM1_DeInit(); TIM1_TimeBaseInit(100, TIM1_COUNTERMODE_UP, period, 0); 
TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, 
TIM1_OUTPUTNSTATE_DISABLE, duty,    TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_LOW, 
TIM1_OCIDLESTATE_RESET,     TIM1_OCNIDLESTATE_SET);
  /* TIM1 counter enable */ TIM1_Cmd(ENABLE);
 /* TIM1 Main Output Enable */ TIM1_CtrlPWMOutputs(ENABLE);  _SFR_(P6_OPT2) |= 
P6_AFR0; _SFR_(P6_NOPT2) &= ~P6_AFR0;

  if(!runup) { duty+=10; LEDSpeed=3;            //blink red LED fast in 
interrupt SLCD_Position(1,0); SLCD_PrChar('U'); } else  { duty-=10; LEDSpeed=2; 
       //blink red LED slow in interrupt SLCD_Position(1,0); SLCD_PrChar('D'); 
} PC_ODR ^= (1 << LO_PIN); //Set LED ON        //toggle green LED
 if(duty>= period) { duty=period; runup=1; } if(duty<=0) { duty=0; runup=0; } 
SLCD_Position(1,8); SLCD_PrHexInt(duty); TIM2_CCR2H =  duty >>8; TIM2_CCR2L =  
duty; 







Thanks and Warm Regards
Shiv



_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to