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

    Ok I now realise where I went wrong.. since I last used PBP I re-built the PC and thus the changes made to the 16F628a inc file had been lost.. I followed Steves advice and now have a working device..sorta !

    Just need to tweek the scale so that I get a full duty cycle from 0 to 255

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


    Did you find this post helpful? Yes | No

    Default Change of tactics

    Ok I got nowhere with that POT command, so jump in the deep end and try using ADC.

    I've used a 12F675 with the following code. As I've never used ADC before and still find datasheets confusing I just cut and pasted examples from the PBP manual for ADC.

    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
    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
    
    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
    
    led var GPIO.2
    i var byte
    D var byte
    
    main:
    ADCIN 0, D                                   
        Pwm GPIO.2,D,1
    goto main
    To my suprise, the code compiled and works, well sort off !

    using a 10K pot connected between +5v and GND with the wiper connected to GPIO 0, my DVM reads between +0.14v and +5 on GPIO 2 when the pot is turned through its range - connecting an LED to GPIO 2 confirms that something is working as its brightness can be controlled via the POT... so far so good

    I then tested the FET by connecting a 10K pot between gnd and +5v with the wiper going to the gate, the track between +12v and FET and the FET to GND. Adjusting the pot produced some degree of control over a loco... so I moved the link from the pots wiper and connected it to GPIO 2. However the DVM reads the same vdd of the 12v rail regardless of the setting of the POT.

    I can only assume that its something to do with the PWM output from the PIC that is turning on the FET continiously ?? anyone have any suggestions ?? Can a PIC have DAC so I could convert the resulting digital value to a voltage that would be used to drive the FET (or whatever output stage I use).

    I want to stick with a PIC for the control as it would be easier to use simple for next loops / or counters for programmable stops, acceleration, etc

    Comments welcome as always

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


    Did you find this post helpful? Yes | No

    Default

    i think it's more a matter how this PWM function is made...i'll do some test here first. How many different channel you need?
    Which other PIC you have on hand?
    Last edited by mister_e; - 11th February 2007 at 16:41.
    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

    LOL - Steve, I sence you see I'm strugling and a bit out of my depth

    I would like to use 4 channels in total so I can control 4 trains all independantly, but I'm not bothered if I need to use two chips.

    I have at my disposal the following PICs:

    16F84A
    16F873A
    16F628A
    16F676
    16F688
    16F877A
    16F684
    18F2550
    12F675
    18F4550

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    i think it's more a matter how this PWM function is made...i'll do some test here first.
    Steve, I think you might be right. I used a winscope (soundcard) and captured the output at different settings of the POT - it don't look much like a PPM signal to me
    Attached Images Attached Images   

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Malc

    Your scoping confirms what I thought and read ...

    The pot function charges the capacitor, and then drags little amounts of current ( in coulombs ...), verifies if the pin low thresold is reached, takes another quantity of current, verifies, and so on ...

    That's why you get such garbage !!!

    Now, the result is a count of the little quantities ... and that explains why you must use the indicated values and not others, even the RC value remains constant.

    Alain

    PS: and what about a scale value of ... 64 ???
    ************************************************** ***********************
    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
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Alain,

    The traces were from the 12f675 that used A/D to read the voltage from a 10K pot (as detailed in post #22).

    Code:
    ADCIN 0, D                                   
        Pwm GPIO.2,D,1
    goto main
    I was expecting a traditional square wave type signal, with varying width of pulse, not the noisy signal the PIC is outputing.... The manual shows additional components for analogue output (resistor / capacitor), maybe I should try using that to get a decent signal out ?

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


    Did you find this post helpful? Yes | No

    Talking The Bass beat Filter II ???

    Huh !!!

    The manual clearly tells Pwm outputs garbage ... and needs a RC or more sophisticated filter.

    Now just keep in mind PWM is only good to get some "analogic" output from the PIC.

    Another STAMP " Not so good a function " survivor.

    Now, if you want to keep the PWM function ... just compare a sawtooth to this "analogic" voltage ( once filtered ) and you'll get a neat "real PWM" at the output of the comparators.

    a quad LM 339 sould do that job very honestly ...

    But we remember DARREL's slow PWM is the shiny solution to what you want to do.

    Ah, last point ... and not least ! you'll discover the motors have a low PWM ratio thresold not to make some noise and unwanted heating while not turning. one more thing to add !!!

    Alain
    Last edited by Acetronics2; - 12th February 2007 at 10:13.
    ************************************************** ***********************
    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