Small pin-count device for generating output frequencies when triggered


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2012
    Posts
    64

    Default Small pin-count device for generating output frequencies when triggered

    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.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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.
    Attached Files Attached Files
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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



    Code:
    '@__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

    Quote Originally Posted by Dave View Post
    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.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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.
    Code:
    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.

  5. #5
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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

    Code:
    @  __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

    Quote Originally Posted by HenrikOlsson View Post
    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.
    Code:
    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.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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.

  7. #7
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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


    Quote Originally Posted by HenrikOlsson View Post
    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.

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,518


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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:
    Code:
    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.

  9. #9
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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.....
    Dave Purola,
    N8NTA
    EN82fn

  10. #10
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Small pin-count device for generating output frequencies when triggered

    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


    Quote Originally Posted by Dave View Post
    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.....

Similar Threads

  1. PBP Support for 12F1840 8-Pin Device?
    By springtank in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 10th November 2012, 09:32
  2. Replies: 3
    Last Post: - 24th September 2010, 08:10
  3. How to know what pin triggered an interrupt?
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 13th October 2008, 08:29
  4. Turn on output pin
    By savnik in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th March 2007, 12:49
  5. Input / output using same pin
    By leonel in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th March 2007, 22:19

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts