PWM in ATTiny48 :? :?

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
anu007
Posts: 5
Joined: 09 Sep 2015 06:16

PWM in ATTiny48 :? :?

#1 Post by anu007 » 19 Sep 2015 11:40

Hello frndzz im working on project I want to turn on PWM accoding to the ADC value but the code does not generate any PWM signal.

PORTB.B5 = 0;

if(adc_bsens > 307 ) //for battery power more then 45%
{
PORTB.B4 = 1;
PWM16bit_Start(_TIMER1_CH_A);

past=adc_bsens;
current_duty=past;
PWM16bit_Change_Duty(current_duty, _TIMER1_CH_A);

}

else //for battery less then 30%
{
PWM16bit_Stop(_TIMER1_CH_A );

PORTB.B3 = 1;
}

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: PWM in ATTiny48 :? :?

#2 Post by biljana.nedeljkovic » 21 Sep 2015 11:37

Hello,

please take a look at the library in the compiler. I don't know if you have sent me the whole PWM routine you have written. but you have to initialize PWM first.

You have it explained in here:
http://www.mikroe.com/download/eng/docu ... ibrary.htm

Best regards,
Biljana

anu007
Posts: 5
Joined: 09 Sep 2015 06:16

Re: PWM in ATTiny48 :? :?

#3 Post by anu007 » 21 Sep 2015 20:00

Hyyy...

char current_duty;
void main()
{
PWM16bit_Init(_PWM16_PHASE_CORRECT_MODE_10BIT, _PWM16_PRESCALER_16bit_8, _PWM16_NON_INVERTED, 255,1);

current_duty = 255;

DDRB.B0 = 1; //pwm
DDRD.B7=0;
DDRD.B0=0;


do {

if(PIND.B0) // Detect if PORTD pin 0 is pressed
{
PWM16bit_Start(_TIMER1_CH_A );
current_duty=155;
PWM16bit_Change_Duty(current_duty, _TIMER1_CH_A); }
else{

PWM16bit_Stop(_TIMER1_CH_A );
}
while(1); // Endless loop

}


this is the real code when i press D0 the PWM does not stop.
I want if I press button PWM start and is I release it PWM stop

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: PWM in ATTiny48 :? :?

#4 Post by biljana.nedeljkovic » 30 Sep 2015 15:58

Hello,

please take a look at our button function, maybe you can use that to manage debounce.

Also double check the initialization to fit the specifications of your microcontroller.

Best regards,
Biljana

Post Reply

Return to “mikroC PRO for AVR General”