Menu

Youtube Channel - Great Cow BASIC training videos

Help
Anobium
2020-03-25
2020-05-23
1 2 > >> (Page 1 of 2)
  • Anobium

    Anobium - 2020-03-25

    Training Video #1

    This covered installing and using the tool chain to program an LED to flash.

    The code used was as follows:

    #CHIP 16F18313
    
        ' ----- Main body of program commences here.
        Do Forever
    
            'Lighten LED onboard LED for 100 milliseconds:
            PulseOut RA1, 100 ms
    
            'Then wait 900 milliseconds after LED goes off:
            Wait 900 ms
    
        Loop
    

    The video https://youtu.be/HpHDKLPF8Wc

     

    Last edit: Anobium 2020-04-15
  • Anobium

    Anobium - 2020-03-25

    Training Video #2

    This covers flashing two LEDs alternatively.

    Code used was

    #CHIP 16F18313
    
      Dir RA1 out
      Dir RA2 out
    
      'Set initial value
      RA1 = 0
      RA2 = 1
    
      ' ----- Main body of program commences here.
      Do Forever
    
        wait 1 s
        RA1 = NOT RA1
        RA2 = NOT RA1
    
      Loop
    

    and

    #CHIP 16F18313
    
      Dir RA1 out
      Dir RA2 out
    
      Dim LEDState as Byte
      LEDState = 0
    
      ' ----- Main body of program commences here.
      Do Forever
    
        IF LEDState = 0 then
          RA1 = 1
          RA2 = 0
          LEDState = 1
        else
          RA1 = 0
          RA2 = 1
          LEDState = 0
        end if
    
        wait 100 ms
    
      Loop
    

    The video

     

    Last edit: Anobium 2020-03-25
  • Anobium

    Anobium - 2020-03-26

    Training Video #3

    This covers setting the state of the two LEDs with an switch input switch.
    So, far we have covered setup, outputs, creating a variable and now inputs.

    The video shows a layout. Chris Roper provided this.. so, very grateful.

    Code used was:

    #CHIP 16F18313
    
      #OPTION Explicit
      #DEFINE GREENLED RA1
      #DEFINE REDLED   RA2
      #DEFINE SWITCH   RA0
    
      Dir GREENLED out
      Dir REDLED   out
      Dir SWITCH   in
    
    
      ' ----- Main body of program commences here.
      Do Forever
    
        if SWITCH = On then
            GREENLED = On
            REDLED   = Off
        else
            GREENLED = Off
            REDLED   = On
        end if
    
      Loop
    

    and

    #CHIP 16F18313
    
      #OPTION Explicit
      #DEFINE GREENLED RA1
      #DEFINE REDLED   RA2
      #DEFINE SWITCH   RA0
    
      Dir GREENLED out
      Dir REDLED   out
      Dir SWITCH   in
    
    
      ' ----- Main body of program commences here.
      Do Forever
    
        SetWith ( GREENLED, SWITCH )
        SetWith ( REDLED,   NOT SWITCH )
    
      Loop
    

    The video

     

    Last edit: Anobium 2020-03-26
  • bed

    bed - 2020-03-26

    Nice! For German not native English Listener it is easy to follow! Very good.

     
    • Anobium

      Anobium - 2020-03-26

      Thank you for the feeback!

       
    • stan cartwright

      stan cartwright - 2020-03-26

      someone could dub it to German. Es sind nur Worte

       
  • stan cartwright

    stan cartwright - 2020-03-26

    I saw this on email and commented on use of setwith. It seemed a jump as it's a command I have never used. I have used set. I looked setwith up in gcb help and it looked complicated.
    The demo was fine until then. This is just feed back not criticism. It just seemed a big jump for a beginner.
    I hate making videos cos I don't have the cameras,mics or even know how to use free video software like proper screen capture...using spare time to learn but some is easier than other.
    Stay well.

     
    • Anobium

      Anobium - 2020-03-27

      Re SetWith(). It is an option. To show different approaches. The reality is that there are many ways to set the state and the training only shows two.

       
  • stan cartwright

    stan cartwright - 2020-03-26

    It was a good video. Not for avr users really. OK I use the uno port names ie port c,1 but there's the 328 include that converts digital 10 whatever to the ports and that is used in gcb demos...I prefer ports and define them as in the video so that was safe and option explicit too.
    avr would be just plug an usb lead in and that is it. Plus you get to use the gcb terminal to show results without extra hardware

     
    • Anobium

      Anobium - 2020-03-27

      The video clearly states this is for PIC. We should do same training for AVR - may be a book where we can have PIC and AVR sections.

       
  • stan cartwright

    stan cartwright - 2020-03-26

    If we took a survey, avr vs pic users? Please vote. Do you use pic or a uno/nano thingy?

     
    • Anobium

      Anobium - 2020-03-27

      Dunno answer to usage.

      AVR is relatively static in terms of the development program. The essentials of the chips are very similar hence less changes to Great Cow BASIC to support AVR.

      PIC is relatively hectice in terms of the development program. The essentials of the chips are very different hence all the changes to Great Cow BASIC to support the newer PICs.

       
  • Anobium

    Anobium - 2020-03-27

    Training Video #4

    This covers using the ADC to read the state of a potentiometer to set the state of the four LEDs.

    So, far we have covered setup, outputs, creating a variable, inputs and now ADC.

    The video shows the latest layout. Chris Roper provided this.. so, very grateful. We will be using this layout for remainder of the training.

    Code used was:

    #chip 16f18313
    #option Explicit
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
      'Declare or dimensiona a Byte variable to store the ADC value
      Dim ADCValue as Byte
    
      ' ----- Main body of program commences here.
      Do Forever
    
        'ReadAD return a byte value of 0 to 255
        ADCValue = ReadAD( ANA0 )
    
        'Test to see if in the mid point
        if ADCValue < 128 then
            LED1 = 0
            LED2 = 0
            LED3 = 1
            LED4 = 1
        else
            LED1 = 1
            LED2 = 1
            LED3 = 0
            LED4 = 0
    
        end if
    
      Loop
    

    The video

     

    Last edit: Chris Roper 2020-03-27
  • Chris Roper

    Chris Roper - 2020-03-27

    For those wishing to build the 21-Trainer board used in this and subsequent videos in this series here are a couple of construction and usage tips.

    The Two wires (Yellow and Red) show on top of the TrimPot (Potentiometer) are actually beneath the POT. They are depicted as they are for clarity when building the board to show which rows/columns they are in.

    The Blue and Black wires near the ICSP connector overlap by one column, they are not connected to each other.

    The two Green LEDs have the Anode (positive or input) Pin Bent and extended out, they are not wired in parallel with the RED LEDs just positioned as such for visual layout.

    All 4 LEDs share a common Ground (Vss or V0) connection. It is provided by the Long Black wire from the Vss Pin of the device, and it bridges between the upper and lower board sections via the Push Button Switch.

    Here is an image of a constructed board:

    The Board and the exercises are designed around the PIC16F18313 chip shown in the drawing but any 8 pin PIC will work in this circuit. Not all of the exercises will work on an older PIC but many will so play along even if you do not have a PIC16F18313 device.

    You can also Build a Board to accept a 14 PIN PIC by using a slim Push Button switch or mounting your switch off the Breadboard:

    This option may be useful if you do not have any 8 pin PIC Devices, as again most examples will work on the 14 pin device.

    If you have a Microchip Low Pin Count Demo Board from either the PICkit2 or PICKit3 bundle you can of course use that or the later Curiosity Board.

    If you do not have any suitable PIC devices then you may use an Arduino Board instead and if you do not have an Arduino to try it on you can use an Arduino Simulator:

    The simulator may be downloaded from here:
    https://sourceforge.net/projects/picsim/

    And the Workspace File from here:
    https://sourceforge.net/p/gcbasic/discussion/579127/thread/6a952bedb2/05aa/attachment/Arduino-21-Lockdown.pzw

    So lets turn The 21 Days of Lockdown into 21 days to Lockdown your Great Cow BASIC skills.
    We will have things of interest for users of all levels and you have no excuse not to follow along.
    If you don't have any hardware you can use the Simulator instead, and we all have time on our hands at the moment.

    Cheers, and stay safe in these worrying times,

    Chris Roper

     
  • Anobium

    Anobium - 2020-03-28

    Training Video #5

    This covers using PWM to the power to one of more LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session show two methods:

    1. Software PWM. This method can be used on any chip, but, the signal is only operational when the command is operational.
    2. Hardware PWM using the CCP/PMW module. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.

    The video uses the latest board layout, same as training session 4, from Chris Roper provided this.

    Code used was:

    #chip 16F18313
    #option Explicit
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
       ; ----- Constants
          'PWM constant. This is a required constant.
          #define PWM_Out1 LED1
    
        ; ----- Define Hardware settings
          'PWM port out.  This is not required but good practice.
          dir PWM_Out1 out
    
          'A potentiometer is attached to ANO
    
        ; ----- Variables
          ' No Variables specified in this example.
    
        ; ----- Main body of program commences here.
            do
              '100 cycles is a purely arbitrary value
                PWMOut 1, ReadAD(AN0), 100
                wait 5 s
    
            loop
        end
    

    and

    #chip 16F18313
    #option Explicit
    
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.1
        'PinManager data: v1.79.0
        'Generated for 16f18313
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f18313
    
        Sub InitPPS
    
                'Module: CCP1
                RA1PPS = 0x000C    'CCP1 > RA1
                CCP1PPS = 0x0001    'RA1 > CCP1 (bi-directional)
                RA2PPS = 0x000C    'CCP1 > RA2
                CCP1PPS = 0x0002    'RA2 > CCP1 (bi-directional)
                RA4PPS = 0x000C    'CCP1 > RA3
                CCP1PPS = 0x0004    'RA3 > CCP1 (bi-directional)
                RA5PPS = 0x000C    'CCP1 > RA5
                CCP1PPS = 0x0005    'RA5 > CCP1 (bi-directional)
    
        End Sub
        'Template comment at the end of the config file
    
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
      #define PWM_Freq 40      'Frequency of PWM in KHz
      #define PWM_Duty 60      'Duty cycle of PWM (%)
    
    
    
    
    
    
      Do forever
    
          PWMOn
          wait 2 s
          PWMOff
          wait 2 s
    
      Loop
    

    The video

     
  • Moto Geek

    Moto Geek - 2020-04-02

    Evan, I have sent a link to this to several of my cohorts. Great Job, I can't wait to see the rest. Social distancing is getting stricter here in Florida and has given me the opportunity to get back in to the Great Cow Basic Groove. Good Stuff!!!!

     
    👍
    1
  • Anobium

    Anobium - 2020-04-03

    PMW Training - damn cool

    #chip 16f18313
    #option Explicit
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.1
        'PinManager data: v1.79.0
        'Generated for 16f18313
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f18313
    
        Sub InitPPS
    
                'Module: PWM5
                RA1PPS = 0x0002    'PWM5 > RA1
                RA2PPS = 0x0002    'PWM5 > RA2
                RA4PPS = 0x0002    'PWM5 > RA4
                RA5PPS = 0x0002    'PWM5 > RA5
    
        End Sub
        'Template comment at the end of the config file
    
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
      'Declare or dimensiona a Byte variable to store the ADC value
      Dim ADCValue as Byte
    
      ' ----- Main body of program commences here.
    
      HPWM 5, 40, ADCValue, 2
    
      Do Forever
    
        'ReadAD return a byte value of 0 to 255
        ADCValue = ReadAD( ANA0 )
        HPWMUpdate 5, ADCValue
        wait 100 ms
    
      Loop
    
     
  • Anobium

    Anobium - 2020-04-03

    Great Cow BASIC: Part 6: Controlling the outputs to set power of LEDs with PWM/CCPn & PWMn Module - this allows you to nine PWM signals with very small program memory usage.

    The training session explains how to set up and use multiple channels for 1) CCP/PWM and 2) the PWM module with a static PWM frequency and duty

    This training session uses PWM to the power to one of more LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session show two methods:

    1. CCP/PWM channel. This method support up to nine CCP/PWM channels. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.

    2. PWM module. This method support up to nine PWM modules. The signal is constant and uses no CPU cycles. The method shown generates a fixed frequency and fixed duty cycle - these can be changed by changing the source code but the frequency and duty cycle cannot be changed within your program. The chip requires the use of PPS - this is also covered.

    The video uses the latest board layout, same as training session 4, from Chris Roper provided this.

    Code used was:

    #chip 16F18313
    #option Explicit
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.1
        'PinManager data: v1.79.0
        'Generated for 16f18313
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f18313
    
        Sub InitPPS
    
                'Module: CCP1
                RA1PPS = 0x000C    'CCP1 > RA1
                CCP1PPS = 0x0001    'RA1 > CCP1 (bi-directional)
                'Module: CCP2
                RA2PPS = 0x000D    'CCP2 > RA2
                CCP2PPS = 0x0002    'RA2 > CCP2 (bi-directional)
    
        End Sub
        'Template comment at the end of the config file
    
    
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
      #define PWM_Timer2_Freq 16
      #define PWM_1_Duty 75
      #define PWM_1_Clock_Source 2
    
    
      #define PWM_2_Duty 25
      #define PWM_2_Clock_Source 2
    
      PWMOn (1)
      PWMOn (2)
    
      do
      loop
    

    and

    #chip 16F18313
    #option Explicit
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.1
        'PinManager data: v1.79.0
        'Generated for 16f18313
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f18313
    
        Sub InitPPS
    
                'Module: PWM5
                RA1PPS = 0x0002    'PWM5 > RA1
                'Module: PWM6
                RA2PPS = 0x0003    'PWM6 > RA2
    
        End Sub
        'Template comment at the end of the config file
    
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
      #define PWM_Timer2_Freq 16
      #define PWM_5_Duty 75
      #define PWM_5_Clock_Source 2
    
    
      #define PWM_6_Duty 25
      #define PWM_6_Clock_Source 2
    
      PWMOn (1, PWMModule )
      PWMOn (2, PWMModule )
    
      do
      loop
    

    The video is here: https://youtu.be/532gxSRI_w8

     
  • Anobium

    Anobium - 2020-04-03

    Great Cow BASIC: Part 7: Controlling the outputs to set duty and frequencies of LEDs with PWM Module.

    The training session explains how to set up and use multiple PWM modules PWM module with a variable PWM duty and frequency.

    This training session uses PWM to the power to some of the LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session shows:

    1. PWM module. This method support up to nine PWM modules. The signal is constant and uses no CPU cycles. The method shown generates a variable duty cycle and frequency. These frequency is changed within the program using a simple calculation and the duty cycle is changed using the value returned from the 10bit ADC. The chip requires the use of PPS - this is also covered.

    The video uses the latest board layout, same as training session 4, from Chris Roper provided this.

    Code used was:

    'Static demo at start
    '''A demonstration program for GCGB and GCB.
    '''The program shows PWM options for this device
    ''':
    '''This demonstration how use the PWM 10 bit Module but with this method you can change the parameters.
    ''':
    '''Change the PPS to test different module, but, remember to change the CONSTANTS!!
    '''This default to PWM but you can change the PWM parameters.
    '''
    '''You can make the ASM smaller, adapt the PWM Optimisation!!
    '''
    '''@author  EvanV
    '''@licence GPL
    '''@version 1.0a
    '''@date    24.03.2020
    '''*************************************************************************
    
    'Chip Settings
    #CHIP 16F18313
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.1
        'PinManager data: v1.79.0
        'Generated for 16f18313
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f18313
    
        Sub InitPPS
    
                'Module: PWM5
                RA1PPS = 0x0002    'PWM5 > RA1
                'Module: PWM6
                RA2PPS = 0x0003    'PWM6 > RA2
    
        End Sub
        'Template comment at the end of the config file
    
    
        Dir RA1 Out
        Dir RA2 Out
    
    
    
    Do
    
        'use for-loop to show the duty changing a 10bit value
        Dim dutyvalue As Word
        For dutyvalue = 0 To 1023
            HPWM 5, 8, dutyvalue, 2
            HPWM 6, 8, 1023-dutyvalue, 2
            wait 5 ms
        Next
    
    Loop
    

    and the code created during the video is:

    #chip 16f18313
    #option Explicit
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.1
        'PinManager data: v1.79.0
        'Generated for 16f18313
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f18313
    
        Sub InitPPS
    
                'Module: PWM5
                RA1PPS = 0x0002    'PWM5 > RA1
                'Module: PWM6
                RA2PPS = 0x0003    'PWM6 > RA2
    
        End Sub
        'Template comment at the end of the config file
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
    
      Dim ADCValue as word
      Dim DynamicFrq as Byte
    
      DynamicFrq = 1
    
      Do forever
    
        ADCValue = ReadAD10( ANA0 )
        HPWM ( 5, DynamicFrq, ADCValue, 2 )
        HPWM ( 6, DynamicFrq, 1023-ADCValue, 2 )
        wait 100 ms
        DynamicFrq = DynamicFrq + 1
        if DynamicFrq > 32 then
            DynamicFrq = 1
        end if
    
      Loop
    
    
      ''' GCB Optimisation file
    
      'Optmise PWM.h
          #define USE_HPWMCCP1 FALSE
          #define USE_HPWMCCP2 FALSE
          #define USE_HPWMCCP3 FALSE
          #define USE_HPWMCCP4 FALSE
          #define USE_HPWMCCP5 FALSE
    
          #define USE_HPWM1 FALSE
          #define USE_HPWM2 FALSE
          #define USE_HPWM3 FALSE
          #define USE_HPWM4 FALSE
          #define USE_HPWM5 TRUE
          #define USE_HPWM6 TRUE
          #define USE_HPWM7 FALSE
          #define USE_HPWM8 FALSE
    
          #define USE_HPWM_TIMER2 TRUE
          #define USE_HPWM_TIMER4 FALSE
          #define USE_HPWM_TIMER6 FALSE
    
      'Optimise A-d.h
        'Standard family chips
          #define USE_AD0 TRUE
          #define USE_AD1 FALSE
          #define USE_AD2 FALSE
          #define USE_AD2 FALSE
          #define USE_AD3 FALSE
          #define USE_AD4 FALSE
          #define USE_AD5 FALSE
          #define USE_AD6 FALSE
          #define USE_AD7 FALSE
          #define USE_AD8 FALSE
          #define USE_AD9 FALSE
          #define USE_AD10 FALSE
          #define USE_AD11 FALSE
          #define USE_AD12 FALSE
          #define USE_AD13 FALSE
          #define USE_AD14 FALSE
          #define USE_AD15 FALSE
          #define USE_AD16 FALSE
          #define USE_AD17 FALSE
          #define USE_AD18 FALSE
          #define USE_AD19 FALSE
          #define USE_AD20 FALSE
          #define USE_AD21 FALSE
          #define USE_AD22 FALSE
          #define USE_AD23 FALSE
          #define USE_AD24 FALSE
          #define USE_AD25 FALSE
          #define USE_AD26 FALSE
          #define USE_AD27 FALSE
          #define USE_AD28 FALSE
          #define USE_AD29 FALSE
          #define USE_AD30 FALSE
          #define USE_AD31 FALSE
          #define USE_AD32 FALSE
          #define USE_AD33 FALSE
          #define USE_AD34 FALSE
    
          'Family of chips based on 16f1688x with ADCON3 register
          #define USE_ADA0 FALSE
          #define USE_ADA1 FALSE
          #define USE_ADA2 FALSE
          #define USE_ADA3 FALSE
          #define USE_ADA4 FALSE
          #define USE_ADA5 FALSE
          #define USE_ADA6 FALSE
          #define USE_ADA7 FALSE
          #define USE_ADB0 FALSE
          #define USE_ADB1 FALSE
          #define USE_ADB2 FALSE
          #define USE_ADB3 FALSE
          #define USE_ADB4 FALSE
          #define USE_ADB5 FALSE
          #define USE_ADB6 FALSE
          #define USE_ADB7 FALSE
          #define USE_ADC0 FALSE
          #define USE_ADC1 FALSE
          #define USE_ADC2 FALSE
          #define USE_ADC3 FALSE
          #define USE_ADC4 FALSE
          #define USE_ADC5 FALSE
          #define USE_ADC6 FALSE
          #define USE_ADC7 FALSE
          #define USE_ADD0 FALSE
          #define USE_ADD1 FALSE
          #define USE_ADD2 FALSE
          #define USE_ADD3 FALSE
          #define USE_ADD4 FALSE
          #define USE_ADD5 FALSE
          #define USE_ADD6 FALSE
          #define USE_ADD7 FALSE
          #define USE_ADE0 FALSE
          #define USE_ADE1 FALSE
          #define USE_ADE2 FALSE
    

    The video is here: https://youtu.be/3Eo7W7k3yqA

     
  • Anobium

    Anobium - 2020-04-03

    Great Cow BASIC: Part 8: Controlling the outputs to set the LEDs using a state engine

    The training session explains how to use SELECT CASE to create a simple state machine that controls the LEDs.

    This training session uses state machine to set the LEDs. So, far we have covered setup, outputs, creating a variable, inputs and now PWM. The session shows:

    1. How to create a simple state machine controlled by a switch.
    2. How to create a simple state machine controlled by the value of the ADC.

    The video uses the latest board layout, same as training session 4, from Chris Roper provided this.

    Code used was:

    #chip 16F18313
    #option Explicit
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    Type:   -------|LED|LED|SW |LED|LED|ADC
    Real:           RA5 RA4 RA3 RA2 RA1
    Name:   -------| 4 | 3 |SW | 2 | 1 |ANA0
    -----------------------------------------
    */
    
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    CAP:   -------|LED|LED|SW |LED|LED|ADC|-
    -----------------------------------------
    STATE TABLE
    STATE 1       | 0 | 0 |   | 0 | 1 |   |
    STATE 2       | 0 | 0 |   | 1 | 0 |   |
    STATE 3       | 0 | 1 |   | 0 | 0 |   |
    STATE 5       | 1 | 0 |   | 0 | 0 |   |
    
    */
    
    
      Dim LEDState as Byte
      'Initilize the variable to zero
      LEDState = 0
    
    
      ' ----- Main body of program commences here.
      Do Forever
    
        Select Case LEDState
          case 0
            'Set one LED on... could 1 or ON
            LED1 = 1
            LED2 = 0
            LED3 = 0
            LED4 = 0
            LEDState = 1
          case 1
            LED1 = 0
            LED2 = 1
            LED3 = 0
            LED4 = 0
            LEDState = 2
          case 2
            LED1 = 0
            LED2 = 0
            LED3 = 1
            LED4 = 0
            LEDState = 3
          case 3
            LED1 = 0
            LED2 = 0
            LED3 = 0
            LED4 = 1
            LEDState = 0
        end select
    
        wait 500 ms
    
        wait while switch = 0
    
      Loop
    

    and the code created during the video is:

    #chip 16F18313
    #option Explicit
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    Type:   -------|LED|LED|SW |LED|LED|ADC
    Real:           RA5 RA4 RA3 RA2 RA1
    Name:   -------| 4 | 3 |SW | 2 | 1 |ANA0
    -----------------------------------------
    */
    
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    CAP:   -------|LED|LED|SW |LED|LED|ADC|-
    -----------------------------------------
    STATE TABLE
    STATE 1       | 0 | 0 |   | 0 | 1 |   |
    STATE 2       | 0 | 0 |   | 1 | 0 |   |
    STATE 3       | 0 | 1 |   | 0 | 0 |   |
    STATE 5       | 1 | 0 |   | 0 | 0 |   |
    
    */
    
    
      Dim ADCValue as Byte
    
    
      ' ----- Main body of program commences here.
      Do Forever
    
        ADCValue = READAD ( ANA0 )
    
        Select Case ADCValue
          case 0 to 63
            'Set one LED on... could 1 or ON
            LED1 = 1
            LED2 = 0
            LED3 = 0
            LED4 = 0
    
          case 64 to 127
            LED1 = 0
            LED2 = 1
            LED3 = 0
            LED4 = 0
    
          case 128 to 191
            LED1 = 0
            LED2 = 0
            LED3 = 1
            LED4 = 0
    
          case 192 to 255
            LED1 = 0
            LED2 = 0
            LED3 = 0
            LED4 = 1
    
        end select
    
        wait 500 ms
    
        wait while switch = 0
    
      Loop
    

    The video is here: https://youtu.be/ASLWNJemIJ8

     
  • Anobium

    Anobium - 2020-04-03

    Great Cow BASIC: Part 9: Controlling the LEDs rotation direction using a switch and an Interrupt.

    The training session explains how to use a switch and an interrupt routine set the state machine that controls the LEDs.

    This training session uses state machine to set the LEDs. So, far we have covered setup, outputs, creating a variable, inputs, PWM and now interrupts.

    The session shows:
    1. Adapting the training session 8a code to create a simple state machine controlled by a switch.
    2. Adding an interrupt to handle the switch press event which then changes the simple state machine.

    The video uses the latest board layout, same as training session 4, from Chris Roper provided this.

    Code used was:

    #chip 16F18313
    #option Explicit
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    Type:   -------|LED|LED|SW |LED|LED|ADC
    Real:           RA5 RA4 RA3 RA2 RA1
    Name:   -------| 4 | 3 |SW | 2 | 1 |ANA0
    -----------------------------------------
    */
    
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    CAP:   -------|LED|LED|SW |LED|LED|ADC|-
    -----------------------------------------
    STATE TABLE
    STATE 1       | 0 | 0 |   | 0 | 1 |   |
    STATE 2       | 0 | 0 |   | 1 | 0 |   |
    STATE 3       | 0 | 1 |   | 0 | 0 |   |
    STATE 5       | 1 | 0 |   | 0 | 0 |   |
    
    */
    
    
      Dim LEDState as Integer
      'Initilize the variable to zero
      LEDState = 0
    
      Dim Direction as Integer
      Direction = -1
    
    
      ' ----- Main body of program commences here.
      Do Forever
    
        Select Case LEDState
          case 0
            'Set one LED on... could 1 or ON
            LED1 = 1
            LED2 = 0
            LED3 = 0
            LED4 = 0
          case 1
            LED1 = 0
            LED2 = 1
            LED3 = 0
            LED4 = 0
          case 2
            LED1 = 0
            LED2 = 0
            LED3 = 1
            LED4 = 0
          case 3
            LED1 = 0
            LED2 = 0
            LED3 = 0
            LED4 = 1
        end select
    
        LEDState = LEDState + Direction
        If LEDState = 4  then LEDState = 0
        If LEDState = -1 then LEDState = 3
    
    
        wait 500 ms
    
        if switch = 0 then
            if Direction = 1 then
              Direction = -1
            else
              Direction = 1
            End if
            wait while switch = 0
        end if
    
      Loop
    

    and the code created during the video is:

    #chip 16F18313
    #option Explicit
    
      #define LED1 RA1
      #define LED2 RA2
      #define LED3 RA4
      #define LED4 RA5
    
      #define SWITCH  RA3
      #define VR1  RA0
    
      Dir LED1 out
      Dir LED2 out
      Dir LED3 out
      Dir LED4 out
      Dir SWITCH  in
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    Type:   -------|LED|LED|SW |LED|LED|ADC
    Real:           RA5 RA4 RA3 RA2 RA1
    Name:   -------| 4 | 3 |SW | 2 | 1 |ANA0
    -----------------------------------------
    */
    
    
    /*
    -------------------LATA-----------------
    Bit#:  -7---6---5---4---3---2---1---0---
    CAP:   -------|LED|LED|SW |LED|LED|ADC|-
    -----------------------------------------
    STATE TABLE
    STATE 1       | 0 | 0 |   | 0 | 1 |   |
    STATE 2       | 0 | 0 |   | 1 | 0 |   |
    STATE 3       | 0 | 1 |   | 0 | 0 |   |
    STATE 5       | 1 | 0 |   | 0 | 0 |   |
    
    */
    
      On Interrupt PORTChange call MyISR
      IOCAN3 = 1
    
      Dim LEDState as Integer
      'Initilize the variable to zero
      LEDState = 0
    
      Dim Direction as Integer
      Direction = -1
    
    
      ' ----- Main body of program commences here.
      Do Forever
    
        Select Case LEDState
          case 0
            'Set one LED on... could 1 or ON
            LED1 = 1
            LED2 = 0
            LED3 = 0
            LED4 = 0
          case 1
            LED1 = 0
            LED2 = 1
            LED3 = 0
            LED4 = 0
          case 2
            LED1 = 0
            LED2 = 0
            LED3 = 1
            LED4 = 0
          case 3
            LED1 = 0
            LED2 = 0
            LED3 = 0
            LED4 = 1
        end select
    
        LEDState = LEDState + Direction
        If LEDState = 4  then LEDState = 0
        If LEDState = -1 then LEDState = 3
    
        wait ReadAD10( ANA0 ) ms
    
      Loop
    
      Sub MyISR
    
            if Direction = 1 then
              Direction = -1
            else
              Direction = 1
            End if
            IOCAF3 = 0
    
      End Sub
    

    The video is here: https://youtu.be/6nvX3ceWY8Q

     
  • Anobium

    Anobium - 2020-04-03

    Great Cow BASIC: Part 10: Using the software to communicate via the serial port to a PC terminal.

    The video shows using the software to communicate via the serial connection to a PC terminal, and, show the value of the potentiate

    The session shows:
    1. Connecting the USART module to RA5 using PPS, and, send ‘Hello World’
    2. Adapting the program to send the value of ADC on the terminal
    3. Adapting the program to send a ‘scaled’ value of ADC on the terminal

    The video uses the latest board layout, same as training session 4, from Chris Roper provided this.

    Code used was:

    #chip 16f18313
    #option Explicit
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.1
        'PinManager data: v1.79.0
        'Generated for 16f18313
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f18313
    
        Sub InitPPS
    
                'Module: EUSART
                RA5PPS = 0x0014    'TX > RA5
    
        End Sub
        'Template comment at the end of the config file
    
        'USART settings for USART1
        #define USART_BAUD_RATE 9600
        #define USART_TX_BLOCKING
        #define USART_DELAY OFF
    
    /*
    Part One  - Hello World
    
        do Forever
          HSerPrint "Hello World"
          HSerPrintCRLF
          wait 1 s
        loop
    */
    
    /*
    Part Two - Send the ADC value to the terminal software
        do Forever
          HSerPrint "ReadAD = "
          HSerPrint ReadAD( ANA0 )
          HSerPrintCRLF
          wait 1 s
        loop
    */
    
    //Part three - Send a scaled, with a scaled value of between 0 and 100 when the input value is 0 to 236, ADC value to the terminal software
    
        do Forever
          HSerPrint "Scaled = "
          HSerPrint Scale( ReadAD( ANA0 ), 0, 236, 0, 100 )
          HSerPrintCRLF
          wait 1 s
        loop
    

    The video is here: https://youtu.be/hm33YCXMBfY

     
  • Anobium

    Anobium - 2020-04-03

    Great Cow BASIC: Part 11: Using the software to create bi-directional communications between the microcontroller and the PC terminal software using an interrupt driven serial ring buffer.

    This session shows using the software to communicate between the PC terminal software and the microcontroller - what you send to the microcontroller is returned back. From this example you can build 100s of solutions.

    The session shows:
    1. We will connect the USART module using PPSTool
    RA5 for TX
    RA2 for RX
    2. We use existing code in the Help to create overall program
    3. Send data... And the data comes back

    The video uses the latest board layout, same as training session 4, from Chris Roper provided this.

    Code used was:

    ~~~

    chip 16f18313

    option Explicit

    'Generated by PIC PPS Tool for Great Cow Basic
    'PPS Tool version: 0.0.6.1
    'PinManager data: v1.79.0
    'Generated for 16f18313
    '
    'Template comment at the start of the config file
    '
    #startup InitPPS, 85
    #define PPSToolPart 16f18313
    
    Sub InitPPS
    
            'Module: EUSART
            RA5PPS = 0x0014    'TX > RA5
            RXPPS = 0x0002    'RA2 > RX
    
    End Sub
    'Template comment at the end of the config file
    
    ' Add PPS if appropiate for your chip
    ' [change to your config] This is the config for a serial terminal
    ' turn on the RS232 and terminal port.
    ' Define the USART settings
    #DEFINE USART_BAUD_RATE 9600
    
    'This assumes you are using an ANSI compatible terminal.  Use PUTTY.EXE it is very easy to use.
    
    '   Main program
    
    'Create the supporting variables
    Dim next_in As Byte
    Dim next_out As Byte
    Dim syncbyte As Byte
    Dim temppnt As Byte
    
    ' Constants etc required for Buffer Ring
    #DEFINE BUFFER_SIZE 8
    #DEFINE bkbhit (next_in <> next_out)
    
    'Define the Buffer
    Dim buffer( BUFFER_SIZE - 1 ) 'we will use element 0 in the array as part of out buffer
    
    'Call init the buffer
    InitBufferRing
    
    HSerSend 10
    HSerSend 13
    HSerSend 10
    HSerSend 13
    HSerPrint "Started: Serial between two devices"
    HSerSend 10
    HSerSend 13
    
    
    'Get character(s) and send back
    Do
    
        ' Do we have data in the buffer?
        if bkbhit then
    
            'Send the next character in the buffer, exposed via the function `bgetc` back the terminal
            HSerSend bgetc
    
        end if
    
    Loop
    
    'Supporting subroutines
    
    Sub readUSART
    
        buffer(next_in) = HSerReceive
        temppnt = next_in
        next_in = ( next_in + 1 ) % BUFFER_SIZE
        If ( next_in = next_out ) Then  ' buffer is full!!
            next_in = temppnt
        End If
    
    End Sub
    
    Function bgetc
        Dim local_next_out as Byte    'maintain a local copy of the next_out variable to ensure it does not change when an Interrupt happens
        local_next_out = next_out
        bgetc = buffer(local_next_out)
        local_next_out=(local_next_out+1) % BUFFER_SIZE
        INTOFF
        next_out = local_next_out
        INTON
    End Function
    
    
    
    
    Sub InitBufferRing
    
        'Set the buffer to the first address
        next_in = 0
        next_out = 0
        'Interrupt Handler - some have RCIE and some have U1RXIE, so handle
        #IFDEF BIT( RCIE )
            On Interrupt UsartRX1Ready Call readUSART
        #ENDIF
        #IFDEF BIT( U1RXIE )
            On Interrupt UART1ReceiveInterrupt Call readUSART
        #ENDIF
    
    End Sub
    ~~~
    

    The video is here: https://youtu.be/dyMyRMwemDY

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.