Go Down

Topic: Disabling attiny45 Clock Divide (CKDIV8) using arduinoISP + AVRDude (Read 12155 times) previous topic - next topic

Coding Badly

#30
Nov 20, 2011, 10:09 am Last Edit: Nov 20, 2011, 10:12 am by Coding Badly Reason: 1

Unfortunately, the Servo8Bit author assumed timer 0 is in the default state from reset / power-up.

Try this...

 • Locate the core_build_options.h file in the Tiny Core.  

 • Open the core_build_options.h file using your favourite text / source editor.  

 • Locate INITIALIZE_SECONDARY_TIMERS.  

 • Change the line of code to this (basically, change the one to a zero)...

    #define INITIALIZE_SECONDARY_TIMERS               0

 • Save core_build_options.h and close the editor.  

 • If the Arduino IDE is running, close and restart it.  

 • Upload your sketch.

lyron

Thanks again for your help,

but no: changed the 0 to a 1 and it still just writes one position (either 0 or 180) to the servo and nothing else..

Erni


You could try the SoftwareServo.
I have tried it with success on am attiny85 running 8mhz


lyron

@Ernie

What code did you exactly use? i'm trying to get softwareservo to work but it compiles and programs the chip but when i hook up a servo nothing happens :S

Erni

Hi Lyrun

Here is my code.
I was told that you could not use delay() and SoftwareServo at the same time !!, therefore the "blink without delay" code.
I didn't change the core_build_options.h


Code: [Select]

#include <SoftwareServo.h>

SoftwareServo servo;

int potpin = 3;  
int val;
long previousMillis = 0;        // will store last time LED was updated
long interval = 100;           // interval at which to blink (milliseconds)


void setup()
{
pinMode(1, OUTPUT);
pinMode(3, INPUT);
servo.attach(1);
}

void loop()
{
 
   unsigned long currentMillis = millis();
   val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
   val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)

if(currentMillis - previousMillis > interval) {
   previousMillis = currentMillis;  
   servo.write(val);    // sets the servo position according to the scaled value
   SoftwareServo::refresh();

} //if

} //loop


lyron

I undid the change to the core file and tried your code but the servo still won't move :S


lyron



How is the servo powered?



It's powered off the same 5v from my normal arduino that the attiny is hooked up to

Coding Badly


Are you able to control the servo using your "normal Arduino"?

lyron

yep, it's not the servo, i also tried other servo's...

Coding Badly

I undid the change to the core file and tried your code but the servo still won't move :S


Turning the potentiometer had no effect?

Erni

Hmm, maybe my memory was a little optimistic, i have tried to redo the servo Sketch and there seems to be an issue with jittering.

I did eventuel use another sketch that I found on RCGroups.com. Now i have tried it again, and it runs the servo nice and smoothly.
in my setup I use seperate power to the servo and the Attiny85.

The scetch is here:

http://www.rcgroups.com/forums/showthread.php?t=1314676&highlight=attiny85

post 15.


Erni

Finally I managed to make a servo sketch that works for the attiny85 without glitches
It is not perfect, there are only about 90 steps, but again without glithes!
In the same time I learned something about port manipulation.
I adjusted it by comparing the output from an ordinary servotester with the output from my t85 on a double beam oscilloscop
The  delay routine I have borrowed somewhere, I can not remember where or who made it, i hope this is not a problem

Code: [Select]

//Servo sketch for Attiny85
//Ernst Christensen nov.2011

void setup(){
 DDRB = DDRB | B00001000;  //   set pin 3  as output
 PORTB = PORTB| B00000000; // set digital pin 3 LOW
}

void loop(){
 for(int x=50;x<135;x++){

   PORTB^=_BV(3);
   delay_10us(x); //wait 1,50 ms
   PORTB^=_BV(3);
   delay_10us(1750); // wait 20ms

   delay(100);
 }
 delay(250);

 for(int x=135;x>50;x--){
   PORTB^=_BV(3);
   delay_10us(x); //wait 1,50 ms
   PORTB^=_BV(3);
   delay_10us(1750); // wait 20ms
   delay(100);
 }
}


void delay_10us(uint16_t us)
{
 uint8_t delay_count = (F_CPU / 800)-5;
 volatile uint8_t i;

 while (us != 0) {
   for (i=0; i != delay_count; i++);

   us--;
 }
}





Go Up