Workshop 9: Pulse Input

 

Purpose: Using the embedded controller to measure the duration of an input pulse.

Objective: This workshop is designed to familiarize the student with elements of the embedded microcontroller.

Real world application: Speedometer

Requirements:

Hardware: Pin9 RS-232 connector , Max 233 (TTL to RS-232 converter chip), Pulse Generator

Software Commands: Branch

Procedure: Design and implement speedometer program. Use a pulse generator in place of the actual shaft rotation output switch to provide the pulse input to the Picstic. When the input pulse width is 10 milliseconds then the speed is 30 mph (maximum). Each 10-millisecond increase in the pulse width decreases the speed by 1 mph. After the program calculates the speed, it should output the correct speed to the PC. The on screen display shall look as follows:

<speed value> MPH

Circuit Drawing for Workshop #9

 

PicBasic Code for Workshop #9

 

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

'This program will take in a speed input using pulsin
'Command, then output a speed value to a PC. The speed
'output will be proportional to the pulse length stored
'b5. The lower the value in b5 the faster the speed.
'Herb Wagner

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

begn:
         pulsin 0,1,b5                       'take input on pin0

'Depending on the input (b5) jump to the correct branching
'point (max speeds is test1 min. speed is test6)
            if b5 > 1 and b5 <= 5 then test1
            if b5 > 5 and b5 <= 10 then test2
            if b5 > 10 and b5 <= 15 then test3
            if b5 > 15 and b5 <= 20 then test4
            if b5 > 20 and b5 <= 25 then test5
            if b5 > 25 and b5 <= 30 then test6
            if b5 = 0 then test7

'**********************************************************

test1: branch b5,(mph1,mph2,mph3,mph4,mph5)               'branch to
                                                                                 'set proper speed
mph1:       b2 = 30
         goto speed
mph2:      b2 = 29
         goto speed
mph3:     b2 = 28
         goto speed
mph4:     b2 = 27
         goto speed
mph5:    b2 = 26
        goto speed

'**********************************************************

test2:     b2 = b5 - 5             'subtract offset
         branch b2,(mph6,mph7,mph8,mph9,mph10)           'branch to
                                      'set proper speed
mph6:    b2 = 25
         goto speed
mph7:    b2 = 24
        goto speed
mph8:    b2 = 23
        goto speed
mph9:    b2 = 22
         goto speed
mph10:  b2 = 21
         goto speed

'**********************************************************

test3:    b2 = b5 - 10                     'subtract offset
         branch b2,(mph11,mph12,mph13,mph14,mph15)        'branch to
                                              'set proper speed
mph11:    b2 = 20
          goto speed
mph12:   b2 = 19
          goto speed
mph13:   b2 = 18
          goto speed
mph14:   b2 = 17
          goto speed
mph15:   b2 = 16
          goto speed

'**********************************************************

test4:    b2 = b5 - 15                       'subtract offset
branch b2,(mph16,mph17,mph18,mph19,mph20)      'branch to
                                                'set proper speed
mph16:  b2 = 15
          goto speed
mph17:  b2 = 14
          goto speed
mph18:  b2 = 13
          goto speed
mph19:  b2 = 12
          goto speed
mph20:  b2 = 11
          goto speed

'**********************************************************

test5:   b2 = b5 - 20                    'subtract offset
           branch b2,(mph21,mph22,mph23,mph24,mph25)    'branch to
                                        'set proper speed
mph21:   b2 = 10
          goto speed
mph22:   b2 = 9
          goto speed
mph23:   b2 = 8
          goto speed
mph24:   b2 = 7
          goto speed
mph25:   b2 = 6
          goto speed

'**********************************************************

test6:   b2 = b5 - 25                  'subtract offset
       branch b2,(mph26,mph27,mph28,mph29,mph30)           'branch to
                                          'set proper speed
mph26:   b2 = 5
          goto speed
mph27:   b2 = 4
          goto speed
mph28:   b2 = 3
          goto speed
mph29:   b2 = 2
          goto speed
mph30:   b2 = 1
          goto speed

'**********************************************************

'Default outputs

test7: b2 = 0
       goto speed
test8: b2 = 30

'**********************************************************

speed: serout 1,T2400,(#b2," MPH")          'output speed
pause 500                                               'set delay
goto begn

 

 

Qbasic Code for Workshop #9

OPEN "com1:2400,n,8,1,cd0,cs0,ds0,op0" FOR RANDOM AS #1

BEGIN:
          CLS
          data$ = INPUT$(6, #1)
          PRINT data$;
          GOTO BEGIN
END