I am using a 10F222 6-pin device to simply generate a tone when trigger input is high. The tone is adjustable by using an analog input simply tied to a 10k POT between 5V and ground. The 10F222, being a simple device does not have any PWM so I am limited to using the sound command to generate the tones. The tone range is good, but the sound is very choppy because the sound command requires a start/stop time limit. I need a smooth constant tone for the entire duration of trigger being high. I would like to use a 10F322 because I would be able to take advantage of the built in PWM output to generate the tone, however PicBasic does not support this device. I am looking for someone who could help me convert this simple PicBasic code for the 10F222 to 10F322 MPLab C code using the PWM register to generate the tone. I have tried to figure out MP Lab, but I am not getting anywhere with it.
Code:
@ __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _IOFSCS_8MHZ
DEFINE OSC 8
GPIO = %0000
TRISIO = %00111101
ADCON0 = %01000001 ' GPIO 0 = Analog, ADC Enabled
ANA_IN VAR GPIO.0 ' GPIO0/ANA0/PDAT
SPK VAR GPIO.1 ' GPIO1/ANA1/PCLK
Trigger VAR GPIO.2 ' GPIO2/T0CKI
' VAR GPIO.4 ' GPIO3/MCLR/VPP
Tone VAR byte
GO_DONE VAR ADCON0.1 ' Alias to GO/DONE bit for ADC
Main:
GO_DONE = 1 ' Start the conversion
IF Trigger THEN
Sound SPK,[Tone / 4 + 50, 1]
ENDIF
WHILE GO_DONE : WEND ' If trigger isn't 'on' wait for the ADC.
Tone = ADRES
Goto Main
End