• AVR Freaks

Hot!arduiono user needs help with PIC

Author
donrecardo
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2016/04/21 10:07:04
  • Location: 0
  • Status: offline
2019/08/09 04:24:14 (permalink)
0

arduiono user needs help with PIC

Hi
    I accept Arduino is probably a dirty word on here but I can sort of use arduinos to do what I need
    Pic chips are more of a mystery to me
 
I have an Arduino program I have written that works fine but an arduino board is physically just too big
I would like to do the same thing with a Pic chip and the minimum of other components if possible, even
beter if I could do it with one of the 6 pin Pics
 
I have a R/C transmitter and on one of the channels I have an on/off switch that sends out a PWM signal
of about 1000 µSecs when off and about 2000 µSecs when on 
 
If I take the output from the R/C receiver and use the Arduino " pulseIn" command it tells me the width of the pulse
Its then simple to say if the pulse is less than 1500 µSecs ( the mid point between on and off) the switch is off 
or more than 1500 µSecs so the switch is on .
The arduino then turns on or off a mosfet dependant on the result . The mosfet can then handle higher current loads
 
Can someone tell me
how would a program be written to do the same job in a pic chip PIC  ? ( I doubt there is a pulseIn command like Arduino has)
I have a Pickit3 to program it with
Can it be done in one of the 6 or 8 pin chips as I only need one input and one output ?  (Nice and small especially in SMD)
would I need anything else with it , for example on an arduino I would need
a xtal and its 2 caps and also need to tie the reset line high
 
I can buy a comercially made switch thats only about 1 inch square so it must be possible
here is one  which appears to use a 6 pin chip
https://www.pololu.com/product/2802
 
hope someone can help
 
Don
#1

11 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1382
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: arduiono user needs help with PIC 2019/08/09 12:00:03 (permalink)
    +1 (1)
    donrecardo
     
    I have an Arduino program I have written that works fine but an arduino board is physically just too big
    I would like to do the same thing with a Pic chip and the minimum of other components if possible, even
    beter if I could do it with one of the 6 pin Pics

    An Arduino is basically a development board with an ATmega chip. The UNO uses the ATmega328 which is somewhat similar to the 8bit PIC chips.
    You could still prototype in the Arduino platform that you are familiar with and the final product, you could just use build your PCB around the ATmega328 chip of whatever Arduino you are working on. This could decrease the size of your project as you could remove all the components that are not relevant to your design. There are a lot of bare bone arduino tutorials that can guide you. 
    If you choose the PIC path, yes you can, as with Arduino, you will still need some other few components like a crystal circuit (could also use internal oscillator especially if you choose a newer PIC, there quite precise these days) , MCLR reset circuit if you need one.
    As you are used to Arduino libraries for almost everything, this will be your first stumbling block with PIC, you will need to learn some few basics registers, to make your life easier in the beginning, try to use a newer PIC model (use the microchip advanced part selector to filter your criteria, don't select Mature) and use Microchip Code Configurator, it will generate some library code for you.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    Jim Nickerson
    User 452
    • Total Posts : 6187
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/09 12:06:20 (permalink)
    +1 (1)
    The page you linked has a "Resources" and a schematic where the PIC is listed.
    I do not think you could purchase/make this board for the price it is sold for.
    #3
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11286
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/09 13:07:12 (permalink)
    +1 (1)
    Can it be done in one of the 6 or 8 pin chips

     
    Yes, easily.  Set up your input for interrupt-on-change, start a timer on the rising edge, and stop the timer on the falling edge.  The timer then tells you how long the pulse was.
    #4
    DougRice
    Super Member
    • Total Posts : 533
    • Reward points : 0
    • Joined: 2008/10/08 23:44:59
    • Location: 0
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/09 14:23:17 (permalink)
    0
    The Arduino is a fantastic platform.
     
    It is easy to set up and upload code as the boards has the programmer built in and the clock pre-configured and somebody has kindly written a library for the chip you have just brought. The library source code can be read to see how it is done.
     
    The built in RS232 interface is useful.
     
     
    There has been a lot of work done to make an Arduino from the Atmel chip. 
    The power is supplied off the USB lead.
     
    I think they are great if you have a simple problem that needs a quick solution.
     
    However  programming a simple 6 pin chip has an appeal to a hobbyist.
     
    I brought a 10F204 as it was so basic and had a dabble to play with it.
     
    I still needed to make a header for the programmer and read the datasheet!
    The datasheet is not too thick as the chip does not have too many features!
     
    The chip has a built in clock and to find edges I read the inputs and compare to the last read and use XOR to find the edge in a loop.
     
    A loop is used to count the time between edges. I used the MPLAB to step through the code to measure the time the loop takes to work out the counts required.
     
    I put some notes on my web site.
    http://ccgi.dougrice.plus...bin/wiki.pl?PIC_10F204
    http://www.dougrice.plus.com/dev/cn001/cn001.asm
     
     
    #5
    NorthGuy
    Super Member
    • Total Posts : 5580
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/09 14:33:46 (permalink)
    +1 (1)
    You can do it with any PIC. Physically, the smallest PICs are 8-pin ones in 2x3x0.5mm (0.5mm pitch) UDFN package, such as PIC16F1501. You certainly can do it in a smaller footprint than the Polulu board.
    #6
    nigelwright7557
    Super Member
    • Total Posts : 284
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: online
    Re: arduiono user needs help with PIC 2019/08/09 16:28:08 (permalink)
    +1 (1)
    I use the PIC12f508 quite a lot for small projects.
    Its 56p at RS Components.
     
    #7
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11286
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/09 17:04:01 (permalink)
    +4 (4)
    PIC12f508

     
    That's a horrible, ancient, primitive, expensive part that doesn't even have interrupts.  Far better options are available for less money, like the PIC10F320.
    #8
    oliverb
    Super Member
    • Total Posts : 206
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/10 00:54:17 (permalink)
    0
    If you are having to write your own code to replace the libraries then just as a suggestion you could wait for the pulse start, then wait 1500us and sample the input ONCE. if the pulse is 1ms then it will have ended and will return low. If the pulse is 2ms then the pulse won't have ended yet and will return high.
    #9
    donrecardo
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2016/04/21 10:07:04
    • Location: 0
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/10 01:10:41 (permalink)
    +1 (1)
    Hi and thank you all for your comments and advice , there were some very interesting and helpfull sugestions
    although no one actually answered my main question which was as someone that doesnt have a clue about programming Pic chips could some one help me with a program to do what I need  .
    Jtemples came close with his comment " Yes, easily.  Set up your input for interrupt-on-change, start a timer on the rising edge, and stop the timer on the falling edge.  The timer then tells you how long the pulse was."
    Thats probably a great answer but if I knew how to do that I wouldnt have needed to ask my question in the first place
    Some said its not worth building your own with the cost of buying a ready built one costs no more than the parts
    which for some may be true , but I can get pic and Atmel chips as free samples , so yes I can make it cheaper
     
    The comment I found most helpfull was Katela ( thank you) who said why not develop it on my normal arduino then put the final program on a chip and make a bare bones circuit to keep it small, That made a lot of sense so I did some more investigating. I found atmel do an 8 pin chip the ATTiny85 . Its not suppoerted by the arduino IDE but can be added quite easily . This means I can use the IDE with the language I know and love to make a program for the ATTiny and then make a bare bones circuit. This way I dont have the problem of learning to program Pic chips,
    something I might not have needed ever again
    I went to order some samples of the ATTiny85 and found even better news. Its available in a SOIJ package and
    the body of the chip is only 5.25mm square
     
    Once again thank you all for taking the time and trouble to reply to my question it was very much appreciated
    even if I didnt get the answer I wanted , At least it led me to finding out what I needed to know
     
    As an aside , while looking for chips etc I came across a circuit to do what I need without any programming
    (pic or arduino) because it contains no MCU. I uses a single CMOS chip the 4013 Dual D flip Flop. It takes the PWM pulses from the receiver to the clocks of of both flip flops . The first flip flop is used as a monostable  whos pulse length is set with a variable resitor and a capacitor . The first pulse triggers the monostable . When the second pulse arrives the second flip flop decides if the first F/F is still triggered or not , If it is still triggered the receiver is giving shorter pulses than that set by the resistor capacitor pair . If the monostable has reset the receiver pulses arer longer. so that tells me if the output mosfet should be turned on or off
     
    Don
    #10
    oliverb
    Super Member
    • Total Posts : 206
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/10 11:23:41 (permalink)
    0
    OK really short method, suitable for a 6 pin PIC with minimal resources.
    Do the following endlessly:
      wait till input is low
      wait till input is high
      delay 1.5ms
      copy input to output
     
    #11
    DougRice
    Super Member
    • Total Posts : 533
    • Reward points : 0
    • Joined: 2008/10/08 23:44:59
    • Location: 0
    • Status: offline
    Re: arduiono user needs help with PIC 2019/08/18 23:42:07 (permalink)
    0
    I read this thread again.
    The original post was about using PulseIn which is part of the Arduino code. 
    If using the small PIC, this needs to be found in the C library, or written. 
    I wondered if the Arduino PulseIn code was available and found this:
    https://github.com/BretStateham/IoT/blob/master/Intel%20Galileo/HOL%20-%2002%20-%20Running%20Windows/End/HelloGallileo/packages/Microsoft.IoT.Galileo.Arduino.1.0.4-alpha/build/native/source/PulseIn.cpp
     
    If the chip is only monitoring one pin, Oliverb's post sums it up neatly.
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5