Frequency Function

Thread Starter

ELECTRONERD

Joined May 26, 2009
1,147
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:

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