Fellas
I have just hooked up my new babyO328, I would like to use as much as the exiting code as i did with the BabyO168
however I am getting code errors. I have updated the linked library to Atmega328p, I have changed the Device to baby328p, and when i compile i get 5 errors on pins that were previous defined under the old 168 library, here is my full code, and the errors.
#include <avr/io.h>
#define F_CPU 20000000 // system clock is 20 MHz
#include <util/delay.h> // uses F_CPU to achieve us and ms delays
#include <pololu/orangutan.h>
#define SERMI 1500
#define SERHI 2000
#define SERLO 650
// delay for time_ms milliseconds by looping
// time_ms is a two-byte value that can range from 0 - 65535
// a value of 65535 (0xFF) produces an infinite delay
void delay_ms(unsigned int time_ms)
{
// _delay_ms() comes from <util/delay.h> and can only
// delay for a max of around 13 ms when the system
// clock is 20 MHz, so we define our own longer delay
// routine based on _delay_ms()
unsigned int i;
for (i = 0; i < time_ms; i++)
_delay_ms(1);
}
// flashing LED signals round is packed and ready to fire
void TurnOnLED()
{
int count;
for (count=0; count < 5; count++)
{
PORTD |= 1 << PD1; // LED on
delay_ms( 50 );
PORTD &= ~( 1 << PD1 ); // LED off
delay_ms( 800 );
}
}
void MoveServos()
{
// Slowly move the servo to position 1800.
set_servo_speed(0, 100);
set_servo_target(0, SERHI);
delay_ms(3000);
set_servo_speed(1, 75);
set_servo_target(1, 700);
delay_ms(2050);
// Make the servo move back to position 1300 as fast as possible.
set_servo_speed(0, 100);
set_servo_target(0, SERLO);
delay_ms(3000);
set_servo_speed(1, 120);
set_servo_target(1, SERMI);
delay_ms(1050);
}
int main()
{
unsigned char PROC_CTL = 0;
const unsigned char ServoArr[] = {IO_D0, IO_C0, IO_C1};
// servo signal pin assignment PD0, PC0, PC1
servos_init(ServoArr, sizeof(ServoArr));
set_servo_target(0, SERLO); // Make the servo 0 go to a neutral position
set_servo_target(1, SERMI); // Make the servo 1 go to a neutral position
DDRD |= 1 << PD1; // set LED pin PD1 to output, PD1 reserved for user LED
PORTC &= ~(1 << 3); // drive PC3 low
while (1)
{
while (!(PINC & (1 << PC3))); // Wait for PC3 to go high. ( channel 5 will activate )
delay_us(1450); // delay 1.45 ms
if ((PINC & (1 << PC3))) // Test to see if PC3 is still high
{
// The pulse is longer than 1.45 ms
if (PROC_CTL == 1)
{
MoveServos();
TurnOnLED(); // make LED blink: display armed signal
PROC_CTL=0;
}
}
else PROC_CTL=1;
while ((PINC & (1 << PC3))); // Wait for PC3 to go Low
}
return 0;
}
errors
rm -rf PulseMotorCtrl.o PulseMotorCtrl.elf dep/* PulseMotorCtrl.hex PulseMotorCtrl.eep PulseMotorCtrl.lss PulseMotorCtrl.map
Build succeeded with 0 Warnings...
avr-gcc.exe -mmcu=atmega328p -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT PulseMotorCtrl.o -MF dep/PulseMotorCtrl.o.d -c ../PulseMotorCtrl.c
../PulseMotorCtrl.c: In function 'TurnOnLED':
../PulseMotorCtrl.c:32: error: 'PD1' undeclared (first use in this function)
../PulseMotorCtrl.c:32: error: (Each undeclared identifier is reported only once
../PulseMotorCtrl.c:32: error: for each function it appears in.)
../PulseMotorCtrl.c: In function 'main':
../PulseMotorCtrl.c:72: error: 'PD1' undeclared (first use in this function)
../PulseMotorCtrl.c:78: error: 'PC3' undeclared (first use in this function)
make: *** [PulseMotorCtrl.o] Error 1
Build failed with 5 errors and 0 warnings...
Please Advise
Dave