Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
#include "sys/atmega168.h"#include "servos.h"#include "a2d.h" // Define two light sensors connected to ADC channels 0 and 1#define sensorLeft ADC_NUMBER_TO_CHANNEL(5)//#define sensorRight ADC_NUMBER_TO_CHANNEL(1) // Define two servosSERVO left = MAKE_SERVO(FALSE, D0,1500, 500);SERVO right = MAKE_SERVO(TRUE , D1,1500, 500); // Create the list - remember to place an & at the// start of each servo nameSERVO_LIST servos[] = {&left,&right}; // Create a driver for the list of servosSERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servos); //the larger this number, the more likely your robot will drive straight //#define threshold 8 // In my initialising code - pass the list of servos to controlvoid appInitHardware(void){ // Initialise the servo controller servoPWMInit(&bank1); // Give each servo a start value of 'stop' act_setSpeed(&left, 0); act_setSpeed(&right,0);}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;} // This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ //uint8_t lightLeft = a2dConvert8bit(sensorLeft); //if(lightLeft < 100000) //{ act_setSpeed(&left, 20); act_setSpeed(&right,-50); //} return 20000; // wait for 20ms to stop crazy oscillations}
how can you tell from the datasheet, which pins support hardware PWM and which dont?
even though my voltmeter reads a range of 5v, the values range from 65 ~ 150 only.
#include "sys/atmega168.h"#include "a2d.h"#define sensorLeft ADC_NUMBER_TO_CHANNEL(0)uint8_t EEMEM myVar[500];float Divide = 1.0;int Looping = 1;int Delay = 1;int loop = -1;// In my initialising code - pass the list of servos to controlvoid appInitHardware(void){ //Irrelevant code here}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;} // This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ if (Looping < 200) { Divide = a2dConvert8bit(sensorLeft); eeprom_write_byte(&myVar[Looping], Divide); Looping++; } pin_high(B1); delay_cycles(50000); pin_low(B1); loop++; Delay = 1000 * Divide; delay_cycles(Delay); return 2000; // wait for 20ms to stop crazy oscillations}
In the example above, the LED flashing time is meant to vary with the potentiometer.
#include "sys/atmega168.h"#include "a2d.h"#define sensorLeft ADC_NUMBER_TO_CHANNEL(0)uint8_t EEMEM myVar[500];float Divide = 1.0;uint32_t Delay = 1;int Looping = 0;// In my initialising code - pass the list of servos to controlvoid appInitHardware(void){ pin_make_output(B1); pin_make_output(B2); while (Looping < 500) { eeprom_write_byte(&myVar[Looping], 0); Looping++; } Looping = 0;}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;} // This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ if (Looping < 200) { pin_high(B2); Divide = a2dConvert8bit(sensorLeft); eeprom_write_byte(&myVar[Looping], Divide); Looping++; delay_cycles(500); pin_low(B2); } pin_high(B1); delay_cycles(5000); pin_low(B1); if (Divide > 100) { Delay = 100000 * (Divide - 100); } else { Delay = 100000; } delay_cycles(Delay); return 20; // wait for 20ms to stop crazy oscillations}
#include "sys/atmega168.h"#include "a2d.h"#define sensorLeft ADC_NUMBER_TO_CHANNEL(0)uint8_t EEMEM myVar[250];uint8_t Divide = 1.0;//uint32_t Delay = 1;int Looping = 0;// In my initialising code - pass the list of servos to controlvoid appInitHardware(void){ pin_make_output(B1); pin_make_output(B2); pin_high(B1); while (Looping < 250) { eeprom_write_byte(&myVar[Looping], 0); Looping++; } Looping = 0; pin_low(B1);}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;} // This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ if (Looping < 200) { pin_high(B2); Divide = a2dConvert8bit(sensorLeft); eeprom_write_byte(&myVar[Looping], Divide); Looping++; delay_cycles(5000); pin_low(B2); } pin_high(B1); delay_cycles(5000); pin_low(B1); delay_cycles(100000); return 1; // wait for 20ms to stop crazy oscillations}
.... the only thing i can think of would be the software, maybe the registers are incorrectly set.....