help me, something wrong with my output (pwm arduino)

Discussion in 'General Electronics Chat' started by haneys, May 31, 2012.

  1. haneys

    Thread Starter New Member

    May 25, 2012
    7
    0
    I need help.. i have the coding as shown below, but its not working as what i expected.. base on what i know, the coding below should provide me a 2MHz frecuency at output pin 9 and 1kHz at ouput pin 8.. but when i test it with oscilloscope i only obtain 2kHz at output pin 9.. what should i do to obtain 2MHz at output pin 9?? how can i change/modified the code?? many2 thankz..

    code:
    Code ( (Unknown Language)):
    1. #include <util/delay.h>
    2. int rog = 8;
    3. void setup() {
    4.   pinMode(9, OUTPUT);
    5.   pinMode(rog, OUTPUT);
    6.  
    7.   TCCR1A = 0;
    8.   TCCR1B = 0;
    9.  
    10.   TCCR1A |= _BV(WGM11) | _BV(COM1A1);
    11.   TCCR1B |= _BV(WGM12) | _BV(WGM13) | _BV(CS10) | _BV(ICNC1);
    12.  
    13.   ICR1= 7;
    14.  
    15.   OCR1A = 3;
    16. }
    17.  
    18. void loop(){
    19. delayrog();
    20.  
    21. }
    22.  
    23. void delayrog(){
    24.    while (1)
    25.     {
    26.        
    27.   digitalWrite(rog, HIGH);
    28.   _delay_ms(0.52);
    29.   digitalWrite(rog, LOW);
    30.   _delay_ms(0.52);
    31.  
    32.     }
    33. }
     
  2. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    I only see pin 8 being written.
     
  3. strantor

    AAC Fanatic!

    Oct 3, 2010
    4,302
    1,988
  4. haneys

    Thread Starter New Member

    May 25, 2012
    7
    0
    but, why i can get 2Mz at output pin 9 when i only use code below, but when i add up another output at pin 8 i wont get 2Mz at output pin 9.. i found this weird.. help me..

    Code ( (Unknown Language)):
    1. void setup() {
    2.   pinMode(9, OUTPUT);
    3.  
    4.   TCCR1A = 0;
    5.   TCCR1B = 0;
    6.  
    7.   TCCR1A |= _BV(WGM11) | _BV(COM1A1);
    8.   TCCR1B |= _BV(WGM12) | _BV(WGM13) | _BV(CS10) | _BV(ICNC1);
    9.  
    10.   ICR1= 7;
    11.  
    12.   OCR1A = 3;
    13. }
    14.  
    15. void loop(){
    16.  
    17. }
     
Loading...