Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootcamp: Lily Wang #165

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Bootcamp: Lily Wang #165

wants to merge 3 commits into from

Conversation

lilywang899
Copy link

No description provided.

Copy link

@Penguronik Penguronik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work so far! Just a few small changes and adding the tx data left


//adc value is 10 bits so rxData[1] stores 2 MSBs and rxData[2] stores the 8 remaining since data can only be sent in 8 bits
uint16_t adcValue = ((rxData[1]&0x03)<<8 | rxData[2]);
compareValue = (adcValue * maxTimerCounts)/maxADCValue;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to shift this to be from 5% to 10% of your PWM period

//bring CS to low to select ADC
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET);
//transmit and receive data from ADC simultaneously
HAL_SPI_TransmitReceive(&hspi1,txData,rxData,2,HAL_MAX_DELAY);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're sending and receiving 3 bytes, you would need to update the size value


uint8_t txData[3] = {0};
uint8_t rxData[3] = {0};
uint16_t adcValue = 0x00;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you redeclare the variable down below

/* USER CODE BEGIN 2 */

uint8_t txData[3] = {0};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out page 21 of https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf to see what value you need to send

uint16_t adcValue = 0x00;
uint16_t compareValue = 0x00;
uint16_t maxTimerCounts = 10000; //Auto-reload register
uint16_t maxADCValue = 1023; //10 bits
/* USER CODE END 2 */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you call the appropriate HAL PWM start function here (you should be able to find it with a quick google search)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants