Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Chat GPT

Status
Not open for further replies.

danadakk

Advanced Member level 6
Joined
Mar 26, 2018
Messages
3,090
Helped
413
Reputation
846
Reaction score
721
Trophy points
113
Activity points
13,413
Some interesting AI code generation, and other AI examples, beginnings here :


I asked it this

Code for PSOC DDS waveform generator, and it gave me

Code:
#include <project.h>

// Waveform settings
#define SAMPLING_RATE 48000 // Hz
#define FREQUENCY 1000 // Hz
#define AMPLITUDE 1.0 // 0.0 to 1.0
#define WAVEFORM_LENGTH 256 // Samples

// DDS settings
#define DDS_CLOCK_FREQ 100000000 // Hz
#define DDS_PHASE_ACC_WIDTH 32
#define DDS_PHASE_ACC_SCALE 4294967296.0 // 2^DDS_PHASE_ACC_WIDTH
#define DDS_PHASE_INCREMENT ((FREQUENCY * DDS_PHASE_ACC_SCALE) / DDS_CLOCK_FREQ)

// Lookup table for waveform samples
uint8 waveform[WAVEFORM_LENGTH] = {
    0, 24, 49, 73, 97, 120, 142, 164, 184, 203, 220, 235, 247, 255, 260, 260,
    255, 247, 235, 220, 203, 184, 164, 142, 120, 97, 73, 49, 24, 0, 0, 0, 0,
    // ... (omitted for brevity)
    0
};

// Variables for tracking DDS phase and output sample
uint32 dds_phase_acc = 0;
uint8 output_sample = 0;

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    // Set up the output pin
    Waveform_Output_Enable_Write(1); // Enable output
    Waveform_Output_Start(); // Start output
    Waveform_Output_SetDriveMode(Waveform_Output_DM_STRONG);

    // Set up the timer interrupt for sampling the waveform
    uint32_t interrupt_period = DDS_CLOCK_FREQ / SAMPLING_RATE;
    Waveform_Timer_Start();
    Waveform_Timer_WritePeriod(interrupt_period - 1);
    Waveform_Timer_EnableInt();

    for(;;)
    {
        // Do nothing, DDS output is generated in the interrupt handler
    }
}

CY_ISR(Waveform_Timer_ISR)
{
    // Increment DDS phase accumulator
    dds_phase_acc += DDS_PHASE_INCREMENT;

    // Compute waveform sample from DDS phase accumulator
    uint8_t waveform_index = (dds_phase_acc >> (DDS_PHASE_ACC_WIDTH - 8)) % WAVEFORM_LENGTH;
    output_sample = (uint8_t)(waveform[waveform_index] * AMPLITUDE);

    // Write output sample to output pin
    Waveform_Output_Write(output_sample);
}

and this

Here's an example code for a PSOC DDS (Direct Digital Synthesis) waveform generator:

CCopy code
#include <project.h>

// Waveform settings
#define SAMPLING_RATE 48000 // Hz
#define FREQUENCY 1000 // Hz
#define AMPLITUDE 1.0 // 0.0 to 1.0
#define WAVEFORM_LENGTH 256 // Samples

// DDS settings
#define DDS_CLOCK_FREQ 100000000 // Hz
#define DDS_PHASE_ACC_WIDTH 32
#define DDS_PHASE_ACC_SCALE 4294967296.0 // 2^DDS_PHASE_ACC_WIDTH
#define DDS_PHASE_INCREMENT ((FREQUENCY * DDS_PHASE_ACC_SCALE) / DDS_CLOCK_FREQ)

// Lookup table for waveform samples
uint8 waveform[WAVEFORM_LENGTH] = {
0, 24, 49, 73, 97, 120, 142, 164, 184, 203, 220, 235, 247, 255, 260, 260,
255, 247, 235, 220, 203, 184, 164, 142, 120, 97, 73, 49, 24, 0, 0, 0, 0,
// ... (omitted for brevity)
0
};

// Variables for tracking DDS phase and output sample
uint32 dds_phase_acc = 0;
uint8 output_sample = 0;

int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */

// Set up the output pin
Waveform_Output_Enable_Write(1); // Enable output
Waveform_Output_Start(); // Start output
Waveform_Output_SetDriveMode(Waveform_Output_DM_STRONG);

// Set up the timer interrupt for sampling the waveform
uint32_t interrupt_period = DDS_CLOCK_FREQ / SAMPLING_RATE;
Waveform_Timer_Start();
Waveform_Timer_WritePeriod(interrupt_period - 1);
Waveform_Timer_EnableInt();

for(;;)
{
// Do nothing, DDS output is generated in the interrupt handler
}
}

CY_ISR(Waveform_Timer_ISR)
{
// Increment DDS phase accumulator
dds_phase_acc += DDS_PHASE_INCREMENT;

// Compute waveform sample from DDS phase accumulator
uint8_t waveform_index = (dds_phase_acc >> (DDS_PHASE_ACC_WIDTH - 8)) % WAVEFORM_LENGTH;
output_sample = (uint8_t)(waveform[waveform_index] * AMPLITUDE);

// Write output sample to output pin
Waveform_Output_Write(output_sample);
}


Here's how the code works:

  1. First, we define some constants for the waveform settings, such as the sampling rate, frequency, amplitude, and waveform length.
  2. We also define constants for the DDS settings, such as the clock frequency, phase accumulator width, phase accumulator scaling factor, and phase increment.
  3. We create a lookup table for the waveform samples. This example code uses a 256-sample lookup table for a sine wave, but other waveforms could be used as well.
  4. We define variables for tracking the DDS phase accumulator and the output sample.
  5. In the main() function, we enable global interrupts and set up the output pin for the waveform generator.
  6. We set up a timer interrupt to sample the waveform at the desired sampling rate. The interrupt period is calculated based on the DDS clock frequency and the desired sampling rate.
  7. In the interrupt handler, we increment the DDS phase accumulator by the phase increment value. We then compute the index into the waveform lookup table based on the phase accumulator value and scale the sample by the

It did not give me the schematic of interconnect, but its an interesting start....


Regards, Dana.
 
Last edited:

... while I am searching first what the acronym PSOC could mean :D
Whereas search engines are not fully utilizing ChatGPT from OpenAI, MS has funded over $100m to OpenAI for the servers needed and people to develop. OpenAI is private and the chief architect came from Google who are doing their own AI thing (for profit).

So using search engines you have to read a few examples, but using https://chat.openAI.com/chat it can give a computed result

A PSOC (Programmable System on Chip) DDS (Direct Digital Synthesis) waveform generator is a device that can generate various types of waveforms, such as sine, square, triangle, and sawtooth, using digital signal processing techniques. It utilizes a PSOC microcontroller, which is a type of integrated circuit that combines digital logic circuits, analog circuits, and programmable memory on a single chip.


The results can be impressive but also the failures can be impressive too, so a few more revisions are needed in some areas to improve reliability and do no harm with continuous human feedback.
--- Updated ---

psychologist dr jordan peterson, famously asked chatGPT a difficult question because it cannot compute beyond the next word.
So he asked for two definitions each in 25 words. One passed , the other failed. But if you say stop after 24 words that works pretty well.


compute a quadrature decoder using python




A quadrature decoder is a device or software that can convert the two-phase quadrature signals from an incremental encoder into a count of the position or motion of the encoder. Here's an example of how to compute a quadrature decoder using Python:

python

# Quadrature decoder example using Python

# Define the quadrature signals as inputs (in this example, using GPIO pins)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
A_PIN = 23
B_PIN = 24
GPIO.setup(A_PIN, GPIO.IN)
GPIO.setup(B_PIN, GPIO.IN)

# Initialize the count and state variables
count = 0
state = 0

# Define the interrupt callback function to update the count based on the quadrature signals
def callback(channel):
global count, state
A = GPIO.input(A_PIN)
B = GPIO.input(B_PIN)
if A == 1 and B == 0 and state == 0:
count += 1
state = 1
elif A == 1 and B == 1 and state == 1:
count += 1
state = 2
elif A == 0 and B == 1 and state == 2:
count += 1
state = 3
elif A == 0 and B == 0 and state == 3:
count += 1
state = 0
elif A == 0 and B == 1 and state == 0:
count -= 1
state = 3
elif A == 1 and B == 1 and state == 3:
count -= 1
state = 2
elif A == 1 and B == 0 and state == 2:
count -= 1
state = 1
elif A == 0 and B == 0 and state == 1:
count -= 1
state = 0

# Add the interrupt event detection for both signals
GPIO.add_event_detect(A_PIN, GPIO.BOTH, callback=callback)
GPIO.add_event_detect(B_PIN, GPIO.BOTH, callback=callback)

# Wait for user input to exit
input("Press Enter to exit\n")

# Clean up the GPIO pins
GPIO.cleanup()


In this example, we first define the two-phase quadrature signals as inputs using the Raspberry Pi GPIO library. We then initialize the count and state variables to 0. The interrupt callback function callback() is defined to update the count variable based on the state transitions of the quadrature signals.

The GPIO.add_event_detect() function is used to detect any changes in the quadrature signals and trigger the interrupt callback function. Finally, we wait for user input to exit the program and clean up the GPIO pins


this took about the same time to answer as me typing this question
next...

define CMRR for an INA in 40 words or less in french





Le CMRR (Common Mode Rejection Ratio) est la mesure de la capacité d'un amplificateur d'instrumentation à rejeter les signaux communs indésirables présents sur les deux entrées, et de ne fournir qu'une amplification du signal différentiel utile.
--- Updated ---

regenerated

Define CMRR for an INA in 40 words or less in french


2 / 2
Le CMRR (Common Mode Rejection Ratio) d'un INA (amplificateur d'instrumentation) mesure sa capacité à rejeter les signaux de mode commun indésirables, tels que les interférences électromagnétiques, et à amplifier les signaux différentiels utiles. C'est le rapport entre l'amplitude de signal différentiel amplifié et celle du signal de mode commun rejeté.

Was this response better or worse?
--- Updated ---

define AM dsb-sc in syrian




تشكل الـ DSB-SC (Double Sideband Suppressed Carrier) بتعديل مرحلة موجتين ذات تردد متساوٍ و متعامدتين في مخطط الطيف. يتم حذف حامل التردد و توفير استخدام النطاق بكفاءة مضاعفة على حساب النطاق الترددي والاستهلاك للطاقة.
--- Updated ---

Here is a more efficient implementation of a quadrature decoder using Python that utilizes bitwise operations to reduce the amount of code needed:

python

import RPi.GPIO as GPIO

# Set the GPIO mode and pins for the A and B channels
GPIO.setmode(GPIO.BCM)
A_PIN = 17
B_PIN = 18

# Set up the GPIO pins as inputs with pull-up resistors
GPIO.setup(A_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(B_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Initialize the state of the decoder
state = 0

# Define a function to handle the quadrature decoder interrupts
def quadrature_decoder(channel):
global state
a_state = GPIO.input(A_PIN)
b_state = GPIO.input(B_PIN)
state = (state << 2 | (a_state << 1) | b_state) & 0b1111

# Set up the interrupt handlers for both channels
GPIO.add_event_detect(A_PIN, GPIO.BOTH, callback=quadrature_decoder)
GPIO.add_event_detect(B_PIN, GPIO.BOTH, callback=quadrature_decoder)

# Start an infinite loop to monitor the state of the decoder
while True:
# Compute the current position of the encoder based on the state of the channels
if state == 0b0001 or state == 0b1110:
position += 1
elif state == 0b0010 or state == 0b1101:
position -= 1
elif state == 0b0111 or state == 0b1000:
position += 2
elif state == 0b0100 or state == 0b1011:
position -= 2

# Print the current position of the encoder
print(position)


In this implementation, we use bitwise operations to combine the state of both channels into a single 4-bit value, which allows us to more easily determine the current position of the encoder. We also use the & operator to ensure that the state value is always within the range of 0 to 15, which prevents errors from occurring when the encoder is rotated rapidly.

This implementation is more efficient than the previous example because it uses fewer conditional statements and computations, and it utilizes bitwise operations to reduce the amount of code needed.
 
Last edited:
  • Like
Reactions: KerimF

    KerimF

    Points: 2
    Helpful Answer Positive Rating
... while I am searching first what the acronym PSOC could mean :D

PSOC is a SOC (System on Chip), Cypress/Infineon processor with significant
analog and routable capability. Several families PSOC 4, 5LP, 6 (dual core).

Whats onchip (multiple copies in many instances) :

1681143838541.png



Regards, Dana.
 
  • Like
Reactions: KerimF

    KerimF

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top