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

    Darrel,

    Thanks for the advice, never thought that the scope / soundcard software would cause that issue...

    I've not given up entirely on using a PIC, as I feel they offer a lot more and simpler than using descrete components. I'll keep plugging away and see what I come up with.

    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)

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Darrel,

    Thanks for the advice, never thought that the scope / soundcard software would cause that issue...

    I've not given up entirely on using a PIC, as I feel they offer a lot more and simpler than using descrete components. I'll keep plugging away and see what I come up with.

    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)
    I've ran a heater blower motor on a car at ~4khz and unless I strained to hear it, there wasn't much to hear. I know it's a different motor, but still, quite a current draw and I switched the power with MOSFETs. Initially, I ran it with somewhere around 62hz...lots of noise! Both audible and almost a vibration...not to mention the noise coming thru the stereo (which may have just been a bad ground somewhere).
    The 12F675 can run 4mhz on the internal clock. You should be able to easy incorporate the TMR0 interrupt and make a software PWM output that'll run at 3.9khz (which should be plenty high enough) and use the A/D input to set the duty cycle on that PWM. I suppose the easy way to do it would be to take the 10bit A/D input, divide it by 4, giving you 8 bits and use that as the basis for the software PWM.
    Are you familiar with doing software PWM based on interrupts?

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    The 12F675 can run 4mhz on the internal clock. You should be able to easy incorporate the TMR0 interrupt and make a software PWM output that'll run at 3.9khz (which should be plenty high enough) and use the A/D input to set the duty cycle on that PWM. ... Are you familiar with doing software PWM based on interrupts?
    I'd be interested to know how you could do that.
    And since Malcolm was attempting to use MY software PWM routines based on interrupts, I guess you could say I'm familiar with them.

    Let's see, 4 channels @ 3.9khz with 8-bit resolution.

    That'll take (3900 *256) = 998,400 interrupts per second.
    With a PIC running at 4mhz, it'll execute 1,000,000 intructions per second.
    That leaves, 1.0016... instructions per interrupt.

    You wouldn't have a code example for that would you?
    <br>
    DT

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I'd be interested to know how you could do that.
    And since Malcolm was attempting to use MY software PWM routines based on interrupts, I guess you could say I'm familiar with them.

    Let's see, 4 channels @ 3.9khz with 8-bit resolution.

    That'll take (3900 *256) = 998,400 interrupts per second.
    With a PIC running at 4mhz, it'll execute 1,000,000 intructions per second.
    That leaves, 1.0016... instructions per interrupt.

    You wouldn't have a code example for that would you?
    <br>
    Well, yes, I've seen your PWM routines, and fine routines they are, as are most of possibly 100% of the items you post...........ppppfffffffttttttt (that's me fizzling out)

    AND I had a brain fart! I had a whole paragraph typed out explaining my position when I realized I forgot the final divide by 256 for the software PWM. Yep, 15.25hz is about the top for 4mhz. That is unless you start sacrificing resolution for speed...but it still doesn't get you up into the khz range, which is what I did to get a 4khz PWM signal in the blower motor project...then again, I only needed slow, fast and a few speeds in between for that one.

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


    Did you find this post helpful? Yes | No

    Default

    skimask,

    Aw rat's, gave you a chance, but you missed it.

    You were supposed to say "BAM".

    Bit Angle Modulation.

    For devices that rely on the "Average Current" resulting from a PWM signal, the PWM signal doesn't need to be exactly symmetrical waveforms based on consecutive ON and OFF cycles.

    With BAM, you only need 8 interrupts per cycle. Each time period is "weighted" by it's bit position in the DutyCycle variable.

    This way, you could turn every pin on a PIC18F8720 (all 67 of them) into PWM (BAM) outputs (at pretty high frequencies).

    And of course, with DT_INTS, it's a piece of cake.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Hi, Malc

    Some more food for your brain :

    http://www.manhattancontrols.com/for...wtopic.php?t=4

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  7. #7
    Join Date
    Jan 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Red face

    Why not talk to a PIC in the module using I2C?? After all, the track is two wires.

    You could modulate this on top of a standing DC voltage then control a motor using hard coded addresses on the loco module PCB and an H bridge driven by the PWM from the PIC.

    Just a thought. I tried it and it worked fine. Be careful of the need to filter the I2C signals HEAVILY but not so much that you lose them.

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


    Did you find this post helpful? Yes | No

    Default

    Interesting concept, sort of a cross between modern DCC and traditional control. However, its not practical in this instance as the contoller is for a club layout and would mean that every member would have to have the same system installed on their own layaouts at home. Also with the scale, fiting modules to small loco's is a pain in the ***

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


    Did you find this post helpful? Yes | No

    Wink Food for Brain ...

    Hi Malc,

    I Had my father home this week-end ...

    We talked about supplies and it seems the today's "must" is to use switching supply during speed transitions ( or accelerations ) and DC during constant speed running ( of course for noize !!! ) ...

    That meets one of Sougata's threads about signal generation with a Pic ... and opens interesting reflexion and work about what output stage to use !!!

    new challenge for Darrel !!! ( He Looooooves !!!! )

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  10. #10
    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

  11. #11
    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  

  12. #12
    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

  13. #13
    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

  14. #14
    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 " !!!
    *****************************************

  15. #15
    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)

  16. #16
    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 ?

  17. #17
    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.

  18. #18
    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

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