News:

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

Main Menu

Need a recommendation on a pic24 or DSPIC

Started by TimB, Nov 02, 2025, 09:57 AM

Previous topic - Next topic

TimB


I decided I need to move up to a faster pic.

I need to sample 3 voltage signals at around 10k sps each although in reality I could be much slower.

I also need 3 PWMS. They do not need to be high resolution I'm currently using a 5 bit DAC and that does the job.

3 pins as signal outputs and another for say an RS232 and pins for 3 leds

Any recommendations?

Thanks
Tim

TimB


I think I can get the sample rates with a Pic18 Q10 series. If I run it at 64mhz I can get the calcs done in between samples


charliecoutas

I used one of these Tim: 33CK256MP505. I needed speed and fast ADC conversion. This little bugger runs at 200MHZ and it did the job nicely. I have some code which might help in case of difficulties (I had trouble getting 200Mhz but sorted it.)

Charlie

TimB


As is typical I re-evaluated my requirements

I used to need fast sampling but realised that what I needed that for has been dropped

Just for giggles my new requirement is

Sample 3 Opto sensors and make decisions on levels at >100hz   
Control a stepper motor with pulses every 100hz based on one of the optos
Act as an i2c slave to main cpu can request sensor and count status every 100hz

Also perform simple display and input tasks eg some led's

Tim

top204

#4
The new PIC18FxxQ devices are great, but as Charlie stated, the new dsPIC33xxCK devices are excellent, and very easy to use.

They also fit onto John's Amicus16B board using the excellent SMD header board he designed. So it just plugs into the DIL socket on it.

Below is a tested code listing template for a dsPIC33CK64MP102 device, operating at 200MHz.

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Code Listing template for a dsPIC33CK64MP102 device, running on an 'Easy Driver' Amicus16B development board.
' The device is setup to run at 200 MHz using its internal oscillator.
'
' Written by Les Johnson for the Positron16 BASIC Compiler
'
    Device = 33CK64MP102                                                        ' Tell the compiler what device to compile for
    Declare Xtal = 200                                                          ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Set the USART1 pins for an Amicus16B board
'
    Declare Hserial1_Baud = 115200                                              ' Set the Baud rate of USART1 to 115200
    Declare HRSOut1_Pin   = PORTB.0                                             ' Set pin PORTB.0 for TX (PPS pin RP32)
    Declare HRSIn1_Pin    = PORTB.1                                             ' Set pin PORTB.1 for RX (PPS Pin RP33)

$define LED_OnBoard PORTB.15                                                    ' The pin where the on-board LED is connected (if enabled with jumper LK3)
'
' Create any global variables here
'

'----------------------------------------------------------------------------------
' The main program loop starts here
' Setup the device to operate at 200 MHz, and transmit text to a serial terminal at 115200 Baud.
' Also toggle the on-board LED to make sure things are operating as they should (bring the LED into circuit with board jumper LK3)
'
Main:
    Setup()                                                                     ' Setup the program and any peripherals
    Do                                                                          ' Create a loop
        HRSOut1Ln "Hello World"                                                 ' Transmit text, to make sure the device is operating at the correct speed
        Toggle LED_OnBoard                                                      ' \ Toggle the on-board LED at twice a second
        DelayMS 500                                                             ' /
    Loop                                                                        ' Do it forever

'-----------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_200MHz()                                                                ' Initialise the internal oscillator to run the device at 200 MHz
    PPS_Unlock()                                                                ' Unlock the PPS
    PPS_Output(cOut_Pin_RP32, cOut_Fn_U1TX)                                     ' Make pin RB0 USART1 TX for an Amicus16B
    PPS_Input(cIn_Pin_RP33, cIn_Fn_U1RX)                                        ' Make pin RB1 USART1 RX for an Amicus16B
EndProc

'-----------------------------------------------------------------------------------------
' Initialise the internal oscillator to run the device at 200 MHz
' Input     : None
' Output    : None
' Notes     : For a dsPIC33CK64MP102 device
'
Proc Osc_200MHz()
    CLKDIV    = %0011000000000001                                               ' RCDIV is FRC/1. PREPLL is 1:1
    PLLFBD    = %0000000000110010
    OSCTUN    = %0000000000000000
    PLLDIV    = %0000000000010001                                               ' POSTPLL is 1:1. FVCO/4. POST2DIV is 1:1
    ACLKCON1  = %0000000100000001                                               ' PLL disabled. FRC Oscillator. PREPLL is 1:1
    APLLFBD1  = %0000000010010110
    APLLDIV1  = %0000000001000001                                               ' APSTSCLR is 1:4. APOST2DIV is 1:1. AVCODIV is FVCO/4
    REFOCONL  = %0000000000000000
    REFOCONH  = %0000000000000000
    REFOTRIMH = %0000000000000000
    RPCON     = %0000000000000000
    Write_OSCCON(%0000000100000001)                                             ' Enable PLL
    Repeat: Until OSCCONbits_OSWEN = 1                                          ' \ Wait for clock switching to stabilise
    Repeat: Until OSCCONbits_LOCK = 0                                           ' /
EndProc

'-----------------------------------------------------------------------------------------
' Setup the config fuses for an internal oscillator on a dsPIC33CK64MP102 device.
' The OSC pins are general purpose I/O.
'
    Config FSEC = BWRP_OFF,_                                                    ' Boot Segment may be written
                  BSS_DISABLED,_                                                ' Boot Segment No Protection (other than BWRP)
                  BSEN_OFF,_                                                    ' No Boot Segment
                  GWRP_OFF,_                                                    ' General Segment may be written
                  GSS_DISABLED,_                                                ' General Segment No Protection (other than GWRP)
                  CWRP_OFF,_                                                    ' Configuration Segment may be written
                  CSS_DISABLED,_                                                ' Configuration Segment No Protection (other than CWRP)
                  AIVTDIS_OFF                                                   ' Alternate Interrupt Vector Table Disabled

    Config FOSCSEL = FNOSC_FRC,_                                                ' Oscillator Source is Internal Fast RC (FRC)
                     IESO_OFF                                                   ' Start up with user-selected oscillator source

    Config FOSC = POSCMD_NONE,_                                                 ' Primary Oscillator disabled
                  OSCIOFNC_ON,_                                                 ' OSC2 is general purpose digital I/O pin
                  FCKSM_CSECMD,_                                                ' Clock switching is enabled. Fail-safe Clock Monitor is disabled
                  PLLKEN_ON,_                                                   ' PLL clock output will be disabled if Lock is lost
                  XTCFG_G3,_                                                    ' XT Config is 24 to 32 MHz crystals
                  XTBST_ENABLE                                                  ' XT Boost the kick-start


    Config FWDT = RWDTPS_PS2147483648,_                                         ' Run Mode Watchdog Timer Post Scaler is 1:2147483648
                  RCLKSEL_LPRC,_                                                ' Watchdog Timer Clock is use LPRC
                  WINDIS_ON,_                                                   ' Watchdog Timer in Non-Window mode
                  WDTWIN_WIN25,_                                                ' Watchdog Timer Window is 25% of WDT period
                  SWDTPS_PS2147483648,_                                         ' Sleep Mode Watchdog Timer Post Scaler is 1:S2147483648
                  FWDTEN_ON_SW                                                  ' Watchdog Timer controlled via software. Use WDTCON.ON bit

    Config FPOR = BISTDIS_DISABLED                                              ' Memory BIST on reset disabled

    Config FICD = ICS_PGD1,_                                                    ' ICD Communicate on PGC1 and PGD1
                  JTAGEN_OFF                                                    ' JTAG is disabled

    Config FDMT = DMTDIS_OFF                                                    ' Dead Man Timer is Disabled and can be enabled by software

    Config FDEVOPT = ALTI2C1_OFF,_                                              ' I2C1 mapped to SDA1/SCL1 pins
                     ALTI2C2_OFF,_                                              ' I2C2 mapped to SDA2/SCL2 pins
                     SMBEN3_SMBUS3,_                                            ' SMBus 3.0 input levels
                     SPI2PIN_PPS                                                ' SPI2 uses I/O remap (PPS) pins

    Config FALTREG = CTXT1_OFF,_                                                ' (IPL) Associated to Alternate Working Register Not Assigned
                     CTXT2_OFF,_                                                ' (IPL) Associated to Alternate Working Register Not Assigned
                     CTXT3_OFF,_                                                ' (IPL) Associated to Alternate Working Register Not Assigned
                     CTXT4_OFF                                                  ' (IPL) Associated to Alternate Working Register Not Assigned

I recently designed a 64x64 LED matrix library for Ricardo using a PIC24, then a dsPIC33CK device using Positron16, and they operate so fast, I had to put delays in the code when I converted the program to run on a dsPIC33CK64MP102 device. Even when having to scan and alter 4096 RGB LEDs using the on-board shift registers. The dsPIC33CK64MP102 has 8192 bytes of RAM and 64K of Flash memory, and there are some dsPIC33xxCK devices that have 16K of RAM and 128k and 256K of flash.

TimB


Thanks so much for the code Les

I decided to use the 18f27Q10 as after changes to my requirements. Speed of the ADC is no longer an issue

My requirements are now
3 PWMs fixed freq and variable duty
Slave i2c

The rest is simple stuff and my ADC req are now just 3 channels at 1ms each

Slave i2c is going to be pain as the i2c in the chip is different from my previous code in a 18f13k22

Tim