News:

Let's find out together what makes a PIC Tick!

Main Menu

ChatGTP

Started by ken_k, Dec 16, 2022, 02:36 AM

Previous topic - Next topic

ken_k

The internet is abuzz with discussions about ChatGPT AI.

Is this the future of coding?
Will this help with homework?
Can it write Proton Basic?
Will it save me time?
Is it a threat to Google?
Is it smarter then me? y


https://www.youtube.com/watch?v=40Kp_fa8vIw

https://www.youtube.com/results?search_query=chat+gpt+writes+code

https://www.youtube.com/watch?v=JxSlGQrXsdo

I know this is not really relevant to this forum? But it might be!

Ken K

ken_k

#1
Ok I tried this.

Q/  Can you write in proton basic language?

A/  Yes, I can write in Proton Basic. Proton Basic is a programming language that is designed for use with the Proton Development Suite, a set of tools for developing microcontroller-based projects. Proton Basic is based on the BASIC programming language and is similar to other BASIC dialects, such as Microsoft Visual Basic and Liberty BASIC.

Here is a simple example of a Proton Basic program that blinks an LED connected to pin 1 on a microcontroller:

Copy code
' Blink an LED on pin 1

DO
    HIGH 1 ' Turn on the LED
    PAUSE 500 ' Wait for 500 milliseconds
    LOW 1 ' Turn off the LED
    PAUSE 500 ' Wait for 500 milliseconds
LOOP
This program consists of a loop that alternates between turning on and off the LED connected to pin 1 on the microcontroller. The PAUSE statement is used to pause the program for a specified number of milliseconds.

To run this program, you will need the Proton Development Suite, which includes a Proton Basic compiler and other tools for developing microcontroller-based projects. You can find more information about the Proton Development Suite at the following website:

https://www.siriusmicrosystems.com/

I hope this helps! If you have any questions about Proton Basic or if you need further assistance, don't hesitate to ask.kwk@internode.on.net


Q/ can you code in positron16 basic?
A/ I apologize for misunderstanding your previous question. It appears that you are asking about a programming language called Positron16 Basic.

I am not familiar with a programming language by this name. It is possible that you may be thinking of another programming language or tool. It is also possible that Positron16 Basic is a fictional programming language or a variant of another programming language, such as Positron Basic or some other version of BASIC. Without more information, it is difficult for me to provide a more specific response. If you have any additional information or context that might help me to better understand your question, please let me know and I will do my best to assist you.










RGV250

Hi Ken,
I find it amazing what people seem to think is fantastic on the internet, obviously pople who cannot figure it out for themselves.
All it appears to have done is copied and pasted an example from Les's website, hardly writing code.
If the future programmers are relying on this heaven help us.

Bob

keytapper

I think the answer will be NO. Here is for Positron basic  ;D
Is the proton compiler deprecated? Might be.
Ignorance comes with a cost

dnaci

Openai chatGPT artificial intelligence only knows the information available until 2021. So he doesn't know about the positron compiler. There fore positron does not know. But he learned proton basic. :D

xldaedalus

I have been playing around with ChatGPT.  People said the same kind of thing about Google when it first appeared. ChatGPT as "AI" appears to be something like an automated Google.  It knows human knowledge, it know how to write code, if told how to write the code and make it better. But it is very unlikely it will create "original" code.  I see it for what it is intended to be, a tool to learn and increase productivity.  It seems about as good as an super smart 8 year old.  It knows stuff, like using a pencil can "write" stuff, without understanding how the pencil works and how that understand can be applied to making a ball point pen.

And the most important fact is that ChatGPT learns.  So, if we all start using it, we can teach it how to be a better code creator.

Here is an example dialog I had with it.

Can you write a Proton Basic Program that will convert 0-255 into fStops f1.2 to f22?

Yes, here's an example Proton Basic program that converts values ranging from 0 to 255 into f-stops ranging from f/1.2 to f/22:

vbnet
Copy code
; Proton Basic program to convert values from 0 to 255 into f-stops from f/1.2 to f/22

; Define variables
Dim value As Byte
Dim fStop As Float

; Main program loop
Do
    ; Read input value from analog input
    value = ADCIN 0

    ; Convert input value to f-stop value
    fStop = (22.0 - 1.2) * (value / 255.0) + 1.2

    ; Display f-stop value on LCD or other output
    Print "f/", Format(fStop, "0.1")

    ; Delay for a short period of time
    DelayMS 100
Loop
In this program, the input value is read from an analog input using the ADCIN command, which returns a value ranging from 0 to 255. This value is then converted to an f-stop value using a linear scaling equation that maps the input range of 0-255 to the output range of f/1.2 to f/22. The resulting f-stop value is then displayed on an LCD or other output device using the Print command. The program loops continuously, reading the input value, converting it to an f-stop value, and displaying the result with a short delay between iterations.




leefparker@yahoo.com
Can you convert that to a Procedure?

Sure, here's an example of how you could convert the previous program into a procedure:

vbnet
Copy code
; Proton Basic procedure to convert values from 0 to 255 into f-stops from f/1.2 to f/22

; Define procedure to convert value to f-stop
; Takes a byte value as input and returns a float f-stop value
; Input value should be in the range of 0-255
Procedure ConvertTofStop(value As Byte) As Float
    Dim fStop As Float
    fStop = (22.0 - 1.2) * (value / 255.0) + 1.2
    Return fStop
EndProc

; Main program loop 'Use in an example program
Do
    ; Read input value from analog input
    Dim value As Byte
    value = ADCIN 0

    ; Convert input value to f-stop value
    Dim fStop As Float
    fStop = ConvertTofStop(value)

    ; Display f-stop value on LCD or other output
    Print "f/", Format(fStop, "0.1")

    ; Delay for a short period of time
    DelayMS 100
Loop

In this program, the conversion of the input value to an f-stop value has been moved into a separate procedure called ConvertTofStop. The procedure takes a byte value as input and returns a float f-stop value. The main program loop reads the input value, calls the ConvertTofStop procedure to convert the value to an f-stop, and then displays the result with a short delay between iterations. The advantage of using a procedure is that it can be reused in other parts of the program or in other programs.

You will note there are mistakes, but the basic form is correct.  I don't know if we can teach it, but I am going to try.


leefparker@yahoo.com
Can you convert this into Microchip 18F assembly code?
Certainly, here's an example of how you could convert the previous Proton Basic program into Microchip 18F assembly code:

vbnet
Copy code
; Microchip 18F assembly program to convert values from 0 to 255 into f-stops from f/1.2 to f/22

; Define constants
equ ADC_CHANNEL = 0x00       ; Analog channel 0
equ LCD_DATA = 0xFE          ; LCD data command
equ LCD_CLEAR = 0x01         ; LCD clear command
equ LCD_HOME = 0x02          ; LCD home command

; Main program
Main:
    ; Initialize ADC
    movlw b'00000001'         ; Set ADC clock to Fosc/8
    movwf ADCON2
    movlw b'00000000'         ; Set ADC reference to Vdd
    movwf ADCON1
    bsf ADCON0, 0             ; Turn on ADC

    ; Initialize LCD
    movlw LCD_DATA            ; Select data command
    call SendLCD
    movlw LCD_CLEAR           ; Clear LCD display
    call SendLCD
    movlw LCD_HOME            ; Move cursor to home position
    call SendLCD

    ; Main program loop
Loop:
    ; Read input value from analog input
    clrf ADRESH                ; Clear ADC result registers
    clrf ADRESL
    bsf ADCON0, 1             ; Start ADC conversion
    btfsc ADCON0, 1           ; Wait for conversion to complete
    goto $-1
    movf ADRESH, w            ; Read ADC result into W register
    movwf value               ; Move value into variable

    ; Convert input value to f-stop value
    movf value, w             ; Move value into W register
    movwf temp                ; Move value into temporary variable
    movlw d'255'              ; Load constant into W register
    subwf value, w            ; Subtract value from constant
    movf temp, w              ; Move temporary variable into W register
    mulwf fStopScale          ; Multiply by f-stop scale factor
    movlw d'120'              ; Load constant into W register
    addwf prod, f             ; Add to product
    movlw d'1'                ; Load constant into W register
    movwf prod+1              ; Move constant into upper byte of product
    movf prod+1, w            ; Move upper byte of product into W register
    movwf fStop               ; Move f-stop value into variable

    ; Display f-stop value on LCD
    movlw LCD_DATA            ; Select data command
    call SendLCD
    movlw 'f'                 ; Display "f/"
    call SendLCD
    movf fStop, w             ; Move f-stop value into W register
    call DisplayFloat         ; Display f-stop value
    call Delay                ; Delay for a short period of time
    goto Loop

; Subroutine to send data to LCD
SendLCD:
    movwf PORTB                ; Send data to LCD
    bsf PORTC, 0              ; Set RS bit
    bsf PORTC, 1              ; Set E bit
    call Delay                ; Delay for a short period of time
    bcf PORTC, 1              ; Clear E bit
    return

; Subroutine to display a floating point number on LCD
DisplayFloat:
    movlw d'10'               ; Load constant into W register
    movwf digits              ; Move constant into digits counter
    movlw d'0'                ; Load constant into W register
   
Never, never, never give up

Gary Scott

#6
Give it a few years and AI will be a very useful tool, at least for us dummies that can't do it for ourselves and use such tool such as search engines

John Drew

xldaedalus,
It did a better job than I anticipated. I wonder if it would have included fuses if you told it the PIC type?
John

TimB


Ref fuses. Yesterday I asked Chatgpt to workout the fuses for a pic to run at 32Mhz on the internal osc

First attempt made a very coherent attempt but was wrong. I tried again correcting myself to ask for the OSCONN settings I actually learn something from its answer but again it was wrong.

As an example of what chatgpt can do writing code I recommend the eevblog video from a couple of days back where Dave gets it to write some Arduino code to drive 7 seg led displays

https://youtu.be/g5_Ts9SWbYs


kcsl

I've played quite a bit with it and it's a clever piece of technology no doubt, but I think the concept has a basic flaw.
If you enter a search into Google & adverts aside, you get a gazillion results and usually you can see a common theme just from the summary lines from each result displayed to get an idea of what answer you should be expecting. If 99% of the results are saying yes, it's probably fair to say the correct answer is yes. Not always, but it's a good place to start.
Chatgpt gives often gives you a lovely expanded answer that can just be completely wrong... and it lies so convincingly.

I am currently debugging a fault on an Acorn BBC computer, a computer I used extensively as a kid back in the 80's and so know fairly well.
I asked this question:
"any idea why an acorn bbc computer only displays lower case characters in mode 7"

This is it's reply:
"The Acorn BBC Microcomputer in Mode 7 displays a 40-column text display with 256 characters, but it is typically limited to only displaying lowercase characters. This is because Mode 7 uses a graphics mode that utilizes a 6x8 pixel font, which only contains lowercase characters.

If you want to display uppercase characters in Mode 7, you can modify the character set to include them. One way to do this is to create a custom character set with uppercase letters and load it into memory. There are also programs available that can modify the existing character set to include uppercase letters.

It's worth noting that the original design of the BBC Microcomputer was geared towards the education market, and lowercase letters were considered sufficient for most text-based programming tasks. The addition of uppercase letters in Mode 7 was not considered a high priority, as the other text modes (e.g., Mode 0, Mode 1) could display both uppercase and lowercase characters."


It's completely and totally wrong. I suspect it's actually talking about the Acorn Atom computer, but it's do darn convincing that it had me checking to manual to see if my memory was failing, and it's this that I don't like. It gives you one apparently well thought out and informed answer, and it can be a complete load of rubbish.

FYI... the fault with my BBC is a RAM failure.

Regards,
Joe

There's no room for optimism in software or hardware engineering.

RGV250

Hi,
I am no expert in assembler but the example for Xldaedalus has schoolboy errors and would crash the first time it was run (if it actually could run). The bit I find worrying as well is that he said he teaches it, this is not meant as a criticism to his ability but to all the garbage out on the internet that if anyone can teach it then how will it know when someone tells it a load of garbage. it is a bit like if les or me gave an answer about the compiler who would you trust. Unfortunately this so called intelligence will trust anyone who decides to try to teach it and is probably not intelligent enought to tell.

Thwere is another worry here, when everyone is too stupid to work things out for themselves there will not be anyone to tell it if it is wrong, when it does write software I hope it is not for aircraft and if so they tell us so I can stay in the airport bar so avoiding the subsequent crash.

Bob

xldaedalus

#11
Quote from: RGV250 on Feb 26, 2023, 09:11 AMI am no expert in assembler but the example for Xldaedalus has schoolboy errors and would crash the first time it was run (if it actually could run).

Like I think I said, the AI seems to be a very intelligent 8 year old.  I didn't say the conversion from basic to ASM was correct or wouldn't crash.  I merely pointed out it could be done.  AI at the moment is like an Idiot Savant. An Idiot Savant can tell me April 1st 1857 was a Tuesday but he can't tie his shoes. An Idiot Savant can tell me Pi to a million places but he can't explain what Pi is. An Idiot Savant can hear Chopin once, and play the Chopin like Chopin, but he can't create like Chopin.  ChatGPT isn't going to replace people like you and Les any time soon. And that isn't my point, or even relevant IMHO.

For a person who's never programmed, creating a weather station to run, or a show with his Christmas lights might not seem so daunting with ChatGPT to help him. Millions of people have seized upon crappy code writing by jumping on the Arduino platform.  But people with the passion for coding learn how to make their code better.  Herman Melville started with a DICK AND JANE primer before he wrote MOBY DICK, same is true for all of us here.

ChatGPT will encourage people to buy Les's Compiler, because, if you don't know anything, you won't know the program doesn't work until you try it.  You can't try it unless you have a Positron(Proton) compiler.  And you won't try it if you think it will generate crap code.  Once this person finds out it doesn't work, he has to figure out WHY it doesn't work, and this is where the learning starts.  If the person doesn't have the patience to figure out how to fix the code, then he doesn't deserve to be able to create his OWN Weather Station or Christmas Light Show.  Any if code generation by ChatGPT teaches you anything, it teaches you proper formatting and commenting.

Approaching the idea that the method obtain any kind of "true" knowledge as "you walk the Trail of Tears to obtain it" is arrogant, and BS.  Its just as arrogant as a C programmer saying his code better than a Positron Basic Code.  That AI isn't perfect, AI can't be trusted to be right are valid (and obvious) points. But dismissing the potential of AI is foolhardy just because it can't, as of this writing, write proper ASM, or makes mistakes writing Basic. AI in all its forms, sad and dangerous as these may be, is here to stay.

Personally, I think we should encourage people to have AI help them write their BASIC programs because it will help Les sell compilers, which, in turn, will help Les continue to improve and expand Positron into 32b machines, like ARM.  This will help all of us make better devices.  And isn't that more important, especially for this forum? 

After all, have you considered the reason ChatGPT is better at writing Java and C++ code is because it has millions of examples to learn from?  I think its doing pretty damn well given the paucity of examples of "Proton Basic" it must have to base its "guesses" on.  It won't get better unless it has more examples of correct code to learn from and improve.  In this respect, it's no different than we are.

I think ChatGPT could help us create an open source code library as powerful as Arduino's and easier to learn and use.  This would be good for all of us, but especially for Les, without whom we wouldn't be here.
Never, never, never give up

Gary Scott

#12
Quote from: RGV250 on Feb 26, 2023, 09:11 AMThwere is another worry here, when everyone is too stupid to work things out for themselves there will not be anyone to tell it if it is wrong, when it does write software I hope it is not for aircraft and if so they tell us so I can stay in the airport bar so avoiding the subsequent crash.
Bob

 With that logic, should it also not apply to high level languages like Python, Basic etc etc? Do we need to write in assembler to be "smart"?
 I'm by no means saying AI is ready for prime time, but it WILL be the future. Period.
I'm shocked to say the least that so many tech minded folks are so closed minded about innovation and the future.
My health is way less than perfect, so to be very honest I'm jumping for joy  to see a hint of what the future holds for humans

RGV250

I object to the "intelligence", if this is the case then why do we not call calculators maths teachers. In my opinion it is nothing more than a glorified search engine.

QuoteAI in all its forms, sad and dangerous as these may be, is here to stay.
The reason it is here to stay is people are too lazy to think for themselves, look how kids are using it to do their schoolwork.

Bob

SeanG_65

Here's the REALLY scary / cool bit about ChatGPT, tell it to go and learn how to program in Positron 16, or ANY other computer language, then ask it to write the most efficient piece of code for you to do a particular task and......Off it goes and comes back with what you asked for!

I asked ChatGPT to write me a Goetzel Algorithm in Positron Basic and it DID!!

Write me a goetzel algorithm in Positron Basic

ChatGPT said:

Positron BASIC is primarily used for PIC microcontroller programming, and it doesn't natively support complex DSP operations like the Goertzel algorithm. However, you can implement the Goertzel algorithm manually using integer or fixed-point arithmetic.

The Goertzel algorithm is often used for detecting specific frequency components in a signal, such as DTMF tones. Here's an implementation in Positron BASIC:

Goertzel Algorithm in Positron BASIC
basic
Copy
Edit

' Goertzel Algorithm in Positron BASIC
' This example detects a specific frequency in a sampled signal.

Dim k As Float
Dim omega As Float
Dim coeff As Float
Dim q0 As Float
Dim q1 As Float
Dim q2 As Float
Dim power As Float
Dim N As Byte
Dim i As Byte
Dim freq As Float = 697.0 ' Example frequency to detect (Hz)
Dim samplingRate As Float = 8000.0 ' Sampling rate in Hz

' Precompute coefficient for the target frequency
N = 50 ' Number of samples
k = (N * freq) / samplingRate
omega = 2.0 * 3.141592 * k / N
coeff = 2.0 * Cos(omega)

' Reset Goertzel state variables
q1 = 0
q2 = 0

' Sample input and process with Goertzel algorithm
For i = 0 To N - 1
    Dim sample As Float
    sample = ADC_Read(0) ' Read signal from ADC channel 0
   
    ' Goertzel difference equation
    q0 = coeff * q1 - q2 + sample
    q2 = q1
    q1 = q0
Next

' Compute power at target frequency
power = q1^2 + q2^2 - coeff * q1 * q2

' Output result
If power > 1000 Then ' Threshold for detection
    Print "Frequency Detected!"
Else
    Print "No Frequency Detected"
End If
Explanation
The algorithm calculates a coefficient based on the target frequency.
It loops through N samples, applying the Goertzel recurrence formula.
Finally, it calculates the power of the frequency component and checks against a threshold.
Would you like any modifications, such as adapting it for a specific PIC model?

You said:
Adapt it for a PIC16F877A
ChatGPT said:

Here's the Goertzel algorithm adapted for the PIC16F877A using Positron BASIC. This version samples an analog signal from AN0 (RA0) and detects the presence of a specific frequency, such as a DTMF tone.

Goertzel Algorithm for PIC16F877A in Positron BASIC
basic
Copy
Edit

' Goertzel Algorithm for PIC16F877A in Positron BASIC
' Detects a specific frequency in an input signal using ADC

' PIC16F877A Configuration
Device = 16F877A
Declare XTAL = 8 ' 8 MHz Crystal
Declare Adc_Clock = 3
Declare Adc_SampleUs = 10
Declare Adc_Bits = 10
Declare Adc_Vref = Vdd

' Variables for Goertzel Algorithm
Dim k As Float
Dim omega As Float
Dim coeff As Float
Dim q0 As Float
Dim q1 As Float
Dim q2 As Float
Dim power As Float
Dim N As Byte
Dim i As Byte
Dim freq As Float = 697.0 ' Frequency to detect (Hz)
Dim samplingRate As Float = 8000.0 ' Sampling rate in Hz
Dim sample As Float

' LED Output Pin for Detection
Symbol Led = PORTB.0
TRISB = %00000000 ' Set PORTB as Output

' Initialize ADC
TRISA.0 = 1 ' Set RA0 as Input for ADC

' Precompute coefficient for the target frequency
N = 50 ' Number of samples
k = (N * freq) / samplingRate
omega = 2.0 * 3.141592 * k / N
coeff = 2.0 * Cos(omega)

' Main Program Loop
While 1
    ' Reset Goertzel state variables
    q1 = 0
    q2 = 0

    ' Sample input and process with Goertzel algorithm
    For i = 0 To N - 1
        sample = ADC_Read(0) ' Read signal from ADC channel 0

        ' Goertzel difference equation
        q0 = coeff * q1 - q2 + sample
        q2 = q1
        q1 = q0
    Next

    ' Compute power at target frequency
    power = q1^2 + q2^2 - coeff * q1 * q2

    ' Detect if frequency is present
    If power > 1000 Then ' Threshold for detection
        High Led  ' Turn on LED if frequency is detected
    Else
        Low Led   ' Turn off LED if not detected
    End If

    DelayMS 100 ' Small delay before next detection cycle
Wend
How It Works:
Configures PIC16F877A:
Uses an 8 MHz crystal.
Sets RA0 (AN0) as input for ADC.
Uses PORTB.0 as an output LED to indicate detection.
Samples the analog signal from AN0 using the ADC.
Applies the Goertzel algorithm to detect the 697 Hz frequency.
If the frequency is detected, the LED on PORTB.0 turns ON; otherwise, it remains OFF.
Repeats the detection loop continuously.

Hardware Connections:

Component           PIC16F877A Pin
Analog Input Signal   RA0 (AN0)
LED (Indicator)           RB0 (PORTB.0)
GND                   GND
VCC (5V)           VDD

Now tell me that isn't cooler than a dead penguin!

Even MORE radical, is if you give it a state machine diagram, it will code that up for you too.

Humans are obsolete, resistance is futile, you WILL be assimilated.  :-\