Announcement

Collapse
No announcement yet.

DSPIC30F4012 v230 Source Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • moodz
    replied
    Originally posted by 6666 View Post
    Hi moodz
    thanks for the extra info
    I see that part number is for the DSPIC30F4012-30I/SP

    i see that there is also a 30F4012-20I/SP

    would that work to ?

    With your push button ZERO feature, I am sure it has a use
    but would it be possible to remove it please
    as I can see the possibility of some confusion
    creeping in, it would be nice to have it power on and go.

    Thanks
    cheers
    6666
    The 201 chip is technically the slower chip ( 20 mips ) however I have heard it will run at the faster speed ( 30 mips ) ... I have not tested it though.

    I will knock out the push button startup feature very shortly.

    Regards,
    moodz.

    Leave a comment:


  • 6666
    replied
    Hi moodz
    thanks for the extra info
    I see that part number is for the DSPIC30F4012-30I/SP

    i see that there is also a 30F4012-20I/SP

    would that work to ?

    With your push button ZERO feature, I am sure it has a use
    but would it be possible to remove it please
    as I can see the possibility of some confusion
    creeping in, it would be nice to have it power on and go.

    Thanks
    cheers
    6666

    Leave a comment:


  • moodz
    replied
    ...parts I used.

    I got my bits from www.element14.com

    dpsic30F4012 part no : 1294856

    LCD display part no : 1671498

    Rotary Enc part no : 1653380

    ... NOTE .... If you have a PicKit2 / 3 programmer you dont need to wire up the rotary encoder or LCD .... the code will not break if you dont wire these in .... you can use the inbuilt serial comms in the PicKit to talk to the UNIPI code and program / save pulse timings to eeprom. Just use the UART selection under TOOLS tab in PicKit programmer with the programmer dongle connected to the ICSP port as per schematic. Once the settings have been made in the serial mode and saved to eeprom ... they will reload everytime the chip is reset / powered on ... you wont need the serial again ( unless you want to make changes )

    ALSO NOTE ... you must wire the ZERO button though .... the code expects you to press this once to commence operation after first power up .... if people dont like this I will remove this "feature"


    moodz.

    Leave a comment:


  • 6666
    replied
    Thank you Mr Moodz
    I would like to give this a try, been looking for the parts on the net
    and Jaycars.
    Plenty of 1602 backlight HD44780 lcd's on ebay

    Where are you sourceing your 30F4012 in Melbourne if not on ebay ?

    This seems to be your proto board, so vero board should be ok
    cheers
    6666


    Leave a comment:


  • moodz
    replied
    .......all you need then is the hex file

    Metal23.hex.zip


    ...ah the joy of hex.

    Leave a comment:


  • moodz
    replied
    dear friends ... I am happy to ship you a chip if you really cant get hold of one however I feel that if you invest in a pic programmer there will be more benefit as I am sure there will be many small code changes in the near future that will make shipping a new chip each time rather inconvenient if not costly as well. If you have a programmer all you need is the hex file.

    The UNIPI chip can be re-programmed even if soldered into a board via the ICSP interface on the schematic. ( see programmer in position below )

    I use the pickit2 programmer ( pickit3 is later release but would be OK also ). Of course there are other pic programmers available. The pickit2 is connects to your windows computer via USB and is very easy to use ... also powers your target board with 5 volts if required. The UNIPI chip uses the ICSP interface as a serial port and the pickit2 can be used as a serial port also .. so you can talk to the UNIPI chip using the pickit2.

    You should be able to get a genuine pickit2 for about $40 ... there are clones on ebay for less than $20

    The blank dspic30F4012 should be about $5 depending on suppliers.

    Some of the features I have coming up are better audio, active damping, descrimination ( maybe ) Multiple timings saved to eeprom for fast mode switching etc etc ...

    moodz.


    Click image for larger version

Name:	UNIPIv230_pickit.JPG
Views:	2
Size:	119.9 KB
ID:	329567

    Click image for larger version

Name:	pickit2_programmer.JPG
Views:	1
Size:	55.3 KB
ID:	329568

    Leave a comment:


  • moscadondres
    replied
    It's very interesting and i would like buy you one programmed chip,i can pay by paypal tell me your price for shipping to France,thank you.

    Leave a comment:


  • WM6
    replied
    Originally posted by moodz View Post


    [ATTACH]16622[/ATTACH]

    moodz
    A lot of reading inside, thank you very much.

    I need pre-programmed PIC.
    Can you sell me one with your intellectual property inside (PayPal as money transfer)?

    Leave a comment:


  • moodz
    replied
    Schematic is here ....

    A differential front-end PI design originated by Moodz and open for community development.

    Leave a comment:


  • moodz
    replied
    .... the complete MPLAB project files for v230 30F4012



    Metal23.zip

    moodz

    Leave a comment:


  • moodz
    replied
    system.h

    /*
    system.h - various things needed by all code blocks.
    Copyright (C) 2011 Paul Moody

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    #include <p30f4012.h>

    #define VERSION "MooDz UNIPI v230"

    #define FCY 29240000 // 29 MIPS ==> 7.3mhz rc osc * PLL16 /4

    // define some i/o bits for the various modules
    #define STATUS_LED _RB2

    #define SELECTBUTT _RC13
    #define ZEROBUTT _RC14
    #define SATLOCKBUTT _RC15

    #define AUDIO _RE8 //pin16

    #define TRUE (1)
    #define FALSE (0)

    // for some reason these are not defined in the UART.h of the C30 compiler
    // I am using, so I manually add them here if necessary
    #ifndef UART_ALTRX_ALTTX
    #define UART_ALTRX_ALTTX 0xFFE7 /*Communication through ALT pins*/
    #endif
    #ifndef UART_RX_TX
    #define UART_RX_TX 0xFBE7 /*Communication through the normal pins*/
    #endif

    #define DEBOUNCE (5) /* button debounce */

    //OptionState state values//
    #define OptNORM 0
    #define OptX1 1
    #define OptX10 10
    #define OptX100 100
    #define OptSAVE 4
    #define OptEXIT 5

    //MenuState state values//
    #define A 1
    #define B 2
    #define C 3
    #define D 4
    #define E 5
    #define F 6
    #define G 7
    #define H 8
    #define I 9
    #define J 10
    #define K 11
    #define L 12
    #define M 13
    #define N 14
    #define O 15
    #define P 16
    #define Q 17
    #define R 18
    #define S 19
    #define T 20
    #define U 21
    #define V 22
    #define W 23
    #define X 24
    #define Y 25
    #define Z 26

    //MenuItemState state values//
    #define RUN 0
    #define NORM 1
    #define EDIT 2
    #define SAVE 3
    #define OPT 4

    struct VALSTORE
    {
    double FCLOCK;
    unsigned int FREQ;
    unsigned int PWM1;
    unsigned int PWM2;
    unsigned int SP1ON;
    unsigned int SP1OFF;
    unsigned int SP2ON;
    unsigned int SP2OFF;
    unsigned int ADCscale;
    unsigned int SATscale;
    unsigned int AUDIOrate;
    struct
    {
    unsigned unused : 16;
    } bitfield16;
    int CHECKSUM;
    };

    Leave a comment:


  • moodz
    replied
    vars.c

    /*
    vars.c - save and read variables from eeprom.
    Copyright (C) 2011 Paul Moody

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    #include <stdio.h>
    #include "p30fxxxx.h"
    #include "system.h"

    extern unsigned int AUDIOrate;

    struct VALSTORE _EEDATA(32) eeblock; //EE size request must be power of 2
    volatile struct VALSTORE valblock;

    int calc_cksum(int, int *);
    extern int cksum_OK(int, int *);

    unsigned int PWMscale;

    extern int WriteWord(int *, int);
    extern int ReadWord(int *);

    void read_vars(void)
    {
    int i;
    int * source = (int *) &eeblock;
    int * dest = (int *) &valblock;

    for (i=0; i < sizeof(struct VALSTORE); i++)
    *(dest++) = ReadWord(source++);
    //make sure there is a valid TX PWM rate :-)
    if ((valblock.FREQ <= 7370) & (valblock.FREQ >= 737))
    PTPER = valblock.FREQ;
    else PTPER = 7370;
    PDC1 = valblock.PWM1;
    PDC2 = PTPER>>5;
    OC1R = valblock.SP1ON;
    OC1RS = valblock.SP1OFF;
    OC2R = valblock.SP2ON;
    OC2RS = valblock.SP2OFF;
    valblock.ADCscale = valblock.ADCscale & 0x000f;
    valblock.SATscale = valblock.SATscale & 0x000f;
    AUDIOrate = valblock.AUDIOrate;
    }



    void save_vars(void)
    {
    int i, sum;
    int * source = (int *) &valblock;
    int * dest = (int *) &eeblock;
    sum = calc_cksum(sizeof(struct VALSTORE), source); //calc checksum
    for (i=0; i < (sizeof(struct VALSTORE) - 1); i++)
    WriteWord(dest++, *(source++));
    WriteWord(dest, sum); // store the checksum
    }

    //================================================== ===========================
    // Routine to calculate a checksum on a section of memory
    // call with array size in 16 bit words and ptr to start.
    //================================================== ===========================
    int calc_cksum(int sizew, int *adr)
    {
    int i;
    int cksum = 0;
    for (i=0; i < (sizew - 1); i++) //-1 so dont include checksum itself
    cksum += *adr++;
    return cksum;
    }

    //================================================== ===========================
    // Routine to calculate a checksum on a section of EE memory
    // call with array size in 16 bit words and ptr to start.
    //================================================== ===========================
    int calc_EE_cksum(int sizew, int *adr)
    {
    int i;
    int cksum = 0;
    for (i=0; i < (sizew - 1); i++) //-1 so dont include checksum itself
    cksum += ReadWord(adr++);
    return cksum;
    }
    //================================================== ===========================
    // Routine to calculate a checksum on a section of memory
    // call with array size in 16 bit words and ptr to start.
    // checksum is at end of block and test if OK ... return 1 for OK
    //================================================== ===========================
    int cksum_OK(int sizew, int *adr)
    {
    int i;
    int cksum = 0;

    for (i=0; i < (sizew - 1); i++) //-1 so dont include checksum itself
    cksum += *adr++;
    if (cksum == *adr)
    return 1;
    else
    return 0;
    }

    //================================================== ===========================
    // Routine to calculate a checksum on a section of EE memory
    // call with array size in 16 bit words and ptr to start.
    // checksum is at end of block and test if OK ... return 1 for OK
    //================================================== ===========================
    int cksum_EE_OK(int sizew, int *adr)
    {
    int i;
    int cksum = 0;

    for (i=0; i < (sizew - 1); i++) //-1 so dont include checksum itself
    cksum += ReadWord(adr++);
    if (cksum == ReadWord(adr))
    return 1;
    else
    return 0;
    }

    Leave a comment:


  • moodz
    replied
    timers.c

    /*
    timers.c - hardware timer functions.
    Copyright (C) 2011 Paul Moody

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    #include "system.h"

    volatile unsigned int timer1_count;

    /************************************************** *******************
    Function: void __attribute__((__interrupt__)) _T1Interrupt (void)
    ************************************************** ******************/

    void __attribute__((__interrupt__ , auto_psv)) _T1Interrupt (void)
    {

    IFS0bits.T1IF = 0;

    if ( timer1_count == 0 )
    T1CONbits.TON = 0; //timer 1 off.
    else
    {
    TMR1 = 0;
    timer1_count--;
    }
    }

    /************************************************** *******************
    Function: void __attribute__((__interrupt__)) _T2Interrupt (void)
    ************************************************** ******************/

    void __attribute__((__interrupt__ , auto_psv)) _T2Interrupt (void)
    {
    IFS0bits.T2IF = 0;
    T2CONbits.TON = 0; //timer 2 off.
    }

    /************************************************** *******************
    Function: void __attribute__((__interrupt__)) _T3Interrupt (void)
    ************************************************** ******************/

    void __attribute__((__interrupt__ , auto_psv)) _T3Interrupt (void)
    {
    IFS0bits.T3IF = 0;
    T3CONbits.TON = 0; //timer 3 off.
    }


    /************************************************** *******************
    Function: void setupTMR1(void)
    ************************************************** ******************/

    void setup_TMR1(void)
    {
    IPC0bits.T1IP = 6; //lowest priority interrupt
    T1CONbits.TCKPS = 0; // timer 1 prescale = 1
    TMR1 = 0;
    PR1 = (737 * 4); //set timer preset
    //T1CON = 0x0000; //internal Tcy/1 clock
    IFS0bits.T1IF = 0; //interupt flag clear
    IEC0bits.T1IE = 1; //Enable Timer1 Interrupt Service Routine
    T1CONbits.TON = 1; //timer 1 on
    return;
    }


    /************************************************** *******************
    Function: void setupTMR2(void)
    ************************************************** ******************/

    void setup_TMR2(void)
    {
    IEC0bits.T2IE = 0; // Disable Timer2 Interrupt Service Routine
    T2CONbits.TCKPS = 1; // timer 2 prescale = 8
    TMR2 = 0;
    PR2 = 2000;
    T2CONbits.TON = 1; //timer 2 on
    return;
    }
    /************************************************** *******************
    Function: void setupTMR3(void)
    ************************************************** ******************/

    void setup_TMR3(void)
    {
    IEC0bits.T3IE = 0; // Disable Timer3 Interrupt Service Routine
    T3CON = 0x0000; // internal Tcy/1 clock
    TMR3 = 0;
    PR3 = 2500;
    T3CONbits.TON = 0; // timer 3 off
    return;
    }

    /************************************************** *******************
    Function: void delay_tmr1(unsigned int)
    ************************************************** ******************/

    /* delay routine */
    void delay_tmr1(unsigned int delay)
    {
    timer1_count = delay;
    setup_TMR1();
    while(timer1_count);
    }

    Leave a comment:


  • moodz
    replied
    serial.c

    /*
    serial.c - rs232 comms functions :-).
    Copyright (C) 2011 Paul Moody

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    */
    #include "system.h"
    #include <uart.h>
    #include <libpic30.h>

    #define BAUDRATE 9600 //Desired Baud Rate
    //#define BAUDRATE 38400 //Desired Baud Rate
    #define BRGVAL ((FCY/BAUDRATE)/16)-1 //Formula for U1BRG register
    //from dsPIC30F Family
    //Reference Manual

    //Functions and Variables with Global Scope:
    char *UARTCharPtr;

    char rxbuff[30]; // global rx buffer for serial data
    char txbuff[30] = "\r\n UNIPI \r\n\0"; // global tx buffer for serial data
    char *rxbuffptr; // local input ptr for storing data
    short int rxrdy; // flag to indicate a line of data is available in buffer

    void setup_uart(void);
    void WriteUART_to_RS232(void);
    void buff2uart(char *);

    void UART_FlushRX(void);
    char UART_GetChar(void);

    void UART_PutChar(char);
    int write(int, void *, unsigned int);
    int __C30_UART = 2;

    void __attribute__((__interrupt__, auto_psv)) _U1TXInterrupt(void);
    void __attribute__((__interrupt__,auto_psv)) _U1RXInterrupt (void);

    volatile unsigned int rs232busyflag; //flags that the tx buffer not empty yet

    //Functions
    //************************************************** ************************
    //* Configure the USART
    // the default stdin,stdout are directed to serial port 1
    //************************************************** ************************

    //UART_Init() sets up the UART for a 8-bit data, No Parity, 1 Stop bit
    //at 9600 baud with transmitter interrupts enabled
    void setup_uart(void)
    {
    U1MODE = 0x0000; //Clear UART1 registers
    U1STA = 0x0000;

    //U1MODEbits.ALTIO = 1; //use U1ATX and U1ARX instead of
    //U1TX and U1RX pins
    U1MODEbits.ALTIO = 0; //use U1TX and U1RX pins

    U1MODEbits.UARTEN = 1; //Enable UART1 module
    U1BRG = BRGVAL; //Load UART1 Baud Rate Generator

    IFS0bits.U1RXIF = 0; //Clear UART1 Receiver Interrupt Flag
    IFS0bits.U1TXIF = 0; //Clear UART1 Transmitter Interrupt Flag
    IEC0bits.U1RXIE = 0; //Disable UART1 Receiver ISR
    IEC0bits.U1TXIE = 1; //Enable UART1 Transmitter ISR
    U1STAbits.UTXISEL = 1; //Setup UART1 transmitter to interrupt
    //when a character is transferred to the
    //Transmit Shift register and as result,
    //the transmit buffer becomes empty.

    U1STAbits.UTXEN = 1; //Enable UART1 transmitter
    UARTCharPtr = &txbuff[0]; //Initialize UARTCharPtr to point
    //to the first character in the Display buffer

    U1STA = UART_TX_ENABLE & UART_TX_PIN_NORMAL; // TX & RX interrupt modes
    U1STAbits.URXISEL = 0; // rx intr every ch

    rxbuffptr = &rxbuff[0];
    rxbuff[0] = 0;
    rxrdy = 0;

    IFS0bits.U1RXIF = 0;
    IEC0bits.U1RXIE = 1; // go live with serial rx intr
    }


    //WriteUART_to_RS232() triggers interrupt-driven UART communication by writing
    //the first character in the Display buffer to the UART Transmit register
    void buff2uart(char * ptr)
    {
    rs232busyflag = 1;
    UARTCharPtr = ptr; //Re-Initialize UART display
    U1TXREG = *UARTCharPtr++; //Load the UART transmit register with first character
    IFS0bits.U1TXIF = 0; //Clear the UART1 transmitter interrupt flag
    while (rs232busyflag); //flags that the tx buffer not empty yet
    }

    //_U1TXInterrupt() is the UART1 Interrupt Service Routine.
    //The routine must have global scope in order to be an ISR.
    //The ISR name is the same name provided for the module in the device linker
    //script.
    //The UART1 ISR loads the UART1 4-deep FIFO buffers with the next
    //4 characters in the Display buffer unless it encounters a null character.
    void __attribute__((__interrupt__, auto_psv)) _U1TXInterrupt(void)
    {
    int i = 0;
    while (i < 4)
    {
    if (*UARTCharPtr == '\0')
    {
    rs232busyflag--;
    break;
    }
    else
    {
    U1TXREG = *UARTCharPtr++;
    i++;
    }
    }
    IFS0bits.U1TXIF = 0; //Clear the UART1 transmitter interrupt flag
    }

    int write(int handle, void *buffer, unsigned int len)
    {
    int i;
    switch (handle)
    {
    case 0: // handle 0 corresponds to stdout
    case 1: // handle 1 corresponds to stdin
    case 2: // handle 2 corresponds to stderr
    default:
    for (i=0; i<len; i++)
    UART_PutChar(*(char*)buffer++);
    }
    return(len);
    }


    void UART_PutChar(char c)
    {
    while (U1STAbits.UTXBF); // Wait for space in UART2 Tx buffer
    U1TXREG = c; // Write character to UART2
    }

    char UART_GetChar()
    {
    while (!U1STAbits.URXDA);
    return U1RXREG;
    }

    void UART_FlushRX()
    {
    unsigned char c;
    while (!U1STAbits.URXDA)
    c = U1RXREG;
    }

    /************************************************** *******************
    Function: void __attribute__((__interrupt__)) _U1RXInterrupt (void)
    Summary: Handles uart rx interrupt
    ************************************************** ******************/

    void __attribute__((__interrupt__,auto_psv)) _U1RXInterrupt (void)
    {
    char ch;

    IFS0bits.U1RXIF = 0;

    while (U1STAbits.URXDA)
    {
    ch = U1RXREG & 0xFF;
    // save the character if there is room in the input buffer
    if ( ch == 0x0a )
    continue; // strip LF

    if ( ch == 0x0d )
    {
    // end of input stream..
    // flag we have something to process
    *rxbuffptr = 0; // null terminate buffer
    rxrdy = 1;
    break;
    }

    // if we have room in the buffer, store the ch for later processing
    if (rxbuffptr < (&rxbuff[0] + sizeof(rxbuff) - 2 ))
    {
    // still working on filling buffer
    *rxbuffptr++ = ch;
    UART_PutChar(ch);
    }
    }
    }

    Leave a comment:


  • moodz
    replied
    RS232menu.c

    /*
    RS232menu.c - serial comms and terminal menu.
    Copyright (C) 2011 Paul Moody

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    */

    #include "system.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>


    extern char rxbuff[]; // global rx buffer for serial data
    extern char *rxbuffptr; // local input ptr for storing data
    extern short int rxrdy; // flag to indicate a line of data is available in buffer

    extern double Fclock; //input clock frequency in KHz

    extern struct VALSTORE valblock;
    extern struct VALSTORE _EEDATA(32) eeblock;

    extern long ADCval;
    extern long ADCvalSamp;
    extern unsigned int ADCvalCount;
    extern unsigned int ADCvalCountMax;

    extern long ADCvalSATsamp;
    extern int SATdiff;
    extern unsigned int ADCvalSATcountMax;
    extern volatile unsigned int AUDIOrate; //dds accumulator threshold sum for audio events.


    extern void save_vars(void);
    extern void read_vars(void);
    extern int calc_cksum(int, int *);
    extern int calc_EE_cksum(int, int *);
    extern int cksum_OK(int, int *);

    extern unsigned int PWMscale; //scale value for PWM modulation val/scale

    void process_serial_buffer()
    {
    switch( rxbuff[0] )
    {
    case 'A':
    sscanf(&rxbuff[1],"%u",&valblock.FREQ);
    if (valblock.FREQ < 737) valblock.FREQ = 737; //need this limit or would have non stop PWM interrupts
    if (valblock.FREQ > 32767) valblock.FREQ = 32767; //max 15 bits
    PTPER = valblock.FREQ;
    PDC2 = PTPER>>5;
    break;
    case 'B':
    sscanf(&rxbuff[1],"%d",&valblock.PWM1);
    PDC1 = valblock.PWM1;
    break;
    case 'C':
    sscanf(&rxbuff[1],"%d",&valblock.PWM2);
    //PDC2 = valblock.PWM2;
    break;
    case 'E':
    sscanf(&rxbuff[1],"%d",&valblock.SP1ON);
    OC1R = valblock.SP1ON;
    break;
    case 'F':
    sscanf(&rxbuff[1],"%d",&valblock.SP1OFF);
    OC1RS = valblock.SP1OFF;
    break;
    case 'G':
    sscanf(&rxbuff[1],"%d",&valblock.SP2ON);
    OC2R = valblock.SP2ON;
    break;
    case 'H':
    sscanf(&rxbuff[1],"%d",&valblock.SP2OFF);
    OC2RS = valblock.SP2OFF;
    break;
    case 'K':
    sscanf(&rxbuff[1],"%d",&valblock.ADCscale);
    valblock.ADCscale = valblock.ADCscale & 0x000f;
    break;
    case 'M':
    sscanf(&rxbuff[1],"%u",&valblock.AUDIOrate);
    AUDIOrate = valblock.AUDIOrate;
    break;
    case 'X':
    sscanf(&rxbuff[1],"%lf",&Fclock);
    break;
    case 'S':
    save_vars();
    if((calc_cksum(sizeof(struct VALSTORE), (int *) &valblock)) == (calc_EE_cksum(sizeof(struct VALSTORE), (int *) &eeblock)))
    printf("\r\nEEPROM save OK : CHECKSUM OK\r\n");
    else
    printf("\r\n!!!!EEPROM save FAILED : CHECKSUM ERROR!!!!\r\n");
    break;
    case 'R':
    read_vars();
    break;

    default:
    printf("\r\nEnter a command : eg A1234 sets Tx freq count to 1234\r\n");
    }
    printf("\r\n");
    printf(VERSION);
    printf("\r\n");
    printf("S: Save all vars to EEPROM\r\n");
    printf("R: Read all vars from EEPROM\r\n");
    printf(" CHECKSUM: RAM = %i EEPROM = %i\r\n",(calc_cksum((sizeof(struct VALSTORE)), (int *)&valblock)),(calc_EE_cksum((sizeof(struct VALSTORE)), (int *)&eeblock)));
    printf(" STATUS:\r\n");
    printf("X: CPU Ref Clock : 4 X %.3lf Khz = %.3lf Mhz\r\n",Fclock, 4*Fclock/1000);
    printf(" PWM Step is %.3lf Nanosecond\r\n",1000000/(Fclock * 4));
    printf("A: TX FREQUENCY : Count = %u Freq = %.3lf Khz Period = %.3lf usec\r\n",PTPER, (Fclock * 4)/PTPER, (PTPER/(Fclock * 4))*1000);
    printf("B: TX PRIMARY PULSE : Count = %u Duty = %.3lf usec\r\n",PDC1, (PDC1/(Fclock * )*1000);
    printf("C: TX DESCRIM PULSE : Count = %u Duty = %.3lf usec\r\n",PDC2, (PDC2/(Fclock * )*1000);
    printf(" PWM3 TARGET level : Count = %u Duty = %.3lf usec\r\n",PDC3, (PDC3/(Fclock * )*1000);
    printf("E: SAMPLE PULSE 1 ON : Count = %u ON = %.3lf usec\r\n", OC1R, (OC1R/Fclock)*2000);
    printf("F: SAMPLE PULSE 1 OFF : Count = %u OFF = %.3lf usec width = %.3lf usec\r\n", OC1RS, (OC1RS/Fclock)*2000, ((OC1RS - OC1R)/Fclock)*2000);
    printf("G: SAMPLE PULSE 2 ON : Count = %u ON = %.3lf usec\r\n", OC2R, (OC2R/Fclock)*2000);
    printf("H: SAMPLE PULSE 2 OFF : Count = %u OFF = %.3lf usec width = %.3lf usec\r\n", OC2RS, (OC2RS/Fclock)*2000, ((OC2RS - OC2R)/Fclock)*2000);
    printf("K: TARGET PWM scale : %u\r\n", valblock.ADCscale);
    printf(" ADC sample = %lu [%.6lf Volts]\r\n", ADCvalSamp, ADCvalSamp*(5.0/0x1ffff));
    printf(" ADC SAT sample = %lu [%.6lf Volts] DIFF = %d [%.6lf Volts]\r\n", ADCvalSATsamp, ADCvalSATsamp*(5.0/0x1ffff), SATdiff, SATdiff*(5.0/0x1ffff));
    printf("M: AUDIO freq range count = %u\r\n", valblock.AUDIOrate);
    printf("SELECT Button: %u ZERO Button: %u SAT LOCK Button: %u\r\n", SELECTBUTT, ZEROBUTT, SATLOCKBUTT);
    // reset input buffer state
    rxrdy = 0;
    rxbuff[0] = 0;
    rxbuffptr = &rxbuff[0];
    putchar('>');
    }

    Leave a comment:

Working...
X