Recommendations - Model Train Controller


Closed Thread
Results 1 to 40 of 102

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    I assume that using a 100 Hz frequency for the PWM would be ideal... what PIC did you use, and is having an internal clock an issue (I'm using a 12F675 for experimential use)
    Malcolm,

    I was using a 16F877A, I guess it was really comparing Apples to Oranges.

    I figured I better check with a 12F675, but didn't have one handy so I used a 12F683. It was close enough to figure out what was wrong.

    This get's everyone, so I should have seen it right away, but nope.

    CMCON = 7 ; disable the comparators
    ANSEL = 1 ; AN0 is analog, rest digital

    also, You have a PWM output on GPIO.0 ... The same pin as the POT is connected to on AN0. That'll cause problems with the A/D reading.

    Hope you're still interested?

    EDIT: 100hz is no problem. But you'll need a faster crystal/resonator
    INTRC won't cut it.

    HTH,
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Sorry I missed that... I've remmed out the PWM line fro GPIO.0 and have got a reasonable result, especially for slow speed - The crawling speed of an 18 year old tank loco is really amaizing !!

    Here's the code

    Code:
    DEFINE OSC 20
    CLEAR
    
    DEFINE ADC_BITS 8	' Set number of bits in result
    DEFINE ADC_CLOCK 3	' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50	' Set sampling time in microseconds
    
    INCLUDE "DT_INTS-14.bas"            ; Base Interrupt System
    INCLUDE "SPWM_INT.bas"              ; Software PWM module
    
    DEFINE SPWM_FREQ  100                ; SPWM Frequency
    DEFINE SPWM_RES   256               ; SPWM Resolution
    
    D var byte
    
    DutyVars   VAR BYTE[3]              ; DutyCycle Variables
      ;DutyVar1 VAR DutyVars[0]          ; group them in an array for easy access
      ;DutyVar2 VAR DutyVars[1]          ; with FOR loops etc.
      DutyVar3 VAR DutyVars[2]
    
    ASM
    SPWM_LIST  macro                    ; Define Pin's to use for SPWM
        ;SPWM_PIN  GPIO, 0, _DutyVar1  ; and the associated DutyCycle variables
        ; SPWM_PIN  GPIO, 1, _DutyVar2  ; Notice the underscore before variables
         SPWM_PIN  GPIO, 2, _DutyVar3
      endm
      SPWM_INIT  SPWM_LIST              ; Initialize the Pins
    ENDASM
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  SPWMhandler,  ASM,  yes
        endm
        INT_CREATE                      ; Creates the interrupt processor
    ENDASM
    
    @ INT_ENABLE  TMR1_INT              ; enable Timer 1 interrupts
    
    ;_____________________________________________________________________________
    
    Main:                               
     ADCIN 0, D 
        DutyVar3 = D   
    GOTO Main
    Using a close loop fedback output stage and a 12v regulated supply for the track as per the diagram attached, I get a nice smooth slow speed control. This is using the 12F675 with its internal osc.

    The loco does growl a bit when at really slow speed... and at maximum speed its fine for a goods train, but not an express. I susspect that using a higher track supply voltage will resolve the speed issue (my DVM reads 6.5v across the track at full speed), but wondered if there was anything I could do to reduce the growling at slow speed.

    Please bear in mind that I'm still somewhat new to PICs and programming.. so If I've still overlooked something in the settings then please advise what I did wrong and how to correct it.
    Attached Images Attached Images  

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hmm, I don't see the CMCON and ANSEL in your program.

    There's a R-M-W (Read-Modify-Write) problem when OUTPUTting to a pin set to Analog. It adds a high frequency component to the PWM signal.

    I don't know if that's what is causing the growling or not.

    6.5V at full speed? That doesn't sound right. The current is getting limited somewhere. Maybe if you increased the value of R4 ????
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Hmm, I don't see the CMCON and ANSEL in your program.

    There's a R-M-W (Read-Modify-Write) problem when OUTPUTting to a pin set to Analog. It adds a high frequency component to the PWM signal.
    Would the following be correct
    Code:
    TRISIO.2 = 0   'Set GPIO.2 to output.
    ANSEL.2 = 0    'Set GPIO.2 to digital		
    GPIO.0 = 1      'gpio.0 set to input
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    Quote Originally Posted by Darrel Taylor View Post
    6.5V at full speed? That doesn't sound right. The current is getting limited somewhere. Maybe if you increased the value of R4 ????
    I'll try that and see what happens, thanks for the suggestion

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


    Did you find this post helpful? Yes | No

    Wink No surprise !!!

    Hi, Malc

    I do not know where you found R4 and D1 ... but your problems come from there.

    No real use for them ... so, back to their drawer will be the best.

    ... or use another Pic pin if you want to do something with the freewheel emf !!!

    a simpler output stage would be welcome ( your NPN Emitter to ground and a series 1 k in the base connection i.e. )

    Alain
    Last edited by Acetronics2; - 15th February 2007 at 13:27.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Alain,

    Thanks for the suggestion... the output circuit was taken from a book and is actually a cloose-loop feedback controller... I just fed the output from the PIC directly to the base of the NPN tranny... but I'll try your suggestions and see if it improves the max speed settings. However in its current state it makes for an excellent branch line controller where slower trains would run...

    To give you some idea of the excellent slow speed the PWM gives have a look at this video I've uploaded http://www.micro-heli.co.uk/controller.avi (9mb DIVx format)

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


    Did you find this post helpful? Yes | No

    Default

    Omitting the feedback section (R4 and 1N4148), and adding a 1K base resistior I now get a good range of speed and excellent slow speed crawling. Just need to resolve the growling in the armature

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    There's a R-M-W (Read-Modify-Write) problem when OUTPUTting to a pin set to Analog. It adds a high frequency component to the PWM signal.
    That's interesting... whilst I was reading up on the use of your code I could hear this high pitched (estimated 4 - 8 Khz) faint sound like you often hear eminating from a TV... placed my ear near the loco (which is standing still on the track) and its singing away !!

    I presume that this is due to the fact that GPIO.2 is still set to analogue and not digital ??

    What config settings should I use for CMCON and ANSEL to resolve this ?

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


    Did you find this post helpful? Yes | No

    Default

    in theory the right setting have to be
    Code:
    ANSEL=%00110001
    CMCON=7
    GPIO=0
    TRISIO=1
    and later i just change the main loop to...
    Code:
    Main:                               
            ADCIN 0, DUTYVAR3
            GOTO Main
    AND NOW it's working pretty good and smooth... well here...

    For once i found a use of the Left-Justified results... Never thought ADCIN handled it

    Make sure your Pot impedance meet the maximum recommended on.. 2.5 k if my memory serves me well. 10K here (EasyPic 4) still work fine..

    Also, as the ADC results is a 8 bit result, you should change the SPWM_RES to 255.
    Last edited by mister_e; - 15th February 2007 at 18:28.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Steve, Thanks for your input. I made the changes you suggested and the performance is still great and the growling sound produced by the PWM in the armature appears less noticable. The high pitched sound is still noticable, but nothing appears hot

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


    Did you find this post helpful? Yes | No

    Default

    Unfortunately i don't have anything like that here to test, but Maybe the PWM have to be smooth first...

    what happen if you place a big capacitor (470 & up) in parallel with the motors?

    What happen if you place a capacitor (few uF) on the mosfet gate pin? (transistor base)

    What happen if you use a variable voltage regulator (or PSU)? instead of PWM?
    Steve

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

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