Small pin-count device for generating output frequencies when triggered


Closed Thread
Results 1 to 10 of 10

Hybrid View

  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,521


    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,521


    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.

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, 08:32
  2. Replies: 3
    Last Post: - 24th September 2010, 07: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, 07:29
  4. Turn on output pin
    By savnik in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th March 2007, 11:49
  5. Input / output using same pin
    By leonel in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th March 2007, 21: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