Frequency Function

Discussion in 'Embedded Systems and Microcontrollers' started by ELECTRONERD, Oct 16, 2010.

  1. ELECTRONERD

    Thread Starter Senior Member

    May 26, 2009
    1,146
    16
    I'm developing a frequency function for a PWM function later on. For some reason I'm having trouble with it, here's my code:

    Code ( (Unknown Language)):
    1. [FONT=monospace]
    2. [LIST=1]
    3. [*]//
    4. [*]//      PWM1.C
    5. [*]//
    6. [*]        #include <p18f1320.h>
    7. [*]        #include <delays.h>
    8. [*]        #include <stdlib.h>
    9. [*]        #pragma config OSC=INTIO2, WDT=OFF, LVP=OFF, DEBUG=ON
    10. [*]void freq(char pins, unsigned int frqcy, unsigned int timer)   // Note & Timer driver; determines which note will be played and for how long
    11. [*]        {
    12. [*]                        unsigned int times;
    13. [*]            INTCONbits.TMR0IF = 0;   // Clear OVF Flag
    14. [*]            LATA = pins;   // Initialize LATA
    15. [*]            TMR0L = frqcy & 0xFF;
    16. [*]            TMR0H = (frqcy >> 8) & 0xFF;
    17. [*]            T0CON|=0x80;
    18. [*]            for(times=timer;times>0;times--)   // Duration of playing
    19. [*]            {
    20. [*]                TMR0H = (frqcy >> 8) & 0xFF;   //Load TMR0H byte first
    21. [*]                TMR0L = frqcy & 0xFF;   // Load TMR0L byte next
    22. [*]                while(!INTCONbits.TMR0IF);   // Wait for timer
    23. [*]`                            INTCONbits.TMR0IF = 0;   // Clear OVF Flag
    24. [*]                                LATA = ~LATA;   // Invert output
    25. [*]            }
    26. [*]        }
    27. [*]        void main()
    28. [*]        {
    29. [*]                ADCON1 = 0x0E;  // ADC Settings as digital inputs from RA1-RA3
    30. [*]                OSCCONbits.IRCF0=1;
    31. [*]                OSCCONbits.IRCF1=1;
    32. [*]                OSCCONbits.IRCF2=1;
    33. [*]                T0CONbits.TMR0ON = 0;   // Don't turn timer on yet
    34. [*]                T0CONbits.T08BIT = 0;   // Timer0 is configured as 16-bit timer
    35. [*]                T0CONbits.T0CS = 0;       // Use internal clock
    36. [*]                T0CONbits.PSA = 1;   // Prescaler is not assigned
    37. [*]                T0CONbits.T0PS2 = 0;
    38. [*]                T0CONbits.T0PS1 = 0;
    39. [*]                T0CONbits.T0PS0 = 0;
    40. [*]                OSCCONbits.IRCF0=1;
    41. [*]                OSCCONbits.IRCF1=1;
    42. [*]                OSCCONbits.IRCF2=1;
    43. [*]                while(!OSCCONbits.IOFS);
    44. [*]                freq(0x01, 60990, 1000);
    45. [*]        }
    46. [/LIST]
    47. [/FONT]
    48.  
    49.  
    It compiles fine in C18 using the PIC18F1320, but nothing happens. Do any of you notice where the bug is?
     
  2. ELECTRONERD

    Thread Starter Senior Member

    May 26, 2009
    1,146
    16
    Nevermind, figured out the problem!

    The moderator may delete this thread if he wants.
     
Loading...