Remote control by location (PIC in Oshonsoft)

Discussion in 'Embedded Systems and Microcontrollers' started by camerart, May 17, 2018.

  1. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    I'm making a couple of PCBs using surface mount components, and PICs, for use as remote control by location.

    Remote control by location, is when a location is sent from the BASE (Transmitter) and the REMOTE (Model) goes to that location.

    This includes GPS COORDINATES, COMPASS BEARING, ALTITUDE.

    If the signal is lost the model should be at the last sent location.
    For those of us that have difficulty knowing which way our models are aiming, the model should be aiming the direction set by the transmitter, making return to BASE easier..

    Camerart.
     
    Last edited: Jul 11, 2018 at 6:47 AM
  2. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    I received a reply in another thread and I've moved it here:

    TRIBBLES "I never really got to play with the PWM on PICs, so I'm going on intuition here....

    HPOL and LPOL are the high and low polarity - i.e. whether the signal needs to be high or low to turn on a transistor/MOSFET. Figure 18-2 shows that it's used to select the normal or inverted output of the PWM block.

    PWMPIN I think needs to be '1' to indicate that you want the pin to use the PWM block. Figure 18-23 shows that "PWM Pin Enable" switches between the LAT output for the pin, and the output from the PWM block. It looks like the PWM Pin Enable signal also overrides the TRIS configuration as well.

    And I've just read 18.11.3 which confirms my understanding of the PWM Pin Enable signal.

    Now looking into it a bit more, the PWMPIN configuration bit drives the default setting for the PWMEN register - so if you're manually setting PWMEN in your code (which you are - the 0x40 value in PWMCON0), then it doesn't matter what you set the PWMPIN configuration bit :) The only two values that it'll default to is 0x50 or 0x70 - so you can't configure it to 0x40 by this bit, and you'll have to override it anyway."

    HI T,
    I'll check out your findings, thanks.
    C.
     
  3. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi
    Setting up PIC 18LF4431 PWM PINs is quite involved. I'm trying to get 6x PWM outputs, like this:

    Also there may be a problem regarding actually writing the program, as last time I was playing with PWMs, EG wrote this program for me, using ASM, because I can't. Trying this program in the Oshonsoft SIM, it looks as though it may be possible to run it with just one PIN. I'll need to check a bit more.
    EDIT: I don't think the attached program lends itself to the 18LF4431 PIC.
    C.
     
    Last edited: May 21, 2018
  4. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi,
    I've been reminded again, by a web search that PWM in Oshonsoft needs this:

    " Hi C,
    If you recall there is a bug on Oshonsoft PWM, it does not clear the CCPRxL reg correctly, it was reported to Vlad.
    You and I have used this ASM in dozens of programs already, I don't see a problem with using it again.??

    E

    hcw: ' clock wise
    Hserin dutyhcw 'duty 0 thru FFh
    ASM: bcf CCP1CON,DC1B0
    ASM: bcf ccp1con,dc1b1
    ASM: movlw 0x00
    ASM: movwf ccpr1l
    PWMduty 2, dutyhcw
    Goto main

    hacw: ' anti clock wise
    Hserin dutyhacw 'duty 0 thru FFh
    ASM: bcf CCP2CON,DC2B0
    ASM: bcf ccp2con,dc2b1
    ASM: movlw 0x00
    ASM: movwf ccpr2l
    PWMduty 1, dutyhacw
    Goto main "

    So, I'll have to try it again.
     
  5. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi,
    I've added the above CODE into a program, which compiles.
    How is it implemented?
    C
     
  6. ericgibbs

    Moderator

    Jan 29, 2010
    4,852
    924
    hi C,
    I am not sure I follow your question.?
    Hserin gets the 'pwm duty'
    the ASM sets up the correct CCP2CON
    PWMduty is the Oshonsoft output command to the PWM pin
    e
     
  7. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi E,
    If you look at the '20ms PERIOD PWM' in #3

    I need to have 6x PWM output PINS in an approx 1second LOOP.

    I'm not at all sure how this can be done, remembering that SERVOs jitter if not run correctly. I noticed from looking back into threads, where I asked about whether I may need a dedicated PIC just to run 6xSERVOs

    C
     
    Last edited: May 22, 2018
  8. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi,
    Just looking at page 149 of the D/S, 16.5 PWM Mode.

    Initially this looked promising, but it appears to output at the CCP1 and not the expected 6x PWM PINS, which are outputs on my PCB:confused:

    C.
     
  9. ericgibbs

    Moderator

    Jan 29, 2010
    4,852
    924
    hi C,
    I doubt if Oshonsoft Basic can cover 6 PWM pins.????
    It should be possible to use a ASM program block, in Oshonsoft Basic, using a suitable PIC that has 6 PWM's
    E
     
  10. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi E,
    Would a second 18LF4431 used solely for the job, be suitable?
    Here's a note that may help: http://ww1.microchip.com/downloads/en/DeviceDoc/31014a.pdf
    C.
     
  11. ericgibbs

    Moderator

    Jan 29, 2010
    4,852
    924
    hi C,
    Looking at the 18F4431 d/s suggets that 6 PWM pins are possible.
    Write a simple program for say just 3 PWM's and see if that is OK.
    E
     
  12. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi E,
    Ok, do I use the CODE in #4?

    EDIT: I don't understand ASM as in #4, but if I recall correctly, this uses two PINs for each PWM output, and can drive an H-Bridge. I need the type of PWM that only uses one PIN, and will drive a SERVO, which has it's own H-Bridge in it's circuit. E suggests using a dedicated PIC for only PWM.

    C.
     
    Last edited: May 23, 2018
  13. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi,

    I've searched around and found some CODE which maybe what's needed for running multiple SERVO PWM PINS from a PIC.

    It's written in 'C' which I have difficulty understanding, but kind of follow. I've copied it into an Oshonsoft program and tried to change it to BASIC. Here's where I've got to so far. Does it look promising?

    I notice that LAT is used, instead of PORT, so perhaps I'll be able to 'get it' once I've used it.

    C.
     
  14. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi,
    I'm kind of starting again, using information learnt since I started this post.

    Both TRANSMITTER PCB and RECEIVER PCB with use 18LF4520

    Here is a starter program which will READ a message, e,g, It is set for NMEA sentence at the moment, but can be used for messages between the UNITS (TX UNIT RX UNIT) Will someone run it in OSH SIM please and check it, then if ok, I'll split it into two programs TX and RX. (There is a copy and paste sentence 'get_mess: ' for HARDWARE UART)

    The TX will then be fitted into a Radio control transmitter (original radio electronics removed) set to READ 6 inputs ANALOG or DIGITAL. after a calculation the result will be SENT to the RECEIVER via a HC-12 radio module.

    The RX, will RECEIVE the TRANSMITTER MESSAGE via a HC-12 radio module and convert the MESSAGE to 6x SERVO/MOTOR CONTROL outputs attached to a model.

    Later GPS,COMPASS, ALTIMETER/BAROMETER will be added to both PCBs, for location.

    C.
     
    Last edited: Jul 11, 2018 at 7:24 AM
  15. ericgibbs

    Moderator

    Jan 29, 2010
    4,852
    924
    hi C,
    This is the same working program I posted for you a while ago, using the SPI 5110 graphics LCD.??
    Are you having a problem with it.?
    E
     
  16. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi E,
    No problems, There are some small changes, but nothing major. I wanted to make sure it was ok, before moving on. I'll now make two from one.
    Thanks, C.
     
    Last edited: Jul 11, 2018 at 10:29 AM
  17. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi,
    Here's the TRANSMITTER program:
    I'm trying to set 6 Analog inputs, and I'm stuck already!
    See between '################################ lines.
    C
     
  18. ericgibbs

    Moderator

    Jan 29, 2010
    4,852
    924
    hi C,
    You cannot use the same label for two assignments, try this.

    E
    '#####################################################
    Dim vpot0 As Byte
    Dim vpot1 As Byte
    Dim vpot2 As Byte
    Dim vpot3 As Byte
    Dim vpot4 As Byte
    Dim vpot5 As Byte
    ADCIN 0, vpot(0)
    ADCIN 1, vpot(1)
    ADCIN 2, vpot(2)
    ADCIN 3, vpot(3)
    ADCIN 4, vpot(4)
    ADCIN 5, vpot(5)
     
    Last edited: Jul 11, 2018 at 2:47 PM
  19. camerart

    Thread Starter Well-Known Member

    Feb 25, 2013
    670
    31
    Hi E,
    See attached:
    C.
     
    • ADC.jpg
      ADC.jpg
      File size:
      71.7 KB
      Views:
      3
  20. ericgibbs

    Moderator

    Jan 29, 2010
    4,852
    924
    hi C,
    I had removed your Symbols, so use the Oshonsoft code designations.
    I would suggest you don't use symbols, use the actual Oshonsoft ID's, once the program is working you can then tidy it.
    Also you did not post your Fonts Include, so I could not run it.
    E
    Dim vpot0 As Byte
    Dim vpot1 As Byte
    Dim vpot2 As Byte
    Dim vpot3 As Byte
    Dim vpot4 As Byte
    Dim vpot5 As Byte
    ADCIN 0, vpot(0)
    ADCIN 1, vpot(1)
    ADCIN 2, vpot(2)
    ADCIN 3, vpot(3)
    ADCIN 4, vpot(4)
    ADCIN 5, vpot(5)
     
Loading...