Go Down

Topic: i want to create 100hz and pw 1ms in arduino (Read 1 time) previous topic - next topic

akmsr

Sep 15, 2015, 09:52 pm Last Edit: Sep 16, 2015, 07:17 am by akmsr
i am new to arduino please help!  i want to create 100hz and pw 1ms in arduino



program to give 100hz and 1ms clock input to fire my IR LED

 i used function generator and 555 timer circuit, friends says using arduino simply you can create it so i need a program

#define PIN 11
void setup(){
    pinMode(PIN,OUTPUT);  // not absolutely required
    int DUTY = 10;
TCCR1B = TCCR1B & 0b11111000 |4;
}


void loop() {
  static long counter = 0;
  if(millis()%10==0){
      counter++;
      analogWrite(PIN, counter%255);
  }
}

i used this code it gives 498hz

larryd

No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Grumpy_Mike

No idea what this means
Quote
i want to create 100hz and pw 1ms in arduino with accurate
Can you explain more what you mean?

akmsr

#3
Sep 16, 2015, 06:40 am Last Edit: Sep 16, 2015, 06:44 am by akmsr
program to give 100hz and 1ms clock input to my IR LED i used function generator and 555 timer circuit, friends says using arduino simply you can create it so i need a program

#define PIN 11
void setup(){
    pinMode(PIN,OUTPUT);  // not absolutely required
    int DUTY = 10;
TCCR1B = TCCR1B & 0b11111000 |4;
}


void loop() {
  static long counter = 0;
  if(millis()%10==0){
      counter++;
      analogWrite(PIN, counter%255);
  }
}

i used this code it gives 498hz

Grumpy_Mike

First read the how to use this forum sticky thread and edit your last post to comply with the rules on posting code.

Next why are you changing the PWM duty cycle in the loop function? It does not seem to be what you asked for.

Do you want the timers to produce this directly? If so there should be nothing in the loop function at all you just kick it off in the setup and it goes off by itself.

Google about changing the PWM frequency.

CrossRoads

Code: [Select]

void setuo(){
pinMode (2, OUTPUT);
}
void loop(){
digitalWrite (2,  HIGH);
delay(1);
digitalWrite (2, LOW);
delay(9);
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

akmsr

#6
Sep 16, 2015, 08:00 am Last Edit: Sep 16, 2015, 11:58 am by akmsr
Code: [Select]

void setuo(){
pinMode (2, OUTPUT);
}
void loop(){
digitalWrite (2,  HIGH);
delay(1);
digitalWrite (2, LOW);
delay(9);
}


btw small correction i found it its setup please update it in your code

void setup(){
pinMode (2, OUTPUT);
}
void loop(){
digitalWrite (2,  HIGH);
delay(1);
digitalWrite (2, LOW);
delay(9);
}


crossroads thank you very much sir program is working fine my problem solved

Grumpy_Mike

Quote
crossroads thank you very much program is working fine my problem solved
But not your manners.

Go Up