[ Log In ]
Image of the Atmega324p

Atmega324P

$8.50
Qty:
USB AVR programmer

USB AVR Programmer

$9.95
Qty:
Breadboard adapter for the USBasp AVR Programmer

USBasp Breadboard Breakout Adapter

$4.90
Qty:
Serial to USB converter with Micro USB cable

USB to Serial Converter

$10.95
Qty:
Thumbnail: Crystal Oscillator 18.432 MHz for UART

18.432 MHz Crystal Oscillator 18pf 30ppm

$0.94
Qty:
Thumbnail: 22 pF Capacitor

22 pF Multilayer Ceramic Capacitor

$0.43
Qty:
Thumbnail: Quartz crystal oscillator - 16 MHz

16 MHz Crystal Oscillator 20 pF Through Hole

$0.75
Qty:
Thumbnail: 4x4 keypad top view.

4x4 Keypad with Adhesive Backing

$3.80
Qty:
Thumbnail: quad buffer line driver 74HC126E

Quad Buffer Line Driver (Through Hole)

$0.69
Qty:
3 pin slide switch

SPDT Slide Switch 3 pin 30V

$1.49
Qty:

Programming: Outputting a PWM (Pulse Width Modulation) on More Than One Pin of the AVR Microcontroller and Multiple Ports

Important aspects of outputting to more than one pin are as follows:

- Make sure the pins that will output the PWM are set for output data direction (i.e. DDRB = 0xFF for all PORT B pins output)

- Make sure that the pins will be set high in the interrupt service routine (ISR)

- Add another line within code block of the if (TCNT1>=800 && TCNT1<=2400) and make sure the pin reflect the correct output pin and the number after the TCNT1 >= value is correctly set for the position for that servo on that pin.
#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
{
DDRA |= 0xFF;
DDRB |= 0xFF;
DDRD |= 0xFF;

TCCR1A |= 1<<WGM11;
TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10;
TIMSK1 |= 1<<OCIE1A;

sei();

ICR1 = 19999;


while(1)
{
if (TCNT1 > 700 && TCNT1 < 2500)
{
if (TCNT1 >= 2200 && bit_is_set(PORTA,PINA0)) PORTA &= ~(1<<PINA0);
if (TCNT1 >= 900 && bit_is_set(PORTA,PINA1)) PORTA &= ~(1<<PINA1);
if (TCNT1 >= 1200 && bit_is_set(PORTA,PINA2)) PORTA &= ~(1<<PINA2);
if (TCNT1 >= 2000 && bit_is_set(PORTA,PINA3)) PORTA &= ~(1<<PINA3);
if (TCNT1 >= 2200 && bit_is_set(PORTA,PINA4)) PORTA &= ~(1<<PINA4);
if (TCNT1 >= 900 && bit_is_set(PORTA,PINA5)) PORTA &= ~(1<<PINA5);
if (TCNT1 >= 1200 && bit_is_set(PORTA,PINA6)) PORTA &= ~(1<<PINA6);
if (TCNT1 > 2000 && bit_is_set(PORTA,PINA7)) PORTA &= ~(1<<PINA7);

if (TCNT1 >= 2200 && bit_is_set(PORTB,PINB0)) PORTB &= ~(1<<PINB0);
if (TCNT1 >= 900 && bit_is_set(PORTB,PINB1)) PORTB &= ~(1<<PINB1);
if (TCNT1 >= 1200 && bit_is_set(PORTB,PINB2)) PORTB &= ~(1<<PINB2);
if (TCNT1 >= 2000 && bit_is_set(PORTB,PINB3)) PORTB &= ~(1<<PINB3);
if (TCNT1 >= 2200 && bit_is_set(PORTB,PINB4)) PORTB &= ~(1<<PINB4);
if (TCNT1 >= 900 && bit_is_set(PORTB,PINB5)) PORTB &= ~(1<<PINB5);
if (TCNT1 >= 1200 && bit_is_set(PORTB,PINB6)) PORTB &= ~(1<<PINB6);
if (TCNT1 > 2000 && bit_is_set(PORTB,PINB7)) PORTB &= ~(1<<PINB7);

if (TCNT1 >= 2200 && bit_is_set(PORTD,PIND0)) PORTD &= ~(1<<PIND0);
if (TCNT1 >= 900 && bit_is_set(PORTD,PIND1)) PORTD &= ~(1<<PIND1);
if (TCNT1 >= 1200 && bit_is_set(PORTD,PIND2)) PORTD &= ~(1<<PIND2);
if (TCNT1 >= 2000 && bit_is_set(PORTD,PIND3)) PORTD &= ~(1<<PIND3);
if (TCNT1 >= 2200 && bit_is_set(PORTD,PIND4)) PORTD &= ~(1<<PIND4);
if (TCNT1 >= 900 && bit_is_set(PORTD,PIND5)) PORTD &= ~(1<<PIND5);
if (TCNT1 >= 1200 && bit_is_set(PORTD,PIND6)) PORTD &= ~(1<<PIND6);
if (TCNT1 > 2000 && bit_is_set(PORTD,PIND7)) PORTD &= ~(1<<PIND7);
}
}
}

ISR(TIMER1_COMPA_vect)
{
PORTA = 0xFF;
PORTB = 0xFF;
PORTD = 0xFF;
}

Comments and Additional Information

Have some code to share? Or additional information? Respond here:

You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.

Description:

Code (optional):