PDA

View Full Version : Small pin-count device for generating output frequencies when triggered



JimAvanti
- 17th September 2016, 20:51
I am trying to do what seems like one of the simplest PIC programming tasks I ever did and it is turning into a nightmare. All I want to do is use the smallest pin count device possible to monitor 1 digital input pin (Trigger), 1 Analog input pin (To adjust a frequency), and one output pin (frequency output to speaker when trigger is detected). This way I could use a larger device to trigger different tones without having to deal with anything except turning ports on/off.

I purchased 10F322 devices only to find that Picbasic ver 2.06C does not support it. After some playing around in MPLab for a while and deciding it was too much to learn I decided to try some 10F222 devices. I am now finding that they don't support ADCIN or FREQOUT (The two commands I need to use!)

Any suggestions? Any other small 8 or 6 pin devices that might work? Is there anyone here that could write up a quick MPLAB-X C example for the 10F322?
For now I would be happy enough just looping frequency outputs for 1 second bursts as long as the trigger is high, but what I would really prefer is to use hardware PWM to have a nice steady frequency output.

Dave
- 19th September 2016, 12:14
Jim, I have attached a small program I worte a few years back for a 10F222 processor. It was for generating 2 different tones simulating a CW message for amatuer radio to be used for ID or Fox hunting purposes. It would key the radio push to talk circuit, wait 250 Milliseconds and then send the message. It would then go into a sort of sleep mode for about 6 minutes. During the sleep time it awakes approx. every 2.5 seconds and reads a port pin to see if is being commanded to transmit before the timeout period. Use it as a starting point for your project. I don't see why you couldn't use the A/D to set the tone frequency.

JimAvanti
- 19th September 2016, 16:32
Dave,
The program I wrote so far is just a simple test to generate sound (Attached). It uses the sound command like your program and it works, but I wanted to eventually use hardware PWM so that the sound was constant and not just quick 1 second bursts. I tried using FREQOUT command and it gave me errors. When I checked the documentation I noticed a bunch of commands that are not supported with 12-bit core devices including FREQOUT and ADCIN. My plan was to set registers for the HPWM so not having FREQOUT was not a big deal, but when I saw that ADCIN was nut supported I didn’t think I could use this PIC. Maybe ASCIN will work – I haven’t tried it.
Thanks,

Jim




'@__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _IOFSCS_8MHZ

DEFINE OSC 8
tmr0= %00000000
ADCON0 = %000000
GPIO = %0000
TRISIO = %00111101

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

Main:
if Trigger then
'FREQOUT SPK, 20, 1000
Sound SPK,[50,1]
endif
Goto Main

End



Jim, I have attached a small program I worte a few years back for a 10F222 processor. It was for generating 2 different tones simulating a CW message for amatuer radio to be used for ID or Fox hunting purposes. It would key the radio push to talk circuit, wait 250 Milliseconds and then send the message. It would then go into a sort of sleep mode for about 6 minutes. During the sleep time it awakes approx. every 2.5 seconds and reads a port pin to see if is being commanded to transmit before the timeout period. Use it as a starting point for your project. I don't see why you couldn't use the A/D to set the tone frequency.

HenrikOlsson
- 19th September 2016, 17:26
I have never used a 10F part before but looking at the datasheet that has got to be the easiest ADC there is to run. No Clock source selection, no left/right justification, no sample time configuration, nothing, three lines of code pretty much.

GO_DONE VAR ADCON0.1 ' Alias to GO/DONE bit for ADC

ADCON0 = %01000001 ' GPIO 0 = Analog, Channel 0 connected to ADC, ADC Enabled
GO_DONE = 1 ' Start the conversion
WHILE GO_DONE : WEND ' Wait for it to complete.

' Result is now availabe in ADRES.

Of course, not having used one before, may mean I'm missing something but it really looks like there's nothing more to in than that. If you can setup the CCP module manually you can figure out how to operate this ADC :-)

/Henrik.

JimAvanti
- 19th September 2016, 20:49
Thanks again Henrik,
This works pretty good now. I would still like to get rid of the sound command and replace it with a steady HPWM signal eventually, but this will get me by for now and it doesn't look like the 10F222 even has PWM capability.

Jim



@ __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _IOFSCS_8MHZ

DEFINE OSC 8

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
WHILE GO_DONE : WEND ' Wait for it to complete.
Tone = ADRES
if Trigger then
Sound SPK,[Tone / 4 + 50, 1]
endif
Goto Main

End



I have never used a 10F part before but looking at the datasheet that has got to be the easiest ADC there is to run. No Clock source selection, no left/right justification, no sample time configuration, nothing, three lines of code pretty much.

GO_DONE VAR ADCON0.1 ' Alias to GO/DONE bit for ADC

ADCON0 = %01000001 ' GPIO 0 = Analog, Channel 0 connected to ADC, ADC Enabled
GO_DONE = 1 ' Start the conversion
WHILE GO_DONE : WEND ' Wait for it to complete.

' Result is now availabe in ADRES.

Of course, not having used one before, may mean I'm missing something but it really looks like there's nothing more to in than that. If you can setup the CCP module manually you can figure out how to operate this ADC :-)

/Henrik.

HenrikOlsson
- 19th September 2016, 22:19
That's correct, no CCP module in this one (I didn't check that previosuly). And there's no interrupts either.

What sort of frequencies are you talking about?

BTW, in your code, there's no real reason to waste one of the PICs 23 bytes of RAM, out of which PBP uses most, to copy ADRES to Tone - just use ADRES directly.

/Henrik.

JimAvanti
- 20th September 2016, 05:30
Henrik,

Without hardware PWM I don't really need to go any further with this. It is working good enough for what I need it for and the tone range is good. I knew this would be a very small program, but I was hoping to have the capability of a constant tone for the duration of the trigger, but I can live with short sound bursts. I purchased 10F322 chips first, but PBP didn't support them and I couldn't figure out MPLAB-X.

I will be using two of these chips set to different tones so I can hear either or both when they trigger. Maybe at some future time I will figure out MPLAB and be able to program the 10F322's (Hardware PWM with adjustable Duty for LEDs or adjustable Freq for sound). I did figure I could just use ADRES directly, but I don't need to do anything else with these anyway.

Thanks for all your help.
Jim



That's correct, no CCP module in this one (I didn't check that previosuly). And there's no interrupts either.

What sort of frequencies are you talking about?

BTW, in your code, there's no real reason to waste one of the PICs 23 bytes of RAM, out of which PBP uses most, to copy ADRES to Tone - just use ADRES directly.

/Henrik.

HenrikOlsson
- 20th September 2016, 07:55
If you need to be able to change the tone "continously" then rearanging the code slighty might make it a little bit better, the glitch should be in the us* range:


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' we need to wait for the ADC.
Tone = ADRES
Goto Main

*Depending on how much time SOUND needs to "set it self up".

/Henrik.

Dave
- 20th September 2016, 14:08
Hey Jim, If all you are looking for is an A/D to Oscillator output have a look at maybe using some Linear Tech. TIMER BLOX. They make 2 different VCO's to cover the range from 29uHZ to 977 HZ and 1 for 488HZ to 2Mhz. They are in 6 pin SOT packages. Just a thought.....

JimAvanti
- 1st November 2016, 14:37
Hi Dave,

I just looked at the datasheet for the LTC6990 and it does look like it could work for what I need. I would have to test how the frequency ranges sound first, but it seems to have everything I need (OE to trigger it and Freq can be controlled by a POT manually). I'll have to test it and let you know.

Thanks,
Jim



Hey Jim, If all you are looking for is an A/D to Oscillator output have a look at maybe using some Linear Tech. TIMER BLOX. They make 2 different VCO's to cover the range from 29uHZ to 977 HZ and 1 for 488HZ to 2Mhz. They are in 6 pin SOT packages. Just a thought.....