Model Train controller - revisited


Closed Thread
Results 1 to 33 of 33

Hybrid View

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


    Did you find this post helpful? Yes | No

    Wink simple way ...

    Hi, Malc

    Try this:

    TEMP var WORD

    Main:

    ADCIN 0, DUTYVAR[0] ; if having more channels add ADCIN 2, DUTYVAR[2] etc

    TEMP = DUTYVAR[0] * DUTYVAR[0] / 256 '********************

    IF DUTYVAR[0] < 10 THEN ' 10 = value for a neat motor start , if needed !

    DUTYVAR[0] = 0
    GOTO Jump0

    ENDIF

    DUTYVAR[0] = TEMP MAX 10

    Jump0:


    ADCIN 1, DUTYVAR[1]

    TEMP = DUTYVAR[1] * DUTYVAR[1] / 256 '********************

    IF DUTYVAR[1] < 10 THEN ' 10 = value for a neat motor start ,if needed !


    DUTYVAR[1] = 0
    GOTO Jump1

    ENDIF

    DUTYVAR[1] = TEMP MAX 10

    Jump1:

    GOTO Main ; program simply loops round reading ADC and sending corresponding PWM out

    That what I use for my boat speed controllers ... works really fine !!!

    Regards
    Alain

    PS: here is the original

    '************************************************* *****************************
    'Mise à l'echelle 0 - 255 de la sortie PWM pour 0 - 96 % de la course
    '************************************************* *****************************

    ' 265 = 255 / 0.96 ... CQFD

    '************************************************* *****************************
    'Moteur Gauche
    '************************************************* *****************************

    EcartGazG = ( ABS ( PulsGazG - MidGaz)) ' for fwd/rev on the same stick

    IF EcartGazG < 55 THEN 'Center Deadband
    PowerG = 0
    GOTO MotD
    ENDIF

    dummy = EcartGazG * 265
    PowerG = DIV32 CourseGaz

    PowerG = (PowerG + 1 ) MIN 255 ' 255 value as MAXI for PWM

    '************************************************* *****************************
    'Variation exponentielle
    '************************************************* *****************************

    dummy = PowerG * PowerG
    PowerG = DIV32 255

    '************************************************* *****************************
    'Puissance mini appliquee au moteur - démarrage franc ( 20/255 )
    '************************************************* *****************************

    PowerG = PowerG MAX 20
    Last edited by Acetronics2; - 22nd April 2007 at 18: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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Guys, thanks for the replies.

    To answer some of the questions, yes the pots are lin, or at least they are marked as lin and purchased as such, and using a DVM it seem that they are liniar. I'll look at taking all the unused pins to +ve, possibly via 10k resistors.

    Alain,

    I think that the original code above basically works on the same principle of taking the 0 - 254 from the adc and sending that out as the pulse. However it all got a bit complicated when Darrel's routines were used as all I know is that i need to do is change then two values
    Code:
    DEFINE SPWM_FREQ  150                	' SPWM Frequency (Hz)
    DEFINE SPWM_RES   254               	' SPWM Resolution (0 - 255)
    I'll try adding your code and will report back

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


    Did you find this post helpful? Yes | No

    Default

    The LOG pot is a nice idea, Alain's routine too. You can also build a huge LOOKUP table with excel and read from it. If you have some VCA (like ssm2164) you can use a Linear pot and get a LOG curve.

    Many different ways.

    At least, there's some progress

    PS: you can trick the curve a little bit by adding a resistor in parrallel with the wiper... far to be LOG, but could be interesting to trace the curve...

    THE PWM freq shouldn't affect the results... shouldn't..
    Last edited by mister_e; - 22nd April 2007 at 18:30.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default getting there

    Well it compiles Ok and it does indeed work, providing a better range of travel for the lower end of the POT. It produces an interesting wave form

    The only problem is that oscilatons produce noise in the loco's armature. I tried the old trick of using a capacitor across the output which worked to some degree, but as it effectivly smoothed the pulses it defeats the object of using PWM (or PPM)

    Steve, I'll try your suggestion
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Oh and one other thing I've noticed,which may be causingn the PIC to bomb is when the when the wiper is at the top and thus connected to the 5.21v supply the pulses stop and the voltage out drops, and on some occasions this has caused the driver to sort of lock as moving the pot after the effect has no effect as the PMW generation has stopped. Is there a way of setting the voltage ref or ADC value so that a PMW signal is always produced ?

    Edit:
    maybe this video might help explain (2.2 MB Divx format) http://www.micro-heli.co.uk/scope4.avi
    Last edited by malc-c; - 22nd April 2007 at 20:00.

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


    Did you find this post helpful? Yes | No

    Default

    The weird results you have is probably caused by the delay to do the calc... well i think.

    Don't try the Resistor... i was 100% wrong.. it's not going to be LOG... just alog... as per i got from EXCEL... so just worst than before

    <img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1557&stc=1&d=117726977 2">

    oops, it's sunday

    ...mmm something to do anyway with that... scratch scratch...
    Attached Images Attached Images  
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    What happen to your PWM lock-up thingy if you replace the Motor by a resistor? I don't see any back EMF diode here...

    EDIT: check the maximum range of your scalling maths

    EDIT2: well it's really sunday !!
    Quote Originally Posted by Malc-C
    However, the amount of rotation of the pot is quite small before the loco is up to a medium speed.
    so if i'm right... the curve above should work?

    do i need to sleep or get another brain? I've attach my noobie-style excel sheet.

    Just play with the Value in D1 cell and enjoy.
    Attached Files Attached Files
    Last edited by mister_e; - 22nd April 2007 at 20:49.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Hi again Steve,

    The EMF feedback was removed following a suggestion from Alain in the original thread ( http://www.picbasic.co.uk/forum/show...0&postcount=46 )

    Could you elaborate on the scaling thing...

    I'll have a play with the speadsheet and add a few resistors in parallel to see what happens. It will probably won't be tonight as I don't have access to the loco anymore (It shot off the end of the test track and now boxed up as it is in need of repair, and my son has gone to bed now so I can't get one of the other locos !)

    Sorry guys for going over this again, but I still cant get my head round some of these aspects of programming.

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. Graphics controller for the Sitronix ST7549
    By ttease in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th May 2007, 21:45
  4. Recommendations - Model Train Controller
    By malc-c in forum mel PIC BASIC Pro
    Replies: 101
    Last Post: - 8th March 2007, 08:17
  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