I gave this a try, 10F222 at 8MHz. Generating roughly 300-3000Hz with the following code:
Code:
#CONFIG
__config _IOFSCS_8MHZ & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
DEFINE NO_CLRWDT 1 ' Forces manual use of CLRWDT
GPIO = %0000
TRISIO = %00111101
ADCON0 = %01000001 ' GPIO 0 = Analog, ADC Enabled
SPK VAR GPIO.1
Trigger VAR GPIO.2
GO_DONE VAR ADCON0.1
SomeValue CON 75
SomeConstant CON 12
Main:
IF Trigger THEN
GO_DONE = 1
SPK = 1 ' Set pin high
WHILE GO_DONE : WEND ' AD conversion will always take the same amount of time
PAUSEUS SomeValue + (ADRES * SomeConstant)
GO_DONE = 1
SPK = 0 ' Set pin low
WHILE GO_DONE : WEND ' AD conversion will always take the same amount of time
PAUSEUS 16 + SomeValue + (ADRES * SomeConstant)
' The 16 above is to make the dutycycle closer to 50% than what it was
' without it. I'm quite surprised such a high number was needed and I'm
' not sure why that is.
ENDIF
Goto Main
Removing the PAUSEUS statements altoghether brings the frequency to 47kHz so there's plenty of margin.
/Henrik.
Bookmarks