Hi,
How can I use only OC0B output with my atmega88?
The lib. work fine with 0C0A but and I don't found doc or sample...
Regards
Stéf.
PWM Lib. on OC0B with ATMEGA 88 or other
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: PWM Lib. on OC0B with ATMEGA 88 or other
Hi,
Please, take a look at ATmega88 Datasheet:
http://www.atmel.com/Images/doc2545.pdf
OC0B (Timer/Counter0 output compare match B output) - PD5 pin
OC0A (Timer/Counter0 output compare match A output) - PD6 pin
Also, you can take a look at PWM example from compiler:
...\mikroPascal PRO for AVR\Examples\Internal MCU modules\ATmega16\PWM
The example is written for ATmega16, but with the help of datasheet,
you can try to adjust the example for controller that you use.
Best regards,
Marina
Please, take a look at ATmega88 Datasheet:
http://www.atmel.com/Images/doc2545.pdf
OC0B (Timer/Counter0 output compare match B output) - PD5 pin
OC0A (Timer/Counter0 output compare match A output) - PD6 pin
Also, you can take a look at PWM example from compiler:
...\mikroPascal PRO for AVR\Examples\Internal MCU modules\ATmega16\PWM
The example is written for ATmega16, but with the help of datasheet,
you can try to adjust the example for controller that you use.
Best regards,
Marina
Re: PWM Lib. on OC0B with ATMEGA 88 or other
Thank you marina but where do you see other port in code?
On my hardware, I have an LED on PD6 and transistor PD5.
PWM must be on PD5 and not PD6 for me...
Regard
(sorry for my english)
Code: Select all
program PWM_Test;
var current_duty : byte;
current_duty1 : byte;
begin
DDB0_bit := 0; // Set PORTB pin 0 as input
DDB1_bit := 0; // Set PORTB pin 1 as input
DDC0_bit := 0; // Set PORTC pin 0 as input
DDC1_bit := 0; // Set PORTC pin 1 as input
current_duty := 16; // initial value for current_duty
current_duty1 := 16; // initial value for current_duty
DDB3_bit := 1; // Set PORTB pin 3 as output pin for the PWM (according to datasheet)
DDD7_bit := 1; // Set PORTD pin 7 as output pin for the PWM1 (according to datasheet)
PWM1_Init (_PWM1_FAST_MODE, _PWM1_PRESCALER_8, _PWM1_NON_INVERTED, 16);
PWM2_Init(_PWM2_FAST_MODE, _PWM2_PRESCALER_8, _PWM2_NON_INVERTED, 16);
while TRUE do // Endless loop
begin
if (PINB0_bit <> 0) then
begin // Detect if PORTB pin 0 is pressed
Delay_ms(40); // Small delay to avoid deboucing effect
Inc(current_duty); // Increment duty ratio
PWM1_Set_Duty(current_duty); // Set incremented duty
end
else
if (PINB1_bit <> 0) then // Detect if PORTB pin 1 is pressed
begin
Delay_ms(40); // Small delay to avoid deboucing effect
Dec(current_duty); // Decrement duty ratio
PWM1_Set_Duty(current_duty); // Set decremented duty ratio
end
else
if (PINC0_bit <> 0) then // Detect if PORTC pin 0 is pressed
begin
Delay_ms(40); // Small delay to avoid deboucing effect
Inc(current_duty1); // Increment duty ratio
PWM2_Set_Duty(current_duty1); // Set incremented duty
end
else
if (PINC1_bit <> 0) then // Detect if PORTC pin 1 is pressed
begin
Delay_ms(40); // Small delay to avoid deboucing effect
Dec(current_duty1); // Decrement duty ratio
PWM2_Set_Duty(current_duty1); // Set decremented duty ratio
end;
end;
end.
PWM must be on PD5 and not PD6 for me...
Regard
(sorry for my english)
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: PWM Lib. on OC0B with ATMEGA 88 or other
Hi,
The project/code in our compiler on which I referred you to is written for ATmega16.
On ATmega16, OC0 is on PB3 pin and OC1 is on PD7 pin:
The example changes PWM duty ratio on pins PB3 and PD7 continually.
So you need to take a look at datasheet of your device to see which pins you can use for PWM.
Best regards,
Marina
The project/code in our compiler on which I referred you to is written for ATmega16.
On ATmega16, OC0 is on PB3 pin and OC1 is on PD7 pin:
Code: Select all
DDB3_bit := 1; // Set PORTB pin 3 as output pin for the PWM (according to datasheet)
DDD7_bit := 1; // Set PORTD pin 7 as output pin for the PWM1 (according to datasheet)
So you need to take a look at datasheet of your device to see which pins you can use for PWM.
Best regards,
Marina
Re: PWM Lib. on OC0B with ATMEGA 88 or other
For ATMEGA88 it'smarina.petrovic wrote: OC0B (Timer/Counter0 output compare match B output) - PD5 pin
OC0A (Timer/Counter0 output compare match A output) - PD6 pin
OC0A (Timer/Counter0 output compare match A output) - PD5 pin
OC0B (Timer/Counter0 output compare match B output) - PD6 pin
It's ok for OC0A and don't work for OC0Bmarina.petrovic wrote: The project/code in our compiler on which I referred you to is written for ATmega16.
On ATmega16, OC0 is on PB3 pin and OC1 is on PD7 pin:
Code: Select all
DDB3_bit := 1; // Set PORTB pin 3 as output pin for the PWM (according to datasheet)
DDD7_bit := 1; // Set PORTD pin 7 as output pin for the PWM1 (according to datasheet)
The example changes PWM duty ratio on pins PB3 and PD7 continually.
I try this with an easyAVR5 board and ATMEGA164PA :
Code: Select all
current_duty := 16; // initial value for current_duty
current_duty1 := 16; // initial value for current_duty
DDB4_bit := 1; // Set PORTB pin 4 as output pin for the PWM0 (according to datasheet) (OC0B)
DDD6_bit := 1; // Set PORTD pin 6 as output pin for the PWM1 (according to datasheet) (OC1B)
PWM1_Init (_PWM1_FAST_MODE, _PWM1_PRESCALER_8, _PWM1_NON_INVERTED, 16);
PWM2_Init(_PWM2_FAST_MODE, _PWM2_PRESCALER_8, _PWM2_NON_INVERTED, 16);
Regards
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: PWM Lib. on OC0B with ATMEGA 88 or other
Hi,
Like I already mention, the project in our compiler on which I referred you to is written for ATmega16
I referred to the project as an example that might help.
Please, can you try to use PB3 pin for OC0B on your ATMEGA164PA that you mention that you have?
Best regards,
Marina
Like I already mention, the project in our compiler on which I referred you to is written for ATmega16
I referred to the project as an example that might help.
Please, can you try to use PB3 pin for OC0B on your ATMEGA164PA that you mention that you have?
Best regards,
Marina
Re: PWM Lib. on OC0B with ATMEGA 88 or other
PB3 is OC0A and PB4 is OC0Bmarina.petrovic wrote:Please, can you try to use PB3 pin for OC0B on your ATMEGA164PA that you mention that you have?
I already tried with PB4.
Regard