Shop OBEX P1 Docs P2 Docs Learn Events
Shiftin command for the bs2 — Parallax Forums

Shiftin command for the bs2

DANNY MDANNY M Posts: 2
edited 2011-04-25 12:06 in BASIC Stamp
HELLO OUT THERE::
I HAVE JUST SPENT 2 DAYS TRYING TO UNDERSTAND WHY MY SHIFTIN IS NOT WORKING LIKE I THOUGHT I KNEW IT SHOULD WORK....OH WELL I LEARNED SO MANY NEW COMMANDS:smile:..
ANYWAY WHAT I NEED TO DO IS READ A 16 BIT WORD,THE PROBLEM IS I NEED TO READ 8 BITS MSB.,STOP FOR 250USEC., THEN READ 8 MORE BITS LSB...THEN DISPLAY DEC READING... FOR EXAMPLE IF I READ MSB=0000 0001 LSB=1111 0100..THE DEC.# IS 500 IF YOU ADD ALL THE BIT VALUES..OK NOW DIVIDE BY 100= 5.00 THAT IS HOW THE SENSOR OUTPUTS THE GAS VALUE..SO 5.00% GAS ON DISPLAY.... I THANK YOU ALL FOR ANY HELP ON THIS PROJECT.....
HERE IS MY CODE SO FAR.....
DO
MAIN:
GOSUB ENABLE
GOSUB PULSE

ENABLE:
HIGH 15 ''''THIS IS MY DATA ENABLE PIN

PULSE:



SHIFTIN 4,6,MSBPOST, [RESULTHI\8]: SHIFTIN 4,6,MSBPOST, [RESULTLO\8 ]

DEBUG BIN8 RESULTHI
DEBUG BIN8 RESULTLO," %CO2 ",CR



PAUSE 1
LOW 15
PAUSE 250 '''A PAUSE BEFORE GETTING NEW READING
LOOP

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-25 07:23
    First of all, splitting the SHIFTIN into two statements is the best way to get the timing to work. Whether just two SHIFTIN statements in a row will work or whether you'll need some sort of explicit delay between them depends on the actual time delay needed and the execution time of the SHIFTIN statements on the particular Stamp model you're using. There's some good information on execution time here under "app-notes".

    What's your question? Did you try your code fragments and they didn't work? What happened?

    If you want specific advice, you have to ask meaningful questions and supply enough information. What you've supplied is not a valid program for example. The DO / LOOP structure is wrong and you've got GOSUBs without RETURNs among other things. Maybe you should spend some time working through the "What's a Microcontroller?" tutorial and its exercises. That'll teach you PBasic including all the flow of control statements.
  • FranklinFranklin Posts: 4,747
    edited 2011-04-25 10:35
    In your code you have two gosubs and no returns. Check the manual on gosub syntax.
  • DANNY MDANNY M Posts: 2
    edited 2011-04-25 11:59
    Hello again: Ok thanks for the advise..i will put the return command in there....
    The question i have is...yes the program is working somewhat,,it will read in, and the timeing is great,the question is how to display on debug the dec. Equivlent of the binary input...i have been through the bs2 manual,books,ect.....
    ...ok thanks so much for your help..
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-25 12:06
    There are a variety of "formatters" for the SERIN, SEROUT, DEBUG, and DEBUGIN statements. Look in the Stamp Manual for details in the chapters on these statements. DEC formats values as decimal numbers, HEX is for hexadecimal, and BIN is for binary.
Sign In or Register to comment.