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;
}
PWM in ATTiny48 :? :?
- biljana.nedeljkovic
- mikroElektronika team
- Posts: 1043
- Joined: 30 Jun 2015 15:15
Re: PWM in ATTiny48 :? :?
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
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
Re: PWM in ATTiny48 :? :?
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
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
- biljana.nedeljkovic
- mikroElektronika team
- Posts: 1043
- Joined: 30 Jun 2015 15:15
Re: PWM in ATTiny48 :? :?
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
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