Help converting small PicBasic program to MP LAB


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Help converting small PicBasic program to MP LAB

    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.

  2. #2
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Help converting small PicBasic program to MP LAB

    That worked Awesome! Thank you so much! I don’t know why I was thinking I was running at 4GHz, but even at 8GHz I didn’t think it would sound that good. Perfect!

    Jim




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

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Help converting small PicBasic program to MP LAB

    You're welcome, glad I could help!
    I would love to play around with a PIC running at 4GHz, let alone 8 :-)

    /Henrik.

  4. #4
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Help converting small PicBasic program to MP LAB

    Hello Henrik,

    I am trying to send you a private message, but I keep getting logged off each time I attempt to. Could you send me a private message so that I can see if reply works? Thanks,

    Jim

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Help converting small PicBasic program to MP LAB

    Oh, I'm getting them Jim, all of them (I think) :-)

    /Henrik.

Similar Threads

  1. Multi servo interrupt program in Mikro Basic converting to PBP
    By queenidog in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2015, 17:17
  2. Converting CLEAR in Proton basic to picbasic pro
    By Nobby123 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th October 2013, 09:19
  3. help converting assembely program
    By ahmed_salah in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 7th August 2008, 15:28
  4. Making the Lab X1 communicate with the Lab X2
    By MatthewM in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 19th June 2008, 22:26
  5. 1st 16F877A program in PICBasic
    By Borisw37 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th January 2005, 04:46

Members who have read this thread : 0

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