pic telemetry system


Closed Thread
Results 1 to 24 of 24
  1. #1

    Default pic telemetry system

    hi everyone,
    I'm new to pic's and pic basic... however when i was 13 i was writing large BASIC programs on my spectrum and have since gone on to HTML, CSS, PHP etc...

    I'm using MPLAB IDE + PBP 244 for compiling (if thats correct?)
    I'm not using MPLAB IDE to compile because my BAS files are not in the compiler dir... so i used the approch listed here by creating a batch file to execute...

    I'm using PIC16F877-20I/P 's...

    i'm just asking whats the best way of doing the following items...

    1) ADC initialisation, i can't find much info on setting up the ADC's. What i've got sofar is...
    Code:
    Define  ADC_BITS        10     		' Set number of bits in result
    Define  ADC_CLOCK       3     		' Set clock source (3=rc)
    Define  ADC_SAMPLEUS    50    		' Set sampling time in uS
    Define  ADCON0			%11000001
    TRISA = %11111111					' Set PORTA to all input
    ADCON1 = %10000010					' Set PORTA analog and right justify result
    First off, i need to correct the clock source to XT not RC so, will do that later once i found the value it should be...
    My code is directly dependant on the ADC values that come in (nothing to run while it's waiting)... so i want the ADC to run as fast as possible... have i got it right? anything missing?

    2) telemetry link to my laptop... laptop has IR port so I want IR link to PIC to recieve ADC valuse and io values etc...
    i have the IR header (surfice mount mind!) the only way i can think of doing it is to direct drive the IR TX with a FET and use another FET on the reciever...
    I'm also assuming i should be using serin/out at 9600 none inv...
    I want it looping as fast as possible and give me as many ADC samples as possible per second...

    3) i can't find much info on ADC calibration... aparently the ADC can only do upto 5V, after that you need to do something externally? but can't seem to find out exactly what? can someone kick me in the right direction?


    Thanks everyone

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by comwarrior View Post
    hi everyone,
    I'm new to pic's and pic basic... however when i was 13 i was writing large BASIC programs on my spectrum and have since gone on to HTML, CSS, PHP etc...
    And this tells me you are ??teen . . . no matter, Welcome comwarrior. We always welcome Sharp Kids, when I was 13 only Governments and Giant Corporations had computers, and they used punch cards.
    Quote Originally Posted by comwarrior View Post
    I'm using MPLAB IDE + PBP 244 for compiling (if thats correct?)
    I'm not using MPLAB IDE to compile because my BAS files are not in the compiler dir... so i used the approach listed here by creating a batch file to execute...

    I'm using PIC16F877-20I/P 's...

    I'm just asking what's the best way of doing the following items...

    1) ADC initialization, I can't find much info on setting up the ADC's. What i've got so far is...
    Code:
    Define  ADC_BITS        10     		' Set number of bits in result
    Define  ADC_CLOCK       3     		' Set clock source (3=rc)
    Define  ADC_SAMPLEUS    50    		' Set sampling time in uS
    Define  ADCON0			%11000001
    TRISA = %11111111					' Set PORTA to all input
    ADCON1 = %10000010					' Set PORTA analog and right justify result
    First off, i need to correct the clock source to XT not RC so, will do that later once i found the value it should be...
    My code is directly dependant on the ADC values that come in (nothing to run while it's waiting)... so i want the ADC to run as fast as possible... have i got it right? anything missing?

    2) telemetry link to my laptop... laptop has IR port so I want IR link to PIC to recieve ADC valuse and io values etc...
    i have the IR header (surfice mount mind!) the only way i can think of doing it is to direct drive the IR TX with a FET and use another FET on the reciever...
    I'm also assuming i should be using serin/out at 9600 none inv...
    I want it looping as fast as possible and give me as many ADC samples as possible per second...

    3) i can't find much info on ADC calibration... aparently the ADC can only do upto 5V, after that you need to do something externally? but can't seem to find out exactly what? can someone kick me in the right direction?


    Thanks everyone
    OK, go into the FAQ section of the forum,
    http://www.picbasic.co.uk/forum/forumdisplay.php?f=16 ,here you will find good things, like : http://www.picbasic.co.uk/forum/showthread.php?t=543 , and make use of this to search the forum: http://www.google.com/custom?hl=en&c...ch&sitesearch=
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    ADC does not need Calibration... well... how pedantic do you want to be...

    It will always give you steps of 1/255 or 1/1023 (depending if you are in 8 or 10 bit mode) of VREF. So if VREF is 5v, you get steps of 5*(1/255) or 5*(1/1024) accordingly.

    If VREF=VDD for example, then you rarely get 5.0000v, you'll usually have some arbitrary figure between 4.9 and 5.1v. That can throw your math, if you're making a thousand units and each one has to be precisely identical to the next. It's something that either usually you can live with, or design out with more precise Voltage References or circuitry.

    For high speed, I probably wouldn't chose to use ADCIN. It only takes a tiny number of instructions to grab Data from the ADC anyway, and it's just as easy to do it manually...

  4. #4


    Did you find this post helpful? Yes | No

    Default

    @ joe - Knowledge, but no wisdom = unhelpful
    Practice what you preach and look at my profile it will tell you how old i am...

    @mel - completely avoided the question you tried (and failed) to answer = unhelpful
    I allready know it's set to 5 volts... the question was what do you use to measure more than 5 volts?

    Do you two really think I’d post here without spending days trying to find the info myself? that single one liner "...when i was 13 i was writing large BASIC programs on my spectrum and have since gone on to HTML, CSS, PHP..." should tell you I’m an experienced programmer capable of learning on my own and know to check with people that are 'supposedly' in the know to make sure I’m on the right tracks...

    So far, I’m not impressed...

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by comwarrior View Post
    @ joe - Knowledge, but no wisdom = unhelpful
    Practice what you preach and look at my profile it will tell you how old i am...
    Correct. I did not look at your profile, I do not care about your profile, I was willing to help you even if you were 13. It is a little unusual for a 27 year old MAN to profile himself from his thirteenth year, nevertheless in my rush before going to work, I tried to help. Do not worry, I will not make that mistake again. I believe you just hacked off 2 people, 1. Mel, most able to help, 2 Me, most willing to help. So here is My offer . . . Forget everything I said in My first post and have a nice life Dude.

    So far, I’m not impressed...
    TFB
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    joe, i don't mind 'hacking people off' when 'experts' post that level of rubbish...
    Besides, i doubt it's only two people...
    Perhaps you should do a search for me on utube...

    Don't worrie about the IR link... I've finally (after over yet another day totally searching) found the datasheet for the IR trancever i'm using... and it has the hardware i asked about allready built in AND it is on the same wavelengh as PC IR comms...

    So, we can cross that one off... I found some pic simulation software and it would apear my ADC's are ok... will be playing more with the program, i like it...


    Just one left... hmmm, how to measure more than 5 volts...

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    comwarrior, Use a voltage divider....

    Dave Purola,
    N8NTA

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Hmmm... I must remember to avoid spending time and effort in providing helpful information for at least the more complex part of your posting... and not answering what would be the obvious for 1st grade students of basic electrictity or physics.

    How to get your PIC input to handle more than 5 volts moust have been handled at least a dozen or more times on this forum... the SEARCH facility is a good start - and Joe is correct. For newbies, especially those with attitude, do we really have to regurgitate the same advice over and over again nigh on every month?

    Melanie (biting her lip and remaining polite!)

  9. #9
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by comwarrior View Post
    @ joe - Knowledge, but no wisdom = unhelpful
    Practice what you preach and look at my profile it will tell you how old i am...

    @mel - completely avoided the question you tried (and failed) to answer = unhelpful
    I allready know it's set to 5 volts... the question was what do you use to measure more than 5 volts?

    Do you two really think I’d post here without spending days trying to find the info myself? that single one liner "...when i was 13 i was writing large BASIC programs on my spectrum and have since gone on to HTML, CSS, PHP..." should tell you I’m an experienced programmer capable of learning on my own and know to check with people that are 'supposedly' in the know to make sure I’m on the right tracks...

    So far, I’m not impressed...
    Your second post and you are already offending the people trying to help you. Hmm ... Comwarrior, interesting choice for a name given these three postings. Perhaps you should stick with the advice given in the first reply, and use the search tools you were offered instead.

    I'm with Joe, I would have guessed 16. 27? Really?
    http://www.scalerobotics.com

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    I cant' resist!

    If 13th on a Spectrum (around 1983) now maybe 40 something. But this does not have to do with the attitude. Either you have it or not.

    Being polite is a way of life.

    Anyway, I do respect every member of this forum, but some deserve a little extra like Melanie.

    Did not got exactly all the answers? Why not re-ask? No hurt. Blaiming for un-helpful and no-one is going to help in the future. Why bother? Our time is precious besides...

    1. Set up is fine.

    2. You got it. But consider to use (if you don't) the Usart for most efficient way to send receive data and also interrupts (look for DT-INTS on the forum).

    3. As stated a resistive voltage divider is all that is needed. Simple ohms law to find the values according to your Vin/Vout needs.

    Ioannis

  11. #11
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    Perhaps you should stick with the advice given in the first reply, and use the search tools you were offered instead.

    I'm with Joe, I would have guessed 16. 27? Really?
    I dunno, maybe he thought the Google link was the standard Google and not a PICBASIC custom link, I was guessing 17, really what adult talks about their code exploits at 13 anyway? Usually I test the code and pour over the data sheets, didn't have time, but I know everything HE is looking for is here already. Keep handin' out those fish Ioannis, I am sure the recipients appreciate them. Maybe YOU CAN impress him. , funny, I never even thought of trying to impress anybody,incidentally, to everyone who has EVER Tried to help me, Thank You.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    ...really what adult talks about their code exploits at 13 anyway?
    ... the ones that have been programming for fun since an early age and know a few languages...

    As for atitude, as i allready said, i'm considerd a pro or expert or guru in various other forums and i'd be ashamed of myself if i answerd a newby's question like that...

    Quote Originally Posted by Ioannis
    Did not got exactly all the answers? Why not re-ask? No hurt. Blaiming for un-helpful and no-one is going to help in the future. Why bother? Our time is precious besides...

    1. Set up is fine.

    2. You got it. But consider to use (if you don't) the Usart for most efficient way to send receive data and also interrupts (look for DT-INTS on the forum).

    3. As stated a resistive voltage divider is all that is needed. Simple ohms law to find the values according to your Vin/Vout needs.

    Ioannis
    Ioannis, thank you, direct answer saves time...

    I'd actually ruled out using a resister type voltage devider for the reason that it draws curent from the source your measuring... I had thaught of an opamp or another type of amplifier...


    What i'm intensly looking at and trying to resolve is a little problem i seem to have with the data coming out of both hardware and software comm ports in oshonsoft's PIC simulator IDE... dispite having Baud, stop bit and parity correct I regularly get glifs coming out of the ports... but the two ports have gilfs in diferent places... and the software port reciever is reporting stop bit errors????? weird... must be a config error somewhere, thinking about it, I wonder if stop bit/parity is set to none if pic's allow it... meh, i'f sure it's a conf error, i'll find it...

    Thanks to...
    Ioannis & Dave

    Also, I think the PBP way of handling interupts is stupid... you should be allowed to write interupt handlers in PB without PBP inserting all that extra code...

    X

  13. #13
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    comwarrior, I have never seen in my 40+ years of hardware where you would have a start bit and no stop bit.. I would check the frequency being sent to the baudrate generator (clock) and see if it needs some adjustment..

    Dave Purola,
    N8NTA

  14. #14
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by comwarrior View Post
    I'd actually ruled out using a resister type voltage devider for the reason that it draws curent from the source your measuring... I had thaught of an opamp or another type of amplifier...
    Then use higher value resistors (Mohms) and a suitable opamp as an unity gain buffer, like the LMC662 series (rail to rail).


    Quote Originally Posted by comwarrior View Post
    Also, I think the PBP way of handling interupts is stupid... you should be allowed to write interupt handlers in PB without PBP inserting all that extra code...
    Read my post again. Answer is DT-INTS. It has nothing to do with PBP interrupts. Credits go to Darrel Taylor for his great contribution. Look also his site www.pbpgroup.com for the software.

    Ioannis

    P.S. I still have that old ZX Spectrum and Zeus assembler. What days was those...

  15. #15


    Did you find this post helpful? Yes | No

    Default

    ok, i see what your saying for interupt handling and i'll read more when i get fedup trying to sort the comms out...

    here is a little test program i've done to try and debug the problem with the serial comms...

    Code:
    include "modedefs.bas"
    include "bs1defs.bas"
    Define CONF_WORD = 	0x3d71
    Define  OSC				4				' Set clock speed
    
    Define  ADC_BITS        10     			' Set number of bits in result
    Define  ADC_CLOCK       3     			' Set clock source (3=rc)
    Define  ADC_SAMPLEUS    50    			' Set sampling time in uS
    
    SPBRG = 25              ' Set baud rate to 2400
    RCSTA = %10010000       ' Enable serial port and continuous receive
    TXSTA = %00100000       ' Enable transmit and asynchronous mode
    
    RCSTA = %10010000       ' Enable serial port and continuous receive
    TXSTA = %00100000       ' Enable transmit and asynchronous mode
    
    ADT1 var word							' Create ADT1 to store curent ad conversion for AD channel 0
    ADT2 var word                   		' Create ADT2 to store curent ad conversion for AD channel 1
    ADT1MAX var word						' Create ADT1MAX to store curent ADC0 max val
    ADT1MAX = 0
    ADT2MAX var word						' Create ADT2MAX to store curent ADC1 max val
    ADT2MAX = 0
    ADT1VAL var word
    ADT1VAL = 0
    ADT2VAL var word
    ADT2VAL = 0
    ADV1 var word
    
    TRISE = 255							' Set PortE to all inputs
    TRISD = 0							' Set PortD to all outputs
    TRISC = 0							' Set PortC to all outputs
    TRISB = 0							' Set PortB to all outputs
    TRISA = 255 						' Set PORTA to all input
    ADCON1 = 0 							' PORTA is analog
    
    HSEROUT [" initialised",10,13]
    SEROUT PORTB.1,t9600,[" initialised",10,13]
    
    Loop:
    ADCIN 0, ADT1
    HSEROUT [DEC5 ADT1,10,13]
    SEROUT PORTB.1,t9600,[#ADT1,10]
    goto Loop
    end
    From software UART i get...

    Code:
    +¥ֻ±Í•´
    0
    0
    software uart output is reporting incorrect stop bits when it sends the "initialising" stream...

    I should re-point out, i'm experimenting in a PIC simulator untill i get the right output...
    i have a pair of 16F877's due to arive tomarow and JDM programmer and max232 converts (serial and USB versions) due to arive at any time...

    I know i've not included the half second pause for ADC...
    so, what have i missed out from my initialisations?

    Thanks

  16. #16


    Did you find this post helpful? Yes | No

    Default

    and now... i'm having Floting Point Math 'issues' too...

    FPM sux...

  17. #17


    Did you find this post helpful? Yes | No

    Default

    ok, i got it to output the voltage... so, the analog input now output as a voltage over serial connection... so i'm posting my code for anyone else that wants to use it...

    Code:
    Loop:
    ADCIN 0, ADT1
    ADT1 = ADT1 / 64
    VARHIGH = ((48 * ADT1) / 10000)
    VARLOW = ((48 * ADT1) - (((48 * ADT1) / 10000) * 10000)) / 100
    
    HSEROUT ["DEC: ", DEC5 ADT1," V: ",DEC5 VARHIGH,".",DEC5 VARLOW,10]
    GOTO Loop:
    It's actually reading 2% low in the simulation... but thats good enough for me... may be a completely diferent case when in hardware...

  18. #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    In your soft com maybe you have to use n9600 instead of t9600.

    Ioannis

  19. #19


    Did you find this post helpful? Yes | No

    Default

    i tried all combinations of inverted output with none inverted input (into the software uart screen), vica versa and the combo's between...

    but the weird thing is... after the first line it gets all the numbers correct... so, it's almost like a sync problem... but this is all done in sim software, so why would their be and sync problems...

    next job on my telemetry system is to make a counter... or more precisely, an RPM counter...

    I'm mauling over creating a software uart buffer so that while it's waiting for the next AD conversion it can be sending the data...


    I miss the good days of sending a full byte to a hardware uart in one go and have the program go do something else... I loved having 8/16 byte buffers on uarts...
    I also (kinda) loved frying z80 chips when i got hardware wrong... programming in machine code, tape drives, 3" floppies... ahhh those were the days... although, battery backed ram modules were cool...

  20. #20
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I miss the good days of sending a full byte to a hardware uart in one go and have the program go do something else...
    But that's EXACTLY what you do with a PICs USART anyway...

    Actually thinking about it...

    I also (kinda) loved frying z80 chips when i got hardware wrong... programming in machine code, tape drives, 3" floppies... ahhh those were the days... although, battery backed ram modules were cool...
    You can do all of the above with PICs too...

  21. #21


    Did you find this post helpful? Yes | No

    Default

    Sorry mell, i meant with the software UART... my bad...

    my JDM programmer arived today... still waiting on my pair of 16F877's

    I can't help but wonder why mplab doesn't have JDM programmer in the list... i'm guessin it's a sales thing...

    I got my test board solderd up... it's only 8 mini LED's direct drive from portb whith a knight rider program done myself... simple enough for a test board...

    i'm aware of what you can do with a pic... thats why i switched from the Z80180's (it's a Z80 with dual hardware uarts and memort manager that can access upto 1meg with speeds upto 40MHz) but it kinda hard to get hold of them these days...
    PIC's seem to be the dogs cahuners...

  22. #22
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    For the soft uart case. I seldom use the software choice, but if I do, I make sure that the first thing the program does is to issue a high on the serial port (or low, depends of the way it drives the line).

    Then a pause of 1sec and the serial port is initialized to the idle state. Otherwise, it sees an invalid state and the first at least character is messed up.

    Ioannis

  23. #23


    Did you find this post helpful? Yes | No

    Default

    Morning ioannis,

    thats interesting... i completely understand where your coming from... i'm wondering if my trisb is too close (time wise) to my 'initialised' output line...

    I'm going to sim some variations including setting the port to high or low and waiting...

    Everything i've read on software UART indicates the fastes speed is 9600... can it not go any faster? 19200 would be handy...
    i understand why it's speed limited, i'm just asking if it can? other than me programing a software uart myself...

    Thanks

  24. #24
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    TRIS has nothing to do with this. Just give the serial port enough time to set idle. Normally one character (1/9600 x 10) is more than enough time for your terminal to disregard any "startup noise" from your PIC while powering up.

    As for the speed,since it is soft UART, a faster PIC/Clock will drive your port fast. 19200 is no problem for a 20MHz clock.

    Consider to use the harware UART though. It has also a 2 byte buffer and interrupt too. Even better choose a chip with 2 hardware usarts (some of the 18F series).

    Ioannis

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  3. PIC16F877A - Timer0 won't interrupt
    By WishMaster^ in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 25th April 2007, 08:25
  4. calibration clock 12f508
    By volcane in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th December 2006, 10:33
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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