Recommendations - Model Train Controller


Closed Thread
Results 1 to 40 of 102

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Alain,

    One step ahead of you... I'm using a 16F828a and set up a 100K lin pot and 0.1uf capacitor, and a simple bit of code.. but can't get it to work (just slung it together in the past 5 mins)

    The code compiles, but I don't get any PWM on the output (using a LED for test purposes at the moment - no FET connected.)

    10k between MCLR and +5v, input from the pot to A2

    Here's the code

    Code:
    ;************ set up PIC *****************
    PORTA = 0                        ' declare port level BEFORE port direction = safe power-on
    CMCON = 7                        ' PortA Digital inputs
    CCP1CON = 0                      ' PWM off
    VRCON = 0                        ' Voltage reference disabled
    OPTION_REG.7 =    0
    
    
    TRISA=%11101111                  'set PORTA as all input apart from A4
    TRISB=%00000000                  'set PORTB as all output
    
    @RC_OSC_NOCLKOUT 
    @WDT_ON
    @PWRT_ON
    @MCLR_OFF
    @BOD_ON
    @LVP_OFF
    @CPD_OFF
    @PROTECT_OFF
    
    ;************* set up varibles ************
        
    D var byte                          ;used to store the result of the pot on port A2
    scale var byte                      ;used in the POT command
    Scale = 254                         ;used to set range 
                                                                
    ;************* main program ****************
    Main:                         
    Pot PORTA.2,scale,D                 ;used to read value from pot
    pwm PORTB.4,D,1
    Goto main
    The main loop is self explanatory, port A2 is checked and the result is placed in the variable D, this is used to set the width of the PWM sent out on pin B4

    Any ideas why I can't get it to work
    Last edited by malc-c; - 10th February 2007 at 15:44.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Malc,
    Your configuration fuse don't do anything. The way you do it, it actually do nothing else than define some Labels.

    Code:
            '
            '       PIC Configuration fuses
            '       =======================
                    '    _BODEN_ON 
                    '    _BODEN_OFF
                    '    _CP_ALL   
                    '    _CP_75    
                    '    _CP_50    
                    '    _CP_OFF   
                    '    _DATA_CP_ON 
                    '    _DATA_CP_OFF
                    '    _PWRTE_OFF  
                    '    _PWRTE_ON   
                    '    _WDT_ON     
                    '    _WDT_OFF    
                    '    _LVP_ON     
                    '    _LVP_OFF    
                    '    _MCLRE_ON   
                    '    _MCLRE_OFF  
                    '    _ER_OSC_CLKOUT 
                    '    _ER_OSC_NOCLKOUT 
                    '    _INTRC_OSC_CLKOUT 
                    '    _INTRC_OSC_NOCLKOUT 
                    '    _EXTCLK_OSC         
                    '    _LP_OSC             
                    '    _XT_OSC             
                    '    _HS_OSC 
            @ __CONFIG  _INTRC_OSC_NOCLKOUT & _MCLRE_OFF  &  _LVP_OFF & _WDT_ON & _PWRTE_ON  & _BODEN_ON
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Steve,

    The code was ripped from a previous bit of code that worked fine - I just changed the main part of the program and deleted all that wasn't required, so I can't see why it wouldn't work.

    Its always the fuses that catch me out !!

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Steve,

    If I remember correctly, if I leave out any config settings it takes whats listed in the INC file ??

    If I delete my listings and add your last line it errors "overwriting previous settings" - (I'm using MPSAM) - If I leave the listings as

    Code:
    @RC_OSC_NOCLKOUT 
    @WDT_ON
    @PWRT_ON
    @MCLR_OFF
    @BOD_ON
    @LVP_OFF
    @CPD_OFF
    @PROTECT_OFF
    it compiles fine

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Sure it compile fine but it simply don't do anything.

    You could also Type
    Code:
    @SantaClausIsComingToTown_ON
    And MPASM won't yell, it just define a LABEL

    Code:
    @SpinHere
    @        GOTO SpinHere
    Code:
    @MCLR_OFF
    @        Goto MCLR_OFF
    also work

    Have a look at the following...
    http://www.picbasic.co.uk/forum/show...75&postcount=5
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Alain,

    One step ahead of you... I'm using a 16F828a and set up a 100K lin pot and 0.1uf capacitor, and a simple bit of code.. but can't get it to work (just slung it together in the past 5 mins)

    pwm PORTB.4,D,1
    4

    Any ideas why I can't get it to work
    Hi, Malc

    1) May be you should try the HPWM function ... i've noticed it worked much better for motor PWM ... on PORTB.3 instead of B.4 ( ! )

    2) Try RCTime ...instead of this stupid POT ... linearity will be far better !!!

    AND KEEP WITHIN THE MANUAL VALUES ( 5 -50 k ; 0.1µF ) IF STILL USING POT !!!

    heuuuu ... your scale value (254 ) is a bit surprising ...

    Alain
    Last edited by Acetronics2; - 10th February 2007 at 18:35.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Microstepper controller
    By aratti in forum Schematics
    Replies: 14
    Last Post: - 3rd January 2015, 16:52
  2. problem with the GSM controller
    By Dariolo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th May 2009, 20:33
  3. Replies: 2
    Last Post: - 14th July 2008, 22:11
  4. Model Train controller - revisited
    By malc-c in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 8th May 2007, 09:40
  5. Dedicated LCD Controller question
    By chuckles in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th February 2006, 14:44

Members who have read this thread : 0

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

Posting Permissions

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